                 #endif
             })
             self.socket = CFSocketGetNative(myipv4cfsock)
-            
+            pSocket?.pointee = self.socket
             // Make non blocking
             let flags = fcntl(socket, F_GETFL)
             _ = fcntl(socket, F_SETFL, flags | O_NONBLOCK)

        if SSLSetIOFuncs(context, NWSSLRead, NWSSLWrite) != errSecSuccess {
            throw NWError.SSLCallbacksCannotBeSet
        }
        if SSLSetConnection(context, Int(self.socket) as? SSLConnectionRef) != errSecSuccess {
            throw NWError.SSLConnectionCannotBeSet
        }
        if SSLSetPeerDomainName(context, self.host.cString, self.host.length) != errSecSuccess {

    func connect() throws {
        self.disconnect()
        do {
            pSocket = UnsafeMutablePointer<CFSocketNativeHandle>.allocate(capacity: MemoryLayout<CFSocketNativeHandle>.size)
            try self.connectSocket()
            try self.connectSSL()
            try self.handshakeSSL()
