How to use CFStreamCreatePairWithSocket using CFSocketNativeHandle
<p>I am trying to write socket for XMPP, after connection is established socket should reestablish connection with updated TLS settings. Problem is delegate methods Stream.Event.openCompleted is called on both outputStream and inputStream but Stream.Event.hasSpaceAvailable is not getting called after CFStreamCreatePairWithSocket.</p>

<p>code:-</p>

<pre><code>if tls{

var readStream :Unmanaged&lt;CFReadStream&gt;?
var writeStream:Unmanaged&lt;CFWriteStream&gt;?
reset()

print("establish tls ")
tlsEnabled = true


let socketData = CFWriteStreamCopyProperty(self.outputStream as CFWriteStream,
                                           CFStreamPropertyKey.socketNativeHandle) as! CFData


let native = CFSocketNativeHandle(CFDataGetBytePtr(socketData).pointee)




inputStream.close()
outputStream.close()

inputStream.remove(from: RunLoop.current, forMode: .defaultRunLoopMode)
outputStream.remove(from: RunLoop.current, forMode: .defaultRunLoopMode)
inputStream = nil
outputStream = nil




CFStreamCreatePairWithSocket(kCFAllocatorDefault,
                             native,
                             &amp;readStream,
                             &amp;writeStream)




inStream             = readStream!.takeRetainedValue()
outStream            = writeStream!.takeRetainedValue()

inStream.delegate    = self
outStream.delegate   = self

inStream.setProperty(kCFBooleanTrue, forKey: kCFStreamPropertyShouldCloseNativeSocket as Stream.PropertyKey)
outStream.setProperty(kCFBooleanTrue, forKey: kCFStreamPropertyShouldCloseNativeSocket as Stream.PropertyKey)

inStream.setProperty(StreamSocketSecurityLevel.negotiatedSSL as AnyObject,
                     forKey: Stream.PropertyKey.socketSecurityLevelKey)
outStream.setProperty(StreamSocketSecurityLevel.negotiatedSSL as AnyObject,
                      forKey: Stream.PropertyKey.socketSecurityLevelKey)

let settings: [NSObject: NSObject] = [kCFStreamSSLValidatesCertificateChain: NSNumber(value: false),
                                      kCFStreamSSLPeerName: kCFNull]
inStream.setProperty(settings,
                     forKey: kCFStreamPropertySSLSettings as Stream.PropertyKey)
outStream.setProperty(settings,
                      forKey: kCFStreamPropertySSLSettings as Stream.PropertyKey)


inStream.schedule(in: RunLoop.current, forMode:.defaultRunLoopMode)
outStream.schedule(in:RunLoop.current, forMode:.defaultRunLoopMode)

inStream.open()
outStream.open()
</code></pre>

<p>}</p>