     /// - parameters:
     ///     - descriptor: The file descriptor to wrap.
     init(descriptor: CInt) {
+        precondition(descriptor >= 0, "invalid file descriptor")
         self.descriptor = descriptor
-        self.isOpen = true
     }
 
     deinit {

            try Posix.close(descriptor: fd)
        }

        self.isOpen = false
    }
}


/// This should not be created directly but one of its sub-classes should be used, like `ServerSocket` or `Socket`.
class BaseSocket: Selectable {

    private var descriptor: CInt
    public var isOpen: Bool {
        return descriptor >= 0
    }

    func withUnsafeFileDescriptor<T>(_ body: (CInt) throws -> T) throws -> T {
        guard self.isOpen else {
