Ben Copsey

More wack-a-mole style bug fixing

... ... @@ -21,7 +21,7 @@
#import "ASIInputStream.h"
// Automatically set on build
NSString *ASIHTTPRequestVersion = @"v1.2-43 2009-12-18";
NSString *ASIHTTPRequestVersion = @"v1.2-44 2009-12-18";
NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
... ... @@ -867,6 +867,16 @@ static BOOL isiPhoneOS2;
return;
}
// Start the HTTP connection
if (!CFReadStreamOpen(readStream)) {
[self destroyReadStream];
[[self cancelledLock] unlock];
[self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileBuildingRequestType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Unable to start HTTP connection",NSLocalizedDescriptionKey,nil]]];
return;
}
[[self cancelledLock] unlock];
if (shouldResetProgressIndicators) {
double amount = 1;
if (showAccurateProgress) {
... ... @@ -883,17 +893,16 @@ static BOOL isiPhoneOS2;
// Record when the request started, so we can timeout if nothing happens
[self setLastActivityTime:[NSDate date]];
// Schedule the stream
if (!throttleWakeUpTime || [throttleWakeUpTime timeIntervalSinceDate:[NSDate date]] < 0) {
[self scheduleReadStream];
}
[[self cancelledLock] unlock];
}
- (void)loadAsynchronous
{
// Schedule the stream
if (!readStreamIsScheduled && (!throttleWakeUpTime || [throttleWakeUpTime timeIntervalSinceDate:[NSDate date]] < 0)) {
[self scheduleReadStream];
}
[NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(updateStatus:) userInfo:nil repeats:YES];
// If we're running asynchronously on the main thread, the runloop will already be running
... ... @@ -907,6 +916,11 @@ static BOOL isiPhoneOS2;
// This is the main loop for synchronous requests.
- (void)loadSynchronous
{
// Schedule the stream
if (!readStreamIsScheduled && (!throttleWakeUpTime || [throttleWakeUpTime timeIntervalSinceDate:[NSDate date]] < 0)) {
[self scheduleReadStream];
}
while (!complete) {
[self checkRequestStatus];
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.25, NO);
... ... @@ -968,7 +982,6 @@ static BOOL isiPhoneOS2;
} else {
[[self cancelledLock] unlock];
// Go all the way back to the beginning and build the request again, so that we can apply any new cookies
[self main];
}
return;
... ... @@ -991,10 +1004,6 @@ static BOOL isiPhoneOS2;
}
// This thread should wait for 1/4 second for the stream to do something
//CFRunLoopRunInMode(kCFRunLoopDefaultMode,0.25,NO);
[[self cancelledLock] unlock];
}
... ... @@ -2358,7 +2367,9 @@ static BOOL isiPhoneOS2;
{
if (readStream) {
CFReadStreamSetClient(readStream, kCFStreamEventNone, NULL, NULL);
CFReadStreamUnscheduleFromRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
if (readStreamIsScheduled) {
CFReadStreamUnscheduleFromRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
}
CFReadStreamClose(readStream);
CFRelease(readStream);
readStream = NULL;
... ... @@ -2370,24 +2381,14 @@ static BOOL isiPhoneOS2;
if (readStream && !readStreamIsScheduled) {
// Reset the timeout
[self setLastActivityTime:[NSDate date]];
CFStreamClientContext ctxt = {0, self, NULL, NULL, NULL};
CFReadStreamSetClient(readStream, kNetworkEvents, ReadStreamClientCallBack, &ctxt);
CFReadStreamScheduleWithRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
readStreamIsScheduled = YES;
// Start the HTTP connection
if (!CFReadStreamOpen(readStream)) {
[self destroyReadStream];
[self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileBuildingRequestType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Unable to start HTTP connection",NSLocalizedDescriptionKey,nil]]];
return;
}
}
}
- (void)unscheduleReadStream
{
if (readStream && readStreamIsScheduled) {
CFReadStreamSetClient(readStream, kCFStreamEventNone, NULL, NULL);
CFReadStreamUnscheduleFromRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
readStreamIsScheduled = NO;
}
... ...
... ... @@ -1044,11 +1044,11 @@
// We'll test first without throttling
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/the_great_american_novel_%28abridged%29.txt"]];
NSDate *date = [NSDate date];
//[request startSynchronous];
[request startSynchronous];
NSTimeInterval interval =[date timeIntervalSinceNow];
BOOL success = (interval > -7);
//GHAssertTrue(success,@"Downloaded the file too slowly - either this is a bug, or your internet connection is too slow to run this test (must be able to download 128KB in less than 7 seconds, without throttling)");
GHAssertTrue(success,@"Downloaded the file too slowly - either this is a bug, or your internet connection is too slow to run this test (must be able to download 128KB in less than 7 seconds, without throttling)");
// Now we'll test with throttling
[ASIHTTPRequest setMaxBandwidthPerSecond:ASIWWANBandwidthThrottleAmount];
... ...
... ... @@ -695,6 +695,7 @@ IMPORTANT
[request setDownloadDestinationPath:downloadPath];
[request setTemporaryFileDownloadPath:temporaryPath];
[request setAllowResumeForFileDownloads:YES];
[networkQueue setRunRequestsInBackgroundThread:YES];
[networkQueue addOperation:request];
[networkQueue go];
... ... @@ -754,6 +755,7 @@ IMPORTANT
[networkQueue setDownloadProgressDelegate:self];
[networkQueue setShowAccurateProgress:YES];
[networkQueue setDelegate:self];
[networkQueue setRunRequestsInBackgroundThread:YES];
[networkQueue setQueueDidFinishSelector:@selector(queueFinished:)];
request = [[[ASIHTTPRequest alloc] initWithURL:downloadURL] autorelease];
... ...