NSURLConnection Doesn't Remove itself from run loop when done?
NSURLConnection Doesn't Remove itself from run loop when done?
- Subject: NSURLConnection Doesn't Remove itself from run loop when done?
- From: Jerry Krinock <email@hidden>
- Date: Mon, 5 Oct 2009 23:10:25 -0700
I desire to run a run loop for an NSURLConnection, and expect that it
would remove itself as an input source when it is done, thus causing
such a run loop should exit. But it does not.
Here is my method that gets detached to a new thread. (Some
noninteresting stuff such as error-handling has been removed for
brevity.)
- (void)connectWithRequest:(NSURLRequest*)request {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init] ;
NSURLConnection* connection ;
connection = [NSURLConnection connectionWithRequest:request
delegate:self] ;
NSRunLoop* runLoop = [NSRunLoop currentRunLoop] ;
while ([runLoop runMode:NSDefaultRunLoopMode
beforeDate:[NSDatedistantFuture]]) {
NSLog(@"1921: Run loop did run") ;
}
NSLog(@"6053: Run loop exitted") ;
[pool release] ;
}
When my delegate gets messages indicating that the connection is done,
I invoke this:
- (void)endConnection:(NSURLConnection*)connection {
[connection cancel] ;
[connection unscheduleFromRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode] ;
NSLog(@"1323: Cancelled and unscheduled") ;
}
What happens is that the "1921: Run loop did run" logs several times
as redirects and data is received, and then the "1323: Cancelled and
unscheduled" logs. But the "6053: Run loop exitted" never happens.
Although I can't find this documented, I expect from "common sense"
that NSURLConnection would remove itself as a run loop input source
when it is cancelled, which should cause -[NSRunLoop
runMode:beforeDate] to return NO since it has no other input sources,
and my while() loop to exit. Why am I wrong?
Finally, is adding a little isDone condition in that while() loop the
correct way to fix this?
Thanks,
Jerry Krinock
_______________________________________________
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