[swift-corelibs-dev] Create InputStream and OutputStream inside CFSocket accept callback on Linux

Bouke Haarsma bouke at haarsma.eu
Wed Oct 12 01:43:23 CDT 2016

Hi all,

I've started working on an implementation of (NS)NetService 
(https://github.com/Bouke/NetService), in pure Swift. My goal is to 
stay close to the version in Cocoa. While I've got an intial working 
version, I've hit a snag. When publishing a NetService, you can also 
listen for connections for that service:

let ns = NetService(domain: "local.", type: "_airplay._tcp.", name: 
"demo", port: 7000)
ns.publish(options: [.listenForConnections])

The NetService's delegate has  a method for accepting connections:

    func netService(_ sender: NetService,
                    didAcceptConnectionWith inputStream: InputStream,
                    outputStream: OutputStream)

I've setup a CFSocket for listening and inside the accept callback it 
creates a CFReadStream and a CFWriteStream using 
CFStreamCreatePairWithSocket. The problem is that CFNetwork is not 
available on Linux and probably will never be. So 
CFStreamCreatePairWithSocket is not available.

So the question is; how to create InputStream and OutputStream inside 
the accept callback without CFNetwork?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20161012/401c79cd/attachment.html>

More information about the swift-corelibs-dev mailing list