NSStream only knows runloops, NSURLSession only knows operation queues
NSStream only knows runloops, NSURLSession only knows operation queues
- Subject: NSStream only knows runloops, NSURLSession only knows operation queues
- From: Jens Alfke <email@hidden>
- Date: Mon, 21 Jul 2014 17:37:25 -0700
I’m starting to port a pretty complex source base, the Couchbase Lite sync engine, from using NSURLConnection to using NSURLSession. (Primarily because this is the only way to get around the only-four-sockets-per-host limitation.) I thought it was going to be straightforward, until I saw that NSURLSession only supports scheduling delegate calls on an NSOperationQueue, not an NSRunLoop. So that means I now also have to convert a number of runloop dependencies in the same code, which I don’t understand how to do.
Case in point: guess what, it’s 2014, and NSStream has still never heard of dispatch queues or NSOperationQueues. It only supports scheduling delegate calls on a runloop. I have a bunch of async NSStream based code in this same codebase, which has to play nice with the URLConnection-based code. If the stream callbacks are going to require their own thread that’s different from the one(s) running the operation queue, I’m going to have a lot of thread-safety problems that will require me to start wrapping @synchronized around a lot of code.
Also, I note that NSURLSession itself uses NSStreams, for instance if I set the body of an NSURLRequest to be an input or output stream. How should I expect the delegate callbacks of those streams to be called? Will it be on the session’s operation queue, even though streams ostensibly don’t support that? Or do I still have to schedule those streams on some runloop?
—Jens
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden