2016-10-16 19:06:11 +00:00
|
|
|
/++ dub.sdl:
|
|
|
|
name "test"
|
|
|
|
dependency "eventcore" path=".."
|
|
|
|
+/
|
|
|
|
module test;
|
|
|
|
|
|
|
|
import eventcore.core;
|
|
|
|
import std.stdio : writefln;
|
|
|
|
import core.stdc.signal;
|
2017-01-23 14:37:47 +00:00
|
|
|
import core.sys.posix.signal : SIGUSR1;
|
2016-10-19 20:00:06 +00:00
|
|
|
import core.time : Duration, msecs;
|
2016-10-16 19:06:11 +00:00
|
|
|
|
|
|
|
bool s_done;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2017-01-22 19:54:56 +00:00
|
|
|
version (OSX) writefln("Signals are not yet supported on macOS. Skipping test.");
|
2017-01-22 20:03:38 +00:00
|
|
|
else {
|
2017-01-22 19:54:56 +00:00
|
|
|
|
2017-01-23 14:37:47 +00:00
|
|
|
auto id = eventDriver.signals.listen(SIGUSR1, (id, status, sig) {
|
2016-10-16 19:06:11 +00:00
|
|
|
assert(!s_done);
|
|
|
|
assert(status == SignalStatus.ok);
|
2017-01-23 14:37:47 +00:00
|
|
|
assert(sig == () @trusted { return SIGUSR1; } ());
|
2016-10-16 19:06:11 +00:00
|
|
|
s_done = true;
|
|
|
|
eventDriver.core.exit();
|
|
|
|
});
|
|
|
|
|
|
|
|
auto tm = eventDriver.timers.create();
|
2016-10-19 20:00:06 +00:00
|
|
|
eventDriver.timers.set(tm, 500.msecs, 0.msecs);
|
2016-10-16 19:06:11 +00:00
|
|
|
eventDriver.timers.wait(tm, (tm) {
|
2017-01-23 14:37:47 +00:00
|
|
|
() @trusted { raise(SIGUSR1); } ();
|
2016-10-16 19:06:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ExitReason er;
|
2016-10-19 20:00:06 +00:00
|
|
|
do er = eventDriver.core.processEvents(Duration.max);
|
2016-10-16 19:06:11 +00:00
|
|
|
while (er == ExitReason.idle);
|
|
|
|
//assert(er == ExitReason.outOfWaiters); // FIXME: see above
|
|
|
|
assert(s_done);
|
|
|
|
s_done = false;
|
2017-01-22 20:03:38 +00:00
|
|
|
|
|
|
|
}
|
2016-10-16 19:06:11 +00:00
|
|
|
}
|