 
             strong_self.state = .Connecting
 
-            let socketDescriptor = Darwin.socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)
-            guard socketDescriptor >= 0 else {
-                let error = Errno(rawValue: errno)!
-                close(socketDescriptor)
-                callback(Result.Failure(error))
-                return
-            }
-
-            var addr = address.to_sockaddr(port: port)
-
-            let result = Darwin.connect(socketDescriptor, &addr, socklen_t(sizeof(sockaddr)))
-            guard result == 0 else {
-                let error = Errno(rawValue: errno)!
-                close(socketDescriptor)
-                strong_self.state = .Unconnected
-                callback(Result.Failure(error))
-                return
-            }
-
-            let channel = dispatch_io_create(DISPATCH_IO_STREAM, socketDescriptor, queue) {
-                (error) in
-
-                guard let strong_self = self else {
-                    return
-                }
-
-                strong_self.handleDisconnect()
-            }
-
-            dispatch_io_set_low_water(channel, 0)
-
+            let socket = try! Socket.TCP()
+
+            try! socket.connect(address, port: port)
+
+            strong_self.socket = socket
             strong_self.state = .Connected
-            strong_self.channel = channel
-            strong_self.socketDescriptor = socketDescriptor
-
-            strong_self.startReading()
 
             callback(Result.Success())
         }

        disconnectCallback?(Result.Success())
        disconnectCallback = nil
    }
}


        dispatch_io_read(channel, 0, -1 /* Int(truncatingBitPattern:SIZE_MAX) */, queue) {
            [weak self] (done, data, error) in
            guard let strong_self = self else {
                return
            }
            guard error == 0 else {
                if error == ECONNRESET {
                    try! strong_self.handleDisconnect()
                    return
                }
                strong_self.readCallback?(Result.Failure(Errno(rawValue: error)!))
                return
            }
            switch (done, dispatch_data_get_size(data) > 0) {
                case (false, _), (true, true):
                    let dispatchData = DispatchData <Void> (data: data)
