Re: NSData DataWithContentsOfURL within a protocol handler
Yes, I meant GCD. Sorry I missed the part where you told us about supporting 10.5 in your original message. On 6 sept. 2012, at 20:55, Dan S wrote: > if you meant using the grand central dispatch, i think that only became > available in 10.6, I need to support this for 10.5 > > On Thu, Sep 6, 2012 at 11:25 AM, Dan S wrote: > No, actually I've completely missed that it was answered. Thank you. > > Unfortunatelly, the requester is expecting a return data, error or a > redirect. And until the api can be respeced, the sync response has to stay > in. It isn't that it needs to load from network every request, but some > volotile data does have to check the server to pull down the changes before > serving the data. > > 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). > > but now I'm also curiouse of what you mewant by posting a block to another > dispatch queue ? > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSData DataWithContentsOfURL within a protocol handler
On Sep 6, 2012, at 1:21 PM, Dan S wrote: > I can return from > the routine without completing the request, while the caller will be kept > blocked on that request untill I respond with URLProtocolDidFinishLoading Well, the caller probably won’t be blocked, since it should be using an async API. But that doesn’t matter to you as the protocol. > Except can I get a confirmation please that the client using the protocol > handler will not reuse it untill request is completed (i.e. it wont use the > same instance to make another request once I return from -startLoading, > untill it gets a completion like a final redirect or > URLProtocolDidFinishLoading)?? An instance is only ever used once, for a single request. > 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? If you just use the asynchronous API from your protocol handler, the delegate callbacks will all happen on the same thread, so you don’t have to worry about threading at all. If you want to run your loading on a separate thread, you’ll need to remember the identity of the thread that -startLoading was called on (it is not the main thread) and call the client on that thread. You can use -performSelector:onThread:withObject:waitUntilDone: to do this. —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSData DataWithContentsOfURL within a protocol handler
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 wrote: > > On Sep 6, 2012, at 11:25 AM, Dan S 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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSData DataWithContentsOfURL within a protocol handler
doh! I've been treating -startLoading as a sync routine that must return a final result to the caller, and just now realized that I can return from the routine without completing the request, while the caller will be kept blocked on that request untill I respond with URLProtocolDidFinishLoading (and from a different thread if need to) so the "rewrite your code async" comment all of a sudden sounds great :) Except can I get a confirmation please that the client using the protocol handler will not reuse it untill request is completed (i.e. it wont use the same instance to make another request once I return from -startLoading, untill it gets a completion like a final redirect or URLProtocolDidFinishLoading)?? Basically I'm trying to confirm that I don't have to save the request somewhere else and keep track of it separately outside of the initial NSURLProtocol instance itself. On Thu, Sep 6, 2012 at 11:55 AM, Dan S wrote: > if you meant using the grand central dispatch, i think that only became > available in 10.6, I need to support this for 10.5 > > > On Thu, Sep 6, 2012 at 11:25 AM, Dan S wrote: > >> No, actually I've completely missed that it was answered. Thank you. >> >> Unfortunatelly, the requester is expecting a return data, error or a >> redirect. And until the api can be respeced, the sync response has to stay >> in. It isn't that it needs to load from network every request, but some >> volotile data does have to check the server to pull down the changes before >> serving the data. >> >> 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). >> >> but now I'm also curiouse of what you mewant by posting a block to >> another dispatch queue ? >> >> >> On Thu, Sep 6, 2012 at 7:55 AM, Jean Suisse wrote: >> >>> Hi, >>> >>> Fritz Anderson is right. We can only agree. >>> And recently, they made following Jens Alfke's advice incredibly easy. >>> Just post a block to one of the available dispatch queues (not the one >>> running on your main thread thought) and let it run its curse. >>> >>> Jean >>> >>> On 6 sept. 2012, at 16:36, Fritz Anderson wrote: >>> >>> > From what Google tells me, you got a prompt response from Jens Alfke, >>> a very experienced Cocoa-networking programmer, explaining why what you're >>> doing shouldn't be expected to work. Are you looking for a workaround, or >>> just for somebody who will give you better news? I don't think better news >>> is in the cards. >>> >>> >>> On 29 août 2012, at 22:58, Jens Alfke wrote: >>> >>> > If you must use a synchronous API, spawn a new thread to run it on. >>> > >>> >>> >>> >>> >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSData DataWithContentsOfURL within a protocol handler
On Sep 6, 2012, at 11:25 AM, Dan S 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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSData DataWithContentsOfURL within a protocol handler
if you meant using the grand central dispatch, i think that only became available in 10.6, I need to support this for 10.5 On Thu, Sep 6, 2012 at 11:25 AM, Dan S wrote: > No, actually I've completely missed that it was answered. Thank you. > > Unfortunatelly, the requester is expecting a return data, error or a > redirect. And until the api can be respeced, the sync response has to stay > in. It isn't that it needs to load from network every request, but some > volotile data does have to check the server to pull down the changes before > serving the data. > > 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). > > but now I'm also curiouse of what you mewant by posting a block to another > dispatch queue ? > > > On Thu, Sep 6, 2012 at 7:55 AM, Jean Suisse wrote: > >> Hi, >> >> Fritz Anderson is right. We can only agree. >> And recently, they made following Jens Alfke's advice incredibly easy. >> Just post a block to one of the available dispatch queues (not the one >> running on your main thread thought) and let it run its curse. >> >> Jean >> >> On 6 sept. 2012, at 16:36, Fritz Anderson wrote: >> >> > From what Google tells me, you got a prompt response from Jens Alfke, a >> very experienced Cocoa-networking programmer, explaining why what you're >> doing shouldn't be expected to work. Are you looking for a workaround, or >> just for somebody who will give you better news? I don't think better news >> is in the cards. >> >> >> On 29 août 2012, at 22:58, Jens Alfke wrote: >> >> > If you must use a synchronous API, spawn a new thread to run it on. >> > >> >> >> >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSData DataWithContentsOfURL within a protocol handler
No, actually I've completely missed that it was answered. Thank you. Unfortunatelly, the requester is expecting a return data, error or a redirect. And until the api can be respeced, the sync response has to stay in. It isn't that it needs to load from network every request, but some volotile data does have to check the server to pull down the changes before serving the data. 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). but now I'm also curiouse of what you mewant by posting a block to another dispatch queue ? On Thu, Sep 6, 2012 at 7:55 AM, Jean Suisse wrote: > Hi, > > Fritz Anderson is right. We can only agree. > And recently, they made following Jens Alfke's advice incredibly easy. > Just post a block to one of the available dispatch queues (not the one > running on your main thread thought) and let it run its curse. > > Jean > > On 6 sept. 2012, at 16:36, Fritz Anderson wrote: > > > From what Google tells me, you got a prompt response from Jens Alfke, a > very experienced Cocoa-networking programmer, explaining why what you're > doing shouldn't be expected to work. Are you looking for a workaround, or > just for somebody who will give you better news? I don't think better news > is in the cards. > > > On 29 août 2012, at 22:58, Jens Alfke wrote: > > > If you must use a synchronous API, spawn a new thread to run it on. > > > > > > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSData DataWithContentsOfURL within a protocol handler
Hi, Fritz Anderson is right. We can only agree. And recently, they made following Jens Alfke's advice incredibly easy. Just post a block to one of the available dispatch queues (not the one running on your main thread thought) and let it run its curse. Jean On 6 sept. 2012, at 16:36, Fritz Anderson wrote: > From what Google tells me, you got a prompt response from Jens Alfke, a very > experienced Cocoa-networking programmer, explaining why what you're doing > shouldn't be expected to work. Are you looking for a workaround, or just for > somebody who will give you better news? I don't think better news is in the > cards. On 29 août 2012, at 22:58, Jens Alfke wrote: > If you must use a synchronous API, spawn a new thread to run it on. > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSData DataWithContentsOfURL within a protocol handler
From what Google tells me, you got a prompt response from Jens Alfke, a very experienced Cocoa-networking programmer, explaining why what you're doing shouldn't be expected to work. Are you looking for a workaround, or just for somebody who will give you better news? I don't think better news is in the cards. — F On 5 Sep 2012, at 7:59 PM, danchik wrote: > Hello, is there a recomendation of a better list for this question ? > > - Original Message - From: "danchik" > To: > Sent: Thursday, August 02, 2012 3:33 PM > Subject: NSData DataWithContentsOfURL within a protocol handler > > >> Hello, I was callingNSData *data = [NSData DataWithContentsOfURL:url >> within the -startLoading of custom protocol handler, which worked fine for >> 10.5 through 10.7, but in 10.8, for some reason the call timesout with >> unknown error (256) >> >> Seems that in 10.8 any calls I make to pull the content form the web using >> NSString or NSData or NSURLConnection will time out if I am in the custom >> protocol handler inside the -startLoading >> >> Seems like it is waiting for me to return before it will process the >> command, is there a way I can make a syncronouse url content pull from >> within the -startLoading protocol handler? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSData DataWithContentsOfURL within a protocol handler
Hello, is there a recomendation of a better list for this question ? - Original Message - From: "danchik" To: Sent: Thursday, August 02, 2012 3:33 PM Subject: NSData DataWithContentsOfURL within a protocol handler Hello, I was callingNSData *data = [NSData DataWithContentsOfURL:url within the -startLoading of custom protocol handler, which worked fine for 10.5 through 10.7, but in 10.8, for some reason the call timesout with unknown error (256) Seems that in 10.8 any calls I make to pull the content form the web using NSString or NSData or NSURLConnection will time out if I am in the custom protocol handler inside the -startLoading Seems like it is waiting for me to return before it will process the command, is there a way I can make a syncronouse url content pull from within the -startLoading protocol handler? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSData DataWithContentsOfURL within a protocol handler
On Aug 29, 2012, at 12:42 PM, danchik wrote: > Seems like it is waiting for me to return before it will process the > command, is there a way I can make a syncronouse url content pull from > within the -startLoading protocol handler? Don't do that. Never block the URL-loading thread, or you'll delay all URL loading in the app. And I can totally imagine that trying to do synchronous networking on that thread will deadlock it; in fact I have no idea why it would have worked at all in earlier OS versions! If you're going to do networking in a protocol handler, use the asynchronous API. If you must use a synchronous API, spawn a new thread to run it on. —Jens smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSData DataWithContentsOfURL within a protocol handler
Hello, I was callingNSData *data = [NSData DataWithContentsOfURL:url within the -startLoading of custom protocol handler, which worked fine for 10.5 through 10.7, but in 10.8, for some reason the call timesout with unknown error (256) Seems that in 10.8 any calls I make to pull the content form the web using NSString or NSData or NSURLConnection will time out if I am in the custom protocol handler inside the -startLoading Seems like it is waiting for me to return before it will process the command, is there a way I can make a syncronouse url content pull from within the -startLoading protocol handler? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com