Ben Copsey

Start work on removing locks for delegate-style authentication so it can be used on the main thread

@@ -470,7 +470,7 @@ static BOOL isiPhoneOS2; @@ -470,7 +470,7 @@ static BOOL isiPhoneOS2;
470 if (err != noErr) { 470 if (err != noErr) {
471 [NSException raise:@"FailedToDetectOSVersion" format:@"Unable to determine OS version, must give up"]; 471 [NSException raise:@"FailedToDetectOSVersion" format:@"Unable to determine OS version, must give up"];
472 } 472 }
473 - // GCD will manage the operation in its thread pool on Snow Leopard 473 + // GCD will run the operation in its thread pool on Snow Leopard
474 if (versionMajor >= 6) { 474 if (versionMajor >= 6) {
475 [self startAsynchronous]; 475 [self startAsynchronous];
476 476
@@ -962,6 +962,8 @@ static BOOL isiPhoneOS2; @@ -962,6 +962,8 @@ static BOOL isiPhoneOS2;
962 return; 962 return;
963 } 963 }
964 964
  965 + if (readStream) {
  966 +
965 // Find out if we've sent any more data than last time, and reset the timeout if so 967 // Find out if we've sent any more data than last time, and reset the timeout if so
966 if (totalBytesSent > lastBytesSent) { 968 if (totalBytesSent > lastBytesSent) {
967 [self setLastActivityTime:[NSDate date]]; 969 [self setLastActivityTime:[NSDate date]];
@@ -976,6 +978,7 @@ static BOOL isiPhoneOS2; @@ -976,6 +978,7 @@ static BOOL isiPhoneOS2;
976 978
977 // Measure bandwidth used, and throttle if nescessary 979 // Measure bandwidth used, and throttle if nescessary
978 [ASIHTTPRequest measureBandwidthUsage]; 980 [ASIHTTPRequest measureBandwidthUsage];
  981 + }
979 982
980 // This thread should wait for 1/4 second for the stream to do something 983 // This thread should wait for 1/4 second for the stream to do something
981 CFRunLoopRunInMode(ASIHTTPRequestRunMode,0.25,NO); 984 CFRunLoopRunInMode(ASIHTTPRequestRunMode,0.25,NO);
@@ -1740,8 +1743,7 @@ static BOOL isiPhoneOS2; @@ -1740,8 +1743,7 @@ static BOOL isiPhoneOS2;
1740 // Called by delegate or authentication dialog to resume loading once authentication info has been populated 1743 // Called by delegate or authentication dialog to resume loading once authentication info has been populated
1741 - (void)retryUsingSuppliedCredentials 1744 - (void)retryUsingSuppliedCredentials
1742 { 1745 {
1743 - [[self authenticationLock] lockWhenCondition:1]; 1746 + [self attemptToApplyCredentialsAndResume];
1744 - [[self authenticationLock] unlockWithCondition:2];  
1745 } 1747 }
1746 1748
1747 // Called by delegate or authentication dialog to cancel authentication 1749 // Called by delegate or authentication dialog to cancel authentication
@@ -1980,10 +1982,10 @@ static BOOL isiPhoneOS2; @@ -1980,10 +1982,10 @@ static BOOL isiPhoneOS2;
1980 1982
1981 - (BOOL)askDelegateForCredentials 1983 - (BOOL)askDelegateForCredentials
1982 { 1984 {
1983 - // Can't use delegate authentication when running on the main thread 1985 +// // Can't use delegate authentication when running on the main thread
1984 - if ([NSThread isMainThread]) { 1986 +// if ([NSThread isMainThread]) {
1985 - return NO; 1987 +// return NO;
1986 - } 1988 +// }
1987 1989
1988 // If we have a delegate, we'll see if it can handle proxyAuthenticationNeededForRequest:. 1990 // If we have a delegate, we'll see if it can handle proxyAuthenticationNeededForRequest:.
1989 // Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate 1991 // Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate
@@ -1994,13 +1996,13 @@ static BOOL isiPhoneOS2; @@ -1994,13 +1996,13 @@ static BOOL isiPhoneOS2;
1994 1996
1995 if ([authenticationDelegate respondsToSelector:@selector(authenticationNeededForRequest:)]) { 1997 if ([authenticationDelegate respondsToSelector:@selector(authenticationNeededForRequest:)]) {
1996 [authenticationDelegate performSelectorOnMainThread:@selector(authenticationNeededForRequest:) withObject:self waitUntilDone:[NSThread isMainThread]]; 1998 [authenticationDelegate performSelectorOnMainThread:@selector(authenticationNeededForRequest:) withObject:self waitUntilDone:[NSThread isMainThread]];
1997 - [[self authenticationLock] lockWhenCondition:2]; 1999 + //[[self authenticationLock] lockWhenCondition:2];
1998 - [[self authenticationLock] unlockWithCondition:1]; 2000 +// [[self authenticationLock] unlockWithCondition:1];
1999 - 2001 +//
2000 - // Was the request cancelled? 2002 +// // Was the request cancelled?
2001 - if ([self error] || [[self mainRequest] error]) { 2003 +// if ([self error] || [[self mainRequest] error]) {
2002 - return NO; 2004 +// return NO;
2003 - } 2005 + //}
2004 return YES; 2006 return YES;
2005 } 2007 }
2006 return NO; 2008 return NO;
@@ -2144,8 +2146,6 @@ static BOOL isiPhoneOS2; @@ -2144,8 +2146,6 @@ static BOOL isiPhoneOS2;
2144 return; 2146 return;
2145 } 2147 }
2146 if ([self askDelegateForCredentials]) { 2148 if ([self askDelegateForCredentials]) {
2147 - [self attemptToApplyCredentialsAndResume];  
2148 - [delegateAuthenticationLock unlock];  
2149 return; 2149 return;
2150 } 2150 }
2151 2151
@@ -190,7 +190,7 @@ @@ -190,7 +190,7 @@
190 ASIHTTPRequest *request; 190 ASIHTTPRequest *request;
191 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/top_secret/"]] autorelease]; 191 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/top_secret/"]] autorelease];
192 [request setDidFinishSelector:@selector(topSecretFetchComplete:)]; 192 [request setDidFinishSelector:@selector(topSecretFetchComplete:)];
193 - 193 + [request setDelegate:self];
194 [request setUseKeychainPersistance:[keychainCheckbox state]]; 194 [request setUseKeychainPersistance:[keychainCheckbox state]];
195 [request startAsynchronous]; 195 [request startAsynchronous];
196 196