Re: NSData DataWithContentsOfURL within a protocol handler
Re: NSData DataWithContentsOfURL within a protocol handler
- Subject: Re: NSData DataWithContentsOfURL within a protocol handler
- From: Dan S <email@hidden>
- Date: Thu, 06 Sep 2012 13:30:15 -0700
hehe, yes thank you, I was definatelly treating -startLoading it as the end
all call. So, following your suggestion, to avoid
calling URLProtocolDidFinishLoading from the thread, what would be
preferable for calling it from main thread? performSelectorOnMainthread or
listening to threadWillTerninate notification? or something else?
and should I assume that the initial -startLoading came from the main
thread or should I poll for which thread it came from and performSelector
on that thread (in which case am I guaranteed that that particular thread
is still running if it is not main)?
On Thu, Sep 6, 2012 at 1:19 PM, Jens Alfke <email@hidden> wrote:
>
> 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