         ev.events = toEpollEvents(interested: interested)
         ev.data.fd = selectable.descriptor
  
-        let res = CEpoll.epoll_ctl(self.fd, EPOLL_CTL_MOD, selectable.descriptor, &ev)
-        guard res == 0 else {
-            throw ioError(errno: errno, function: "epoll_ctl")
-        }
-#else
-        let res = register_kqueue(selectable: selectable, interested: interested)
-    
-        guard res != -1 else {
-            throw ioError(errno: errno, function: "kevent")
-        }
+        let _ = try wrapSyscall({ $0 == 0 }, function: "epoll_ctl") {
+            CEpoll.epoll_ctl(self.fd, EPOLL_CTL_MOD, selectable.descriptor, &ev)
+        }
+#else
+        try register_kqueue(selectable: selectable, interested: interested)
 #endif
     }
     
     public func deregister(selectable: Selectable) throws {
 #if os(Linux)
         var ev = epoll_event()
-        let res = CEpoll.epoll_ctl(self.fd, EPOLL_CTL_DEL, selectable.descriptor, &ev)
-        guard res == 0 else {
-            throw ioError(errno: errno, function: "epoll_ctl")
-        }
-        registrations.removeValue(forKey: Int(selectable.descriptor))
+        let _ = try wrapSyscall({ $0 == 0 }, function: "epoll_ctl") {
+            CEpoll.epoll_ctl(self.fd, EPOLL_CTL_DEL, selectable.descriptor, &ev)
+        }
 #else
         // Allocated on the stack
         var evs = (kevent(), kevent())

        evs.1.udata = nil
        evs.1.flags = UInt16(Int16(EV_DELETE))

        let res = withUnsafeMutableBytes(of: &evs) { event_ptr -> Int32 in
            precondition(MemoryLayout<kevent>.size * 2 == event_ptr.count)
            let ptr = event_ptr.baseAddress?.bindMemory(to: kevent.self, capacity: 2)
            return kevent(self.fd, ptr, 2, ptr, 2, nil)
        }
    
        guard res != -1 else {
            throw ioError(errno: errno, function: "kevent")
        }
#endif
    }
    
    public func awaitReady() throws -> Array<SelectorEvent>? {
#if os(Linux)
        let ready = CEpoll.epoll_wait(self.fd, events, 2048, 0)
        if (ready > 0) {
            var sEvents = [SelectorEvent]()
            var i = 0;

    
    public init() throws {
#if os(Linux)
        fd = try wrapSyscall({ $0 >= 0 }, function: "epoll_create") {
            CEpoll.epoll_create(128)
        }
        events = UnsafeMutablePointer.allocate(capacity: 2048) // max 2048 events per epoll call
        events.initialize(to: epoll_event())
#else
        fd = try wrapSyscall({ $0 >= 0 }, function: "kqueue") {
            Darwin.kqueue()
        }

        events = UnsafeMutablePointer.allocate(capacity: 2048) // max 2048 events per kqueue call
        events.initialize(to: kevent())
#endif
