Merge pull request #163 from vibe-d/fix_interrupt_behavior
Causes the event loop to exit on Posix when being interrupted by a signal
This commit is contained in:
commit
92ac3f454e
|
@ -85,6 +85,12 @@ interface EventDriverCore {
|
|||
in the event queue. The function will return after either the specified
|
||||
timeout has elapsed, or once the event queue has been fully emptied.
|
||||
|
||||
On implementations that support it, the function will treat
|
||||
interruptions by POSIX signals as if an event was received and will
|
||||
cause it to return. However, note that it is generally recommended to
|
||||
use `EventDriverSignals` instead of raw signal handlers in order to
|
||||
avoid their pitfalls as far as possible.
|
||||
|
||||
Params:
|
||||
timeout = Maximum amount of time to wait for an event. A duration of
|
||||
zero will cause the function to only process pending events. A
|
||||
|
|
|
@ -336,6 +336,13 @@ package class PosixEventLoop {
|
|||
|
||||
protected abstract void dispose();
|
||||
|
||||
/** Waits for and processes a single batch of events.
|
||||
|
||||
Returns:
|
||||
Returns `false` if no event was received before the timeout expired
|
||||
and `true` if either an event was received, or if the wait was
|
||||
interrupted by an error or signal.
|
||||
*/
|
||||
protected abstract bool doProcessEvents(Duration dur);
|
||||
|
||||
/// Registers the FD for general notification reception.
|
||||
|
|
|
@ -57,7 +57,16 @@ final class EpollEventLoop : PosixEventLoop {
|
|||
if (evt.events & EPOLLOUT) notify!(EventType.write)(fd);
|
||||
}
|
||||
return true;
|
||||
} else return false;
|
||||
} else {
|
||||
// NOTE: In particular, EINTR needs to cause true to be returned
|
||||
// here, so that user code has a chance to handle any effects
|
||||
// of the signal handler before waiting again.
|
||||
//
|
||||
// Other errors are very likely to to reoccur for the next
|
||||
// loop iteration, so there is no value in attempting to
|
||||
// wait again.
|
||||
return ret < 0;
|
||||
}
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
|
|
|
@ -85,7 +85,16 @@ abstract class KqueueEventLoopBase : PosixEventLoop {
|
|||
// EV_SIGNAL, EV_TIMEOUT
|
||||
}
|
||||
return true;
|
||||
} else return false;
|
||||
} else {
|
||||
// NOTE: In particular, EINTR needs to cause true to be returned
|
||||
// here, so that user code has a chance to handle any effects
|
||||
// of the signal handler before waiting again.
|
||||
//
|
||||
// Other errors are very likely to to reoccur for the next
|
||||
// loop iteration, so there is no value in attempting to
|
||||
// wait again.
|
||||
return ret < 0;
|
||||
}
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
|
|
|
@ -65,7 +65,16 @@ final class SelectEventLoop : PosixEventLoop {
|
|||
notify!(EventType.status)(fd);
|
||||
});
|
||||
return true;
|
||||
} else return false;
|
||||
} else {
|
||||
// NOTE: In particular, EINTR needs to cause true to be returned
|
||||
// here, so that user code has a chance to handle any effects
|
||||
// of the signal handler before waiting again.
|
||||
//
|
||||
// Other errors are very likely to to reoccur for the next
|
||||
// loop iteration, so there is no value in attempting to
|
||||
// wait again.
|
||||
return ret < 0;
|
||||
}
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
|
|
Loading…
Reference in a new issue