Causes the event loop to exit on Posix when being interrupted by a signal.

Previously, the loop logic would simply retry the wait until the given timeout was actually reached (or an event got received), which could be forever. This change makes sure that after an interrupt the higher level code will get a chance to run to possibly handle the effects of the signal.

This is a fix for vibe-d/vibe-core#205.
This commit is contained in:
Sönke Ludwig 2020-11-25 23:30:38 +01:00
parent 1e5f3f04ce
commit 07d5ead617
3 changed files with 30 additions and 3 deletions

View file

@ -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()

View file

@ -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()

View file

@ -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()