Permalink
Browse files

fixed the locking mechanism, changed the run loops so they terminate;…

… this fixes bug #237

Signed-off-by: Jonathan 'Wolf' Rentzsch <jwr.git@redshed.net>
  • Loading branch information...
1 parent cf7d286 commit f6c59488db93286f97252ef10fd2e438bb8fc25a Simone Manganelli committed with Jul 15, 2009
Showing with 4 additions and 10 deletions.
  1. +4 −10 Plugin/CTFURLConnection.m
View
@@ -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];
@@ -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];
}

0 comments on commit f6c5948

Please sign in to comment.