Ensure we correctly handle deregister while still in the whenReady(...) method and using kqueue

This commit is contained in:
Norman Maurer committed 2017-06-21 08:32:41 +02:00
1 parent f091d61576
commit ca794b158c
1 file changed
+5 -2
+5 -2
View File
@@ -295,8 +295,11 @@ public final class Selector {
for i in 0..<ready {
let ev = events[i]
if ev.ident != Selector.EvUserIdent {
let registration = registrations[Int(ev.ident)]!
try fn((SelectorEvent(isReadable: Int32(ev.filter) == EVFILT_READ, isWritable: Int32(ev.filter) == EVFILT_WRITE, selectable: registration.selectable, attachment: registration.attachment)))
guard let registration = registrations[Int(ev.ident)] else {
// Just ignore as this means the user deregistered already in between. This can happen as kevent returns two different events, one for EVFILT_READ and one for EVFILT_WRITE.
continue
}
try fn((SelectorEvent(isReadable: Int32(ev.filter) == EVFILT_READ, isWritable: Int32(ev.filter) == EVFILT_WRITE, selectable: registration.selectable, attachment: registration.attachment)))
}
}
#endif