• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSURLConnection Doesn't Remove itself from run loop when done?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSURLConnection Doesn't Remove itself from run loop when done?
      • From: Quinn <email@hidden>
  • Prev by Date: Re: Inappropriate NSError from -[NSURLConnection sendSynchronousRequest:::]
  • Next by Date: Re: NSURLConnection Doesn't Remove itself from run loop when done?
  • Previous by thread: Re: Inappropriate NSError from -[NSURLConnection sendSynchronousRequest:::]
  • Next by thread: Re: NSURLConnection Doesn't Remove itself from run loop when done?
  • Index(es):
    • Date
    • Thread