Skip to content

Commit

Permalink
fixed the locking mechanism, changed the run loops so they terminate;…
Browse files Browse the repository at this point in the history
… this fixes bug #237

Signed-off-by: Jonathan 'Wolf' Rentzsch <jwr.git@redshed.net>
  • Loading branch information
Simone Manganelli authored and rentzsch committed Jul 15, 2009
1 parent cf7d286 commit f6c5948
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions Plugin/CTFURLConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ + (NSHTTPURLResponse *)getURLResponseHeaders:(NSURL *)URL

- (void)startRequest:(NSURLRequest *)request;
{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[request retain];

NSLog(@"Connection is starting immediately.");
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self
startImmediately:YES];
[[NSRunLoop currentRunLoop] run];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]];
[connection release];

[request release];
Expand All @@ -79,31 +77,27 @@ - (void)startRequest:(NSURLRequest *)request;

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
{
NSLog(@"Connection failed with error: %@",error);
[theLock tryLock];
[theLock lock];

errorToReturn = error;
[theLock unlockWithCondition:1];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)theResponse;
{

[theLock tryLock];
[theLock lock];

// we cancel here, because otherwise NSURLConnection will continue to download
// data due to a bug; even though we made a HEAD request, it still downloads
// all the data at the given URL instead of stopping after receiving headers
[connection cancel];
responseToReturn = [theResponse retain];
[theLock unlockWithCondition:1];

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
{
NSLog(@"Connection did finish loading.");
[theLock tryLock];
[theLock lock];

[theLock unlockWithCondition:1];
}
Expand Down

0 comments on commit f6c5948

Please sign in to comment.