-
Re: CFReadStream & CFWriteStream callbacks not received
eskimo May 10, 2018 3:19 AM (in response to lapatil)I recommend that you avoid using
CFSocket
here, becauseCFSocket
has many sharp edges. The alternative is pretty simple: Do this part of the job using BSD Sockets. Now, BSD Sockets has lots of sharp edges as well, but they’re well-documented sharp edges (-:The main complication with replacing
CFSocket
with BSD Sockets is the async connect. Fortunately dispatch event sources make that relatively easy.Finally, once you have a connect BSD Socket I recommend that you wrap that in an
NSStream
pair rather than aCFStream
pair, because theNSStream
API is substantially easier to use. You do this by exploiting the toll-free bridge between the types, that is, callCFStreamCreatePairWithSocket
and cast the resulting values toNSInputStream
andNSOutputStream
. You can steal the basic code outline from QA1652 Using NSStreams For A TCP Connection Without NSHost (although that usesCFStreamCreatePairWithSocketToHost
instead ofCFStreamCreatePairWithSocket
).Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: CFReadStream & CFWriteStream callbacks not received
lapatil May 14, 2018 4:31 AM (in response to eskimo)Thanks Quinn, using BSD socket worked in this scenario.
I had to wait on socket to become writable( using select() call) before opening the streams.
I will see if dispatch event sources make it more simpler to handle the async connect.Looks like there is no way to select network interface at application level.
-
Re: CFReadStream & CFWriteStream callbacks not received
lapatil Jun 5, 2018 4:37 AM (in response to lapatil)Hi Quinn,
Like kCFStreamNetworkServiceTypeVoIP, is there any setting needs to be done on BSD socket to ensure that sockets are not dropped by OS during backgrounding?
Regards
-
Re: CFReadStream & CFWriteStream callbacks not received
eskimo Jun 10, 2018 7:39 PM (in response to lapatil)The legacy VoIP API (
kCFStreamNetworkServiceTypeVoIP
and friends) is not compatible with BSD Sockets. For it to function correctly you must useCFSocketStream
(via either theNSStream
orCFStream
API) and use it asynchronously.Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
-
-