Re: NSStream only knows runloops, NSURLSession only knows operation queues
Re: NSStream only knows runloops, NSURLSession only knows operation queues
- Subject: Re: NSStream only knows runloops, NSURLSession only knows operation queues
- From: "Quinn \"The Eskimo!\"" <email@hidden>
- Date: Tue, 22 Jul 2014 09:53:41 +0100
On 22 Jul 2014, at 01:37, Jens Alfke <email@hidden> wrote:
> I’m starting to port a pretty complex source base, the Couchbase Lite sync engine, from using NSURLConnection to using NSURLSession. [...] 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.
You have a couple of choices here:
A. stick with run loops -- In that case you can use your own private queue as NSURLSession's delegate queue and have it bounce over to the run loop via -performSelector:onThread:xxx.
B. move to queues -- NSStream does support queues for its delegate callback, just not via the Cocoa API. Check out CF{Read,Write}StreamSetDispatchQueue. These will work with NSStream due to the magic of toll free bridging.
Option A is likely to be simpler given your current code based. Option B is obviously more sexy (although personally I'm a big fan of run loops).
> 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. [...] Or do I still have to schedule those streams on some runloop?
You give the request an NSInputStream, and the request schedules that stream however it wants. You're not involved in the scheduling of the stream.
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
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