Re: NSData DataWithContentsOfURL within a protocol handler
Re: NSData DataWithContentsOfURL within a protocol handler
- Subject: Re: NSData DataWithContentsOfURL within a protocol handler
- From: Jens Alfke <email@hidden>
- Date: Thu, 06 Sep 2012 13:19:49 -0700
On Sep 6, 2012, at 11:25 AM, Dan S <email@hidden> wrote:
> I will try to offload the server access to a different thread (though I
> still need to block the protocol thread because I still have to return the
> correct data for the current call).
No — as I said before, you should _never_ block the protocol-handler thread.
I think you’re misunderstanding how NSURLProtocol works. When your -startLoading method is called, it does not have to send a response to the client immediately. Unless you have data already available (unlikely in your case) you should just kick off your own async request for the data, and then immediately return. Later on as the data arrives, you can call your client with the response and data. After everything’s done, call the client’s URLProtocolDidFinishLoading:. (The only restriction seems to be that you must call the client from the protocol-handler thread, i.e. the same thread -startLoading was called on. I’ve tried to do otherwise and it didn’t work well.)
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden