From: Steve C. <sco...@gm...> - 2009-02-14 17:02:36
|
Hi everyone. I'm trying to make my own URL Protocol. I've been marching along pretty well but have hit a hang problem - if you can spot the problem I'd appreciate help, but I might be even more interested in what you'd do to debug the problem - I don't even know what to try next. It seems that I've defined startLoading properly - the framework complains if it's not there, or the method signature is incorrect. canonicalRequestForRequest gets called and then the whole operation hangs - startLoading never gets invoked. My class: require 'osx/cocoa' OSX.require_framework 'WebKit' class LocalProtocol < OSX::NSURLProtocol objc_class_method(:canInitWithRequest_, '@:@@') def self.canInitWithRequest(ns_url_request) p" canInitWithRequest" 0 end objc_class_method(:canonicalRequestForRequest_, '@:@@') def self.canonicalRequestForRequest(ns_url_request) p"canonicalRequestForRequest #{ns_url_request.inspect}" ns_url_request end def startLoading p "startLoading" end def stopLoading p "stopLoading" end end Calling code: protocol = LocalProtocol.alloc OSX::NSURLProtocol.registerClass(LocalProtocol) url = OSX::NSURL.alloc.initWithString("local://foo") url_request = OSX::NSURLRequest.requestWithURL(url) url_response = OSX::NSURLResponse.alloc response = OSX::NSURLConnection.sendSynchronousRequest_returningResponse_error(url_request, url_response, nil) str = "." * response.length response.getBytes_length(str) Console result: " canInitWithRequest" " canInitWithRequest" " canInitWithRequest" "canonicalRequestForRequest #<OSX::NSURLRequest:0x8beeee class='NSURLRequest' id=0x2003e50>" <HANGS HERE FOREVER> Regards, Steve |
From: Allison N. <dem...@ma...> - 2009-02-14 17:34:30
|
Steve, Just to clarify, you're trying to subclass NSURLProtocol, and you want to override/create functions that are to be called from Objective C, Is that right? Alli Le 14 févr. 09 à 18:02, Steve Conover a écrit : > Hi everyone. > > I'm trying to make my own URL Protocol. I've been marching along > pretty well but have hit a hang problem - if you can spot the problem > I'd appreciate help, but I might be even more interested in what you'd > do to debug the problem - I don't even know what to try next. > > It seems that I've defined startLoading properly - the framework > complains if it's not there, or the method signature is incorrect. > canonicalRequestForRequest gets called and then the whole operation > hangs - startLoading never gets invoked. > > > My class: > > require 'osx/cocoa' > > OSX.require_framework 'WebKit' > > class LocalProtocol < OSX::NSURLProtocol > > objc_class_method(:canInitWithRequest_, '@:@@') > def self.canInitWithRequest(ns_url_request) > p" canInitWithRequest" > 0 > end > > objc_class_method(:canonicalRequestForRequest_, '@:@@') > def self.canonicalRequestForRequest(ns_url_request) > p"canonicalRequestForRequest #{ns_url_request.inspect}" > ns_url_request > end > > def startLoading > p "startLoading" > end > > def stopLoading > p "stopLoading" > end > > end > > > > Calling code: > > protocol = LocalProtocol.alloc > > OSX::NSURLProtocol.registerClass(LocalProtocol) > > url = OSX::NSURL.alloc.initWithString("local://foo") > url_request = OSX::NSURLRequest.requestWithURL(url) > url_response = OSX::NSURLResponse.alloc > response = > OSX > ::NSURLConnection > .sendSynchronousRequest_returningResponse_error(url_request, > url_response, nil) > str = "." * response.length > response.getBytes_length(str) > > > Console result: > > " canInitWithRequest" > " canInitWithRequest" > " canInitWithRequest" > "canonicalRequestForRequest #<OSX::NSURLRequest:0x8beeee > class='NSURLRequest' id=0x2003e50>" > <HANGS HERE FOREVER> > > > Regards, > Steve > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San > Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the > Enterprise > -Strategies to boost innovation and cut costs with open source > participation > -Receive a $600 discount off the registration fee with the source > code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk |
From: Steve C. <sco...@gm...> - 2009-02-14 19:35:49
|
Exactly On 2/14/09, Allison Newman <dem...@ma...> wrote: > Steve, > > Just to clarify, you're trying to subclass NSURLProtocol, and you want > to override/create functions that are to be called from Objective C, > Is that right? > > Alli > > Le 14 févr. 09 à 18:02, Steve Conover a écrit : > >> Hi everyone. >> >> I'm trying to make my own URL Protocol. I've been marching along >> pretty well but have hit a hang problem - if you can spot the problem >> I'd appreciate help, but I might be even more interested in what you'd >> do to debug the problem - I don't even know what to try next. >> >> It seems that I've defined startLoading properly - the framework >> complains if it's not there, or the method signature is incorrect. >> canonicalRequestForRequest gets called and then the whole operation >> hangs - startLoading never gets invoked. >> >> >> My class: >> >> require 'osx/cocoa' >> >> OSX.require_framework 'WebKit' >> >> class LocalProtocol < OSX::NSURLProtocol >> >> objc_class_method(:canInitWithRequest_, '@:@@') >> def self.canInitWithRequest(ns_url_request) >> p" canInitWithRequest" >> 0 >> end >> >> objc_class_method(:canonicalRequestForRequest_, '@:@@') >> def self.canonicalRequestForRequest(ns_url_request) >> p"canonicalRequestForRequest #{ns_url_request.inspect}" >> ns_url_request >> end >> >> def startLoading >> p "startLoading" >> end >> >> def stopLoading >> p "stopLoading" >> end >> >> end >> >> >> >> Calling code: >> >> protocol = LocalProtocol.alloc >> >> OSX::NSURLProtocol.registerClass(LocalProtocol) >> >> url = OSX::NSURL.alloc.initWithString("local://foo") >> url_request = OSX::NSURLRequest.requestWithURL(url) >> url_response = OSX::NSURLResponse.alloc >> response = >> OSX >> ::NSURLConnection >> .sendSynchronousRequest_returningResponse_error(url_request, >> url_response, nil) >> str = "." * response.length >> response.getBytes_length(str) >> >> >> Console result: >> >> " canInitWithRequest" >> " canInitWithRequest" >> " canInitWithRequest" >> "canonicalRequestForRequest #<OSX::NSURLRequest:0x8beeee >> class='NSURLRequest' id=0x2003e50>" >> <HANGS HERE FOREVER> >> >> >> Regards, >> Steve >> >> ------------------------------------------------------------------------------ >> Open Source Business Conference (OSBC), March 24-25, 2009, San >> Francisco, CA >> -OSBC tackles the biggest issue in open source: Open Sourcing the >> Enterprise >> -Strategies to boost innovation and cut costs with open source >> participation >> -Receive a $600 discount off the registration fee with the source >> code: SFAD >> http://p.sf.net/sfu/XcvMzF8H >> _______________________________________________ >> Rubycocoa-talk mailing list >> Rub...@li... >> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk > > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk > -- Sent from my mobile device |
From: Allison N. <dem...@ma...> - 2009-02-14 20:55:50
|
I don't have any good ideas as to what is going wrong, except to say that it would appear to me that the injection of class methods is not the real problem, it's a red-herring. you can see in the trace that they are correctly called, and they return without any obvious problems, so I'm guessing the real problem is elsewhere. What happens if you remove either the definition of the function, the call to objc_class_method, or both? Does it still work, or does it hang? Have you tried implementing the class in Objective-C to see what happens (this would at least make sure that you are returning reasonable values from your functions, if it works in obj-c). I'm wondering about that 0 that you return for canInitWithRequest: isn't that function supposed to return a boolean, hence false, rather than 0? Ummm, apart from that, I'm not too familiar with NSURLProtocol, so I can't offer up any special insight to the actual implementation :-) Le 14 févr. 09 à 20:35, Steve Conover a écrit : >>> objc_class_method(:canInitWithRequest_, '@:@@') >>> def self.canInitWithRequest(ns_url_request) >>> p" canInitWithRequest" >>> 0 >>> end |
From: Steve C. <sco...@gm...> - 2009-02-15 00:48:19
|
I agree that the class methods aren't the problem - it appears to me like the initialization may have completed, and somewhere on the way to calling startLoading there's either a blocking call that I'm not aware of, or something else. What are the tools the Rubycocoa people bring to bear when there's a mystery like this? Is there a debugger one can easily fire up to see what's going on? Ruby-debug isn't much help - the hang is apparently just after the return from canonicalRequestForRequest... -Steve On Sat, Feb 14, 2009 at 12:55 PM, Allison Newman <dem...@ma...> wrote: > I don't have any good ideas as to what is going wrong, except to say > that it would appear to me that the injection of class methods is not > the real problem, it's a red-herring. you can see in the trace that > they are correctly called, and they return without any obvious > problems, so I'm guessing the real problem is elsewhere. > > What happens if you remove either the definition of the function, the > call to objc_class_method, or both? Does it still work, or does it > hang? Have you tried implementing the class in Objective-C to see > what happens (this would at least make sure that you are returning > reasonable values from your functions, if it works in obj-c). I'm > wondering about that 0 that you return for canInitWithRequest: isn't > that function supposed to return a boolean, hence false, rather than 0? > > Ummm, apart from that, I'm not too familiar with NSURLProtocol, so I > can't offer up any special insight to the actual implementation :-) > > > Le 14 févr. 09 à 20:35, Steve Conover a écrit : > >>>> objc_class_method(:canInitWithRequest_, '@:@@') >>>> def self.canInitWithRequest(ns_url_request) >>>> p" canInitWithRequest" >>>> 0 >>>> end > > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk > |
From: Steve C. <sco...@gm...> - 2009-02-15 04:10:02
|
For the record... I had an rtfm problem, I was using NSURLConnection.sendSynchronousRequest_returningResponse_error, which, according to the docs: "A synchronous load is built on top of the asynchronous loading code made available by the class. The calling thread is blocked while the asynchronous loading system performs the URL load on a thread spawned specifically for this load request. No special threading or run loop configuration is necessary in the calling thread in order to perform a synchronous load." I'm still fuzzy on the details here but the key seems to be the blocking part. So I switched to an asynchronous and got it to work. Thanks for your suggestions Allison. -Steve On Sat, Feb 14, 2009 at 4:48 PM, Steve Conover <sco...@gm...> wrote: > I agree that the class methods aren't the problem - it appears to me > like the initialization may have completed, and somewhere on the way > to calling startLoading there's either a blocking call that I'm not > aware of, or something else. > > What are the tools the Rubycocoa people bring to bear when there's a > mystery like this? Is there a debugger one can easily fire up to see > what's going on? Ruby-debug isn't much help - the hang is apparently > just after the return from canonicalRequestForRequest... > > -Steve > > On Sat, Feb 14, 2009 at 12:55 PM, Allison Newman <dem...@ma...> wrote: >> I don't have any good ideas as to what is going wrong, except to say >> that it would appear to me that the injection of class methods is not >> the real problem, it's a red-herring. you can see in the trace that >> they are correctly called, and they return without any obvious >> problems, so I'm guessing the real problem is elsewhere. >> >> What happens if you remove either the definition of the function, the >> call to objc_class_method, or both? Does it still work, or does it >> hang? Have you tried implementing the class in Objective-C to see >> what happens (this would at least make sure that you are returning >> reasonable values from your functions, if it works in obj-c). I'm >> wondering about that 0 that you return for canInitWithRequest: isn't >> that function supposed to return a boolean, hence false, rather than 0? >> >> Ummm, apart from that, I'm not too familiar with NSURLProtocol, so I >> can't offer up any special insight to the actual implementation :-) >> >> >> Le 14 févr. 09 à 20:35, Steve Conover a écrit : >> >>>>> objc_class_method(:canInitWithRequest_, '@:@@') >>>>> def self.canInitWithRequest(ns_url_request) >>>>> p" canInitWithRequest" >>>>> 0 >>>>> end >> >> >> ------------------------------------------------------------------------------ >> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA >> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise >> -Strategies to boost innovation and cut costs with open source participation >> -Receive a $600 discount off the registration fee with the source code: SFAD >> http://p.sf.net/sfu/XcvMzF8H >> _______________________________________________ >> Rubycocoa-talk mailing list >> Rub...@li... >> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk >> > |
From: Allison N. <dem...@ma...> - 2009-02-15 07:21:30
|
Oh, yeah, I should have seen that. You walked straight into GIL deadlock hell. It's a good lesson to learn though - if you're going to call a blocking Cocoa function, make sure that there is never a call back into Ruby during the treatment of the function. I normally work around this by writing an obj-c wrapper for the function that doesn't block (the equivalent of choosing a non-blocking version of the API if it exists). Does anyone know of a more elegant solution to this? Envoyé de mon iPhone Le 15 févr. 09 à 05:09, Steve Conover <sco...@gm...> a écrit : > For the record... > > I had an rtfm problem, I was using > NSURLConnection.sendSynchronousRequest_returningResponse_error, which, > according to the docs: > > "A synchronous load is built on top of the asynchronous loading code > made available by the class. The calling thread is blocked while the > asynchronous loading system performs the URL load on a thread spawned > specifically for this load request. No special threading or run loop > configuration is necessary in the calling thread in order to perform a > synchronous load." > > I'm still fuzzy on the details here but the key seems to be the > blocking part. So I switched to an asynchronous and got it to work. > > Thanks for your suggestions Allison. > > -Steve > > On Sat, Feb 14, 2009 at 4:48 PM, Steve Conover <sco...@gm...> > wrote: >> I agree that the class methods aren't the problem - it appears to me >> like the initialization may have completed, and somewhere on the way >> to calling startLoading there's either a blocking call that I'm not >> aware of, or something else. >> >> What are the tools the Rubycocoa people bring to bear when there's a >> mystery like this? Is there a debugger one can easily fire up to see >> what's going on? Ruby-debug isn't much help - the hang is apparently >> just after the return from canonicalRequestForRequest... >> >> -Steve >> >> On Sat, Feb 14, 2009 at 12:55 PM, Allison Newman >> <dem...@ma...> wrote: >>> I don't have any good ideas as to what is going wrong, except to say >>> that it would appear to me that the injection of class methods is >>> not >>> the real problem, it's a red-herring. you can see in the trace that >>> they are correctly called, and they return without any obvious >>> problems, so I'm guessing the real problem is elsewhere. >>> >>> What happens if you remove either the definition of the function, >>> the >>> call to objc_class_method, or both? Does it still work, or does it >>> hang? Have you tried implementing the class in Objective-C to see >>> what happens (this would at least make sure that you are returning >>> reasonable values from your functions, if it works in obj-c). I'm >>> wondering about that 0 that you return for canInitWithRequest: >>> isn't >>> that function supposed to return a boolean, hence false, rather >>> than 0? >>> >>> Ummm, apart from that, I'm not too familiar with NSURLProtocol, so I >>> can't offer up any special insight to the actual implementation :-) >>> >>> >>> Le 14 févr. 09 à 20:35, Steve Conover a écrit : >>> >>>>>> objc_class_method(:canInitWithRequest_, '@:@@') >>>>>> def self.canInitWithRequest(ns_url_request) >>>>>> p" canInitWithRequest" >>>>>> 0 >>>>>> end >>> >>> >>> --- >>> --- >>> --- >>> --- >>> ------------------------------------------------------------------ >>> Open Source Business Conference (OSBC), March 24-25, 2009, San >>> Francisco, CA >>> -OSBC tackles the biggest issue in open source: Open Sourcing the >>> Enterprise >>> -Strategies to boost innovation and cut costs with open source >>> participation >>> -Receive a $600 discount off the registration fee with the source >>> code: SFAD >>> http://p.sf.net/sfu/XcvMzF8H >>> _______________________________________________ >>> Rubycocoa-talk mailing list >>> Rub...@li... >>> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk >>> >> > > --- > --- > --- > --------------------------------------------------------------------- > Open Source Business Conference (OSBC), March 24-25, 2009, San > Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the > Enterprise > -Strategies to boost innovation and cut costs with open source > participation > -Receive a $600 discount off the registration fee with the source > code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk |