From ffe54e9149ebd0a3c2912ca671417277045e4481 Mon Sep 17 00:00:00 2001 From: Ben Copsey Date: Wed, 14 Apr 2010 10:17:33 +0100 Subject: [PATCH] Progress API cleanup Use slightly stricter build config, fix 64bit issues --- Classes/ASIFormDataRequest.m | 4 +- Classes/ASIHTTPRequest.h | 23 ++- Classes/ASIHTTPRequest.m | 233 +++++++++++++++---------------- Classes/ASIHTTPRequestDelegate.h | 1 + Classes/ASINetworkQueue.h | 7 +- Classes/ASINetworkQueue.m | 37 +++-- Classes/ASIProgressDelegate.h | 4 +- Mac Sample/AppDelegate.h | 11 ++ Mac Sample/AppDelegate.m | 8 +- Mac.xcodeproj/project.pbxproj | 2 + strict.xcconfig | 4 +- 11 files changed, 189 insertions(+), 145 deletions(-) diff --git a/Classes/ASIFormDataRequest.m b/Classes/ASIFormDataRequest.m index 40b7d35a..1c0a1b6b 100644 --- a/Classes/ASIFormDataRequest.m +++ b/Classes/ASIFormDataRequest.m @@ -243,8 +243,8 @@ - (void)buildURLEncodedPostBody NSEnumerator *e = [[self postData] keyEnumerator]; NSString *key; - int i=0; - int count = [[self postData] count]-1; + NSUInteger i=0; + NSUInteger count = [[self postData] count]-1; while (key = [e nextObject]) { NSString *data = [NSString stringWithFormat:@"%@=%@%@", [self encodeURL:key], [self encodeURL:[[self postData] objectForKey:key]],(i= 3.0 - if ([ASIHTTPRequest isiPhoneOS2]) { - amount = [[NSNumber numberWithUnsignedLongLong:[self postLength]] doubleValue]; - } else { - amount = (double)[self postLength]; - } + [self incrementUploadSizeBy:[self postLength]]; + } else { + [self incrementUploadSizeBy:1]; } - [self resetUploadProgressWithNewLength:amount]; } @@ -1112,16 +1109,16 @@ - (BOOL)shouldTimeOut { NSTimeInterval secondsSinceLastActivity = [[NSDate date] timeIntervalSinceDate:lastActivityTime]; // See if we need to timeout - if ([self readStream] && [self readStreamIsScheduled] && lastActivityTime && timeOutSeconds > 0 && secondsSinceLastActivity > timeOutSeconds) { + if ([self readStream] && [self readStreamIsScheduled] && [self lastActivityTime] && [self timeOutSeconds] > 0 && secondsSinceLastActivity > [self timeOutSeconds]) { // We have no body, or we've sent more than the upload buffer size,so we can safely time out here - if (postLength == 0 || (uploadBufferSize > 0 && totalBytesSent > uploadBufferSize)) { + if ([self postLength] == 0 || ([self uploadBufferSize] > 0 && [self totalBytesSent] > [self uploadBufferSize])) { return YES; // ***Black magic warning*** - // We have a body, but we've taken longer than timeout seconds to upload the first small chunk of data + // We have a body, but we've taken longer than timeOutSeconds to upload the first small chunk of data // Since there's no reliable way to track upload progress for the first 32KB (iPhone) or 128KB (Mac) with CFNetwork, we'll be slightly more forgiving on the timeout, as there's a strong chance our connection is just very slow. - } else if (secondsSinceLastActivity > timeOutSeconds*1.5) { + } else if (secondsSinceLastActivity > [self timeOutSeconds]*1.5) { return YES; } } @@ -1270,7 +1267,6 @@ - (ASIHTTPRequest *)HEADRequest - (void)updateProgressIndicators { - //Only update progress if this isn't a HEAD request used to preset the content-length if (![self mainRequest]) { if ([self showAccurateProgress] || ([self complete] && ![self updatedProgress])) { @@ -1284,49 +1280,40 @@ - (void)updateProgressIndicators - (void)setUploadProgressDelegate:(id)newDelegate { [[self cancelledLock] lock]; - uploadProgressDelegate = newDelegate; -#if !TARGET_OS_IPHONE - // If the uploadProgressDelegate is an NSProgressIndicator, we set it's MaxValue to 1.0 so we can treat it similarly to UIProgressViews - SEL selector = @selector(setMaxValue:); - if ([uploadProgressDelegate respondsToSelector:selector]) { - double max = 1.0; - [ASIHTTPRequest performSelector:selector onTarget:[self uploadProgressDelegate] withObject:nil args:&max,nil]; - } -#endif + #if !TARGET_OS_IPHONE + // If the uploadProgressDelegate is an NSProgressIndicator, we set its MaxValue to 1.0 so we can update it as if it were a UIProgressView + double max = 1.0; + [ASIHTTPRequest performSelector:@selector(setMaxValue:) onTarget:[self uploadProgressDelegate] withObject:nil amount:&max]; + #endif [[self cancelledLock] unlock]; } - (void)setDownloadProgressDelegate:(id)newDelegate { [[self cancelledLock] lock]; - downloadProgressDelegate = newDelegate; -#if !TARGET_OS_IPHONE - // If the downloadProgressDelegate is an NSProgressIndicator, we set it's MaxValue to 1.0 so we can treat it similarly to UIProgressViews - SEL selector = @selector(setMaxValue:); - if ([downloadProgressDelegate respondsToSelector:selector]) { - double max = 1.0; - [ASIHTTPRequest performSelector:selector onTarget:[self downloadProgressDelegate] withObject:nil args:&max,nil]; - } -#endif + #if !TARGET_OS_IPHONE + // If the downloadProgressDelegate is an NSProgressIndicator, we set its MaxValue to 1.0 so we can update it as if it were a UIProgressView + double max = 1.0; + [ASIHTTPRequest performSelector:@selector(setMaxValue:) onTarget:[self downloadProgressDelegate] withObject:nil amount:&max]; + #endif [[self cancelledLock] unlock]; } - (void)updateDownloadProgress { - // We won't update download progress until we've examined the headers, since we might need to authenticate if (![self responseHeaders] || [self needsRedirect] || !([self contentLength] || [self complete])) { return; } unsigned long long bytesReadSoFar = [self totalBytesRead]+[self partialDownloadSize]; - unsigned long long value = 0; + if ([self showAccurateProgress] && [self contentLength]) { value = bytesReadSoFar-[self lastBytesRead]; if (value == 0) { @@ -1336,10 +1323,9 @@ - (void)updateDownloadProgress value = 1; [self setUpdatedProgress:YES]; } - - [ASIHTTPRequest performSelector:@selector(request:didReceiveBytes:) onTarget:[self queue] withObject:self args:&value,nil]; - [ASIHTTPRequest performSelector:@selector(request:didReceiveBytes:) onTarget:[self downloadProgressDelegate] withObject:self args:&value,nil]; + [ASIHTTPRequest performSelector:@selector(request:didReceiveBytes:) onTarget:[self queue] withObject:self amount:&value]; + [ASIHTTPRequest performSelector:@selector(request:didReceiveBytes:) onTarget:[self downloadProgressDelegate] withObject:self amount:&value]; [ASIHTTPRequest updateProgressIndicator:[self downloadProgressDelegate] withProgress:[self totalBytesRead]+[self partialDownloadSize] ofTotal:[self contentLength]+[self partialDownloadSize]]; [self setLastBytesRead:bytesReadSoFar]; @@ -1352,15 +1338,16 @@ - (void)updateUploadProgress return; } - // If this is the first time we've written to the buffer, byteCount will be the size of the buffer (currently seems to be 128KB on both Leopard and iPhone 2.2.1, 32KB on iPhone 3.0) - // If request body is less than the buffer size, byteCount will be the total size of the request body + // If this is the first time we've written to the buffer, totalBytesSent will be the size of the buffer (currently seems to be 128KB on both Leopard and iPhone 2.2.1, 32KB on iPhone 3.0) + // If request body is less than the buffer size, totalBytesSent will be the total size of the request body // We will remove this from any progress display, as kCFStreamPropertyHTTPRequestBytesWrittenCount does not tell us how much data has actually be written if ([self uploadBufferSize] == 0 && [self totalBytesSent] != [self postLength]) { [self setUploadBufferSize:[self totalBytesSent]]; - [self resetUploadProgressWithNewLength:-[self uploadBufferSize]]; + [self incrementUploadSizeBy:-[self uploadBufferSize]]; } unsigned long long value = 0; + if ([self showAccurateProgress]) { if ([self totalBytesSent] == [self postLength] || [self lastBytesSent] > 0) { value = [self totalBytesSent]-[self lastBytesSent]; @@ -1372,36 +1359,38 @@ - (void)updateUploadProgress [self setUpdatedProgress:YES]; } - [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:[self queue] withObject:self args:&value,nil]; - [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:[self uploadProgressDelegate] withObject:self args:&value,nil]; + [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:[self queue] withObject:self amount:&value]; + [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:[self uploadProgressDelegate] withObject:self amount:&value]; [ASIHTTPRequest updateProgressIndicator:[self uploadProgressDelegate] withProgress:[self totalBytesSent] ofTotal:[self postLength]]; } -- (void)resetDownloadProgressWithNewLength:(unsigned long long)length +- (void)incrementDownloadSizeBy:(long long)length { - [ASIHTTPRequest performSelector:@selector(request:resetDownloadContentLength:) onTarget:[self queue] withObject:self args:&length,nil]; - [ASIHTTPRequest performSelector:@selector(request:resetDownloadContentLength:) onTarget:[self uploadProgressDelegate] withObject:self args:&length,nil]; + [ASIHTTPRequest performSelector:@selector(request:incrementDownloadSizeBy:) onTarget:[self queue] withObject:self amount:&length]; + [ASIHTTPRequest performSelector:@selector(request:incrementDownloadSizeBy:) onTarget:[self uploadProgressDelegate] withObject:self amount:&length]; [ASIHTTPRequest updateProgressIndicator:[self uploadProgressDelegate] withProgress:0 ofTotal:length]; } -- (void)resetUploadProgressWithNewLength:(unsigned long long)length + +- (void)incrementUploadSizeBy:(long long)length { - [ASIHTTPRequest performSelector:@selector(request:resetUploadContentLength:) onTarget:[self queue] withObject:self args:&length,nil]; - [ASIHTTPRequest performSelector:@selector(request:resetUploadContentLength:) onTarget:[self uploadProgressDelegate] withObject:self args:&length,nil]; + [ASIHTTPRequest performSelector:@selector(request:incrementUploadSizeBy:) onTarget:[self queue] withObject:self amount:&length]; + [ASIHTTPRequest performSelector:@selector(request:incrementUploadSizeBy:) onTarget:[self uploadProgressDelegate] withObject:self amount:&length]; [ASIHTTPRequest updateProgressIndicator:[self uploadProgressDelegate] withProgress:0 ofTotal:length]; } + -(void)removeUploadProgressSoFar { long long progressToRemove = -[self totalBytesSent]; - [ASIHTTPRequest performSelector:@selector(request:didReceiveBytes:) onTarget:[self queue] withObject:self args:&progressToRemove,nil]; - [ASIHTTPRequest performSelector:@selector(request:didReceiveBytes:) onTarget:[self downloadProgressDelegate] withObject:self args:&progressToRemove,nil]; + [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:[self queue] withObject:self amount:&progressToRemove]; + [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:[self downloadProgressDelegate] withObject:self amount:&progressToRemove]; [ASIHTTPRequest updateProgressIndicator:[self uploadProgressDelegate] withProgress:0 ofTotal:[self postLength]]; } -+ (void)performSelector:(SEL)selector onTarget:(id)target withObject:(id)object args:(void *)firstArgument, ... ++ (void)performSelector:(SEL)selector onTarget:(id)target withObject:(id)object amount:(void *)amount { if ([target respondsToSelector:selector]) { NSMethodSignature *signature = nil; @@ -1410,23 +1399,19 @@ + (void)performSelector:(SEL)selector onTarget:(id)target withObject:(id)object [invocation setTarget:target]; [invocation setSelector:selector]; - void *argument; int argumentNumber = 2; + + // If we got an object parameter, we pass a pointer to the object pointer if (object) { - [invocation setArgument:&argument atIndex:argumentNumber]; + [invocation setArgument:&object atIndex:argumentNumber]; argumentNumber++; } - if (firstArgument) { - [invocation setArgument:firstArgument atIndex:argumentNumber]; - argumentNumber++; - } - va_list args; - va_start(args, firstArgument); - while(argument = va_arg(args, void *) ) { - [invocation setArgument:argument atIndex:argumentNumber]; - argumentNumber++; + + // For the amount we'll just pass the pointer directly so NSInvocation will call the method using the number itself rather than a pointer to it + if (amount) { + [invocation setArgument:amount atIndex:argumentNumber]; } - va_end(args); + [invocation performSelectorOnMainThread:@selector(invokeWithTarget:) withObject:target waitUntilDone:[NSThread isMainThread]]; } } @@ -1434,32 +1419,30 @@ + (void)performSelector:(SEL)selector onTarget:(id)target withObject:(id)object + (void)updateProgressIndicator:(id)indicator withProgress:(unsigned long long)progress ofTotal:(unsigned long long)total { -#if TARGET_OS_IPHONE - // Cocoa Touch: UIProgressView - float progressAmount; - SEL selector = @selector(setProgress:); -#else - // Cocoa: NSProgressIndicator - double progressAmount; - SEL selector = @selector(setDoubleValue:); -#endif + #if TARGET_OS_IPHONE + // Cocoa Touch: UIProgressView + float progressAmount; + SEL selector = @selector(setProgress:); + //Workaround for an issue with converting a long to a double on iPhone OS 2.2.1 with a base SDK >= 3.0 + if ([ASIHTTPRequest isiPhoneOS2]) { + progressAmount = [[NSNumber numberWithUnsignedLongLong:progress] floatValue]/[[NSNumber numberWithUnsignedLongLong:total] floatValue]; + } else { + progressAmount = (progress*1.0f)/(total*1.0f); + } + + #else + // Cocoa: NSProgressIndicator + double progressAmount = progressAmount = (progress*1.0)/(total*1.0); + SEL selector = @selector(setDoubleValue:); + #endif + if (![indicator respondsToSelector:selector]) { return; } - - - //Workaround for an issue with converting a long to a double on iPhone OS 2.2.1 with a base SDK >= 3.0 - if ([ASIHTTPRequest isiPhoneOS2]) { - progressAmount = [[NSNumber numberWithUnsignedLongLong:progress] doubleValue]/[[NSNumber numberWithUnsignedLongLong:total] doubleValue]; - } else { - progressAmount = (progress*1.0)/(total*1.0); - } [progressLock lock]; - - - [ASIHTTPRequest performSelector:selector onTarget:indicator withObject:nil args:&progressAmount,nil]; + [ASIHTTPRequest performSelector:selector onTarget:indicator withObject:nil amount:&progressAmount]; [progressLock unlock]; } @@ -1467,6 +1450,23 @@ + (void)updateProgressIndicator:(id)indicator withProgress:(unsigned long long)p #pragma mark handling request complete / failure + +- (void)requestReceivedResponseHeaders +{ + if ([self error] || [self mainRequest]) { + return; + } + // Let the delegate know we have started + if ([self didReceiveResponseHeadersSelector] && [[self delegate] respondsToSelector:[self didReceiveResponseHeadersSelector]]) { + [[self delegate] performSelectorOnMainThread:[self didReceiveResponseHeadersSelector] withObject:self waitUntilDone:[NSThread isMainThread]]; + } + + // Let the queue know we have started + if ([[self queue] respondsToSelector:@selector(requestReceivedResponseHeaders:)]) { + [[self queue] performSelectorOnMainThread:@selector(requestReceivedResponseHeaders:) withObject:self waitUntilDone:[NSThread isMainThread]]; + } +} + - (void)requestStarted { if ([self error] || [self mainRequest]) { @@ -1478,11 +1478,9 @@ - (void)requestStarted } // Let the queue know we have started - if ([[self queue] respondsToSelector:@selector(requestDidStart:)]) { - [[self queue] performSelectorOnMainThread:@selector(requestDidStart:) withObject:self waitUntilDone:[NSThread isMainThread]]; + if ([[self queue] respondsToSelector:@selector(requestStarted:)]) { + [[self queue] performSelectorOnMainThread:@selector(requestStarted:) withObject:self waitUntilDone:[NSThread isMainThread]]; } - - } // Subclasses might override this method to process the result in the same thread @@ -1501,8 +1499,8 @@ - (void)requestFinished } // Let the queue know we are done - if ([[self queue] respondsToSelector:@selector(requestDidFinish:)]) { - [[self queue] performSelectorOnMainThread:@selector(requestDidFinish:) withObject:self waitUntilDone:[NSThread isMainThread]]; + if ([[self queue] respondsToSelector:@selector(requestFinished:)]) { + [[self queue] performSelectorOnMainThread:@selector(requestFinished:) withObject:self waitUntilDone:[NSThread isMainThread]]; } } @@ -1551,8 +1549,8 @@ - (void)failWithError:(NSError *)theError } // Let the queue know something went wrong - if ([[failedRequest queue] respondsToSelector:@selector(requestDidFail:)]) { - [[failedRequest queue] performSelectorOnMainThread:@selector(requestDidFail:) withObject:failedRequest waitUntilDone:[NSThread isMainThread]]; + if ([[failedRequest queue] respondsToSelector:@selector(requestFailed:)]) { + [[failedRequest queue] performSelectorOnMainThread:@selector(requestFailed:) withObject:failedRequest waitUntilDone:[NSThread isMainThread]]; } [self markAsFinished]; @@ -1588,7 +1586,7 @@ - (void)readResponseHeaders [self setResponseHeaders:(NSDictionary *)headerFields]; CFRelease(headerFields); - [self setResponseStatusCode:CFHTTPMessageGetResponseStatusCode(message)]; + [self setResponseStatusCode:(int)CFHTTPMessageGetResponseStatusCode(message)]; [self setResponseStatusMessage:[(NSString *)CFHTTPMessageCopyResponseStatusLine(message) autorelease]]; // Is the server response a challenge for credentials? @@ -1619,28 +1617,29 @@ - (void)readResponseHeaders // See if we got a Content-length header NSString *cLength = [responseHeaders valueForKey:@"Content-Length"]; + ASIHTTPRequest *theRequest = self; + if ([self mainRequest]) { + theRequest = [self mainRequest]; + } + if (cLength) { SInt32 length = CFStringGetIntValue((CFStringRef)cLength); // Workaround for Apache HEAD requests for dynamically generated content returning the wrong Content-Length when using gzip if ([self mainRequest] && [self allowCompressedResponse] && length == 20 && [self showAccurateProgress] && [self shouldResetProgressIndicators]) { [[self mainRequest] setShowAccurateProgress:NO]; - [self resetDownloadProgressWithNewLength:1]; + [[self mainRequest] incrementDownloadSizeBy:1]; } else { - [self setContentLength:length]; - if ([self mainRequest]) { - [[self mainRequest] setContentLength:length]; - } - + [theRequest setContentLength:length]; if ([self showAccurateProgress] && [self shouldResetProgressIndicators]) { - [self resetDownloadProgressWithNewLength:[self contentLength]+[self partialDownloadSize]]; + [theRequest incrementDownloadSizeBy:[self contentLength]+[self partialDownloadSize]]; } } } else if ([self showAccurateProgress] && [self shouldResetProgressIndicators]) { - [[self mainRequest] setShowAccurateProgress:NO]; - [self resetDownloadProgressWithNewLength:1]; + [theRequest setShowAccurateProgress:NO]; + [theRequest incrementDownloadSizeBy:1]; } // Handle response text encoding @@ -1766,9 +1765,8 @@ - (void)readResponseHeaders } } - - CFRelease(message); + [self requestReceivedResponseHeaders]; } #pragma mark http authentication @@ -2971,8 +2969,8 @@ + (void)addSessionCookie:(NSHTTPCookie *)newCookie { [sessionCookiesLock lock]; NSHTTPCookie *cookie; - int i; - int max = [[ASIHTTPRequest sessionCookies] count]; + NSUInteger i; + NSUInteger max = [[ASIHTTPRequest sessionCookies] count]; for (i=0; i +#import "ASIHTTPRequestDelegate.h" #import "ASIProgressDelegate.h" -@interface ASINetworkQueue : NSOperationQueue { +@interface ASINetworkQueue : NSOperationQueue { // Delegate will get didFail + didFinish messages (if set) id delegate; @@ -17,6 +18,9 @@ // Will be called when a request starts with the request as the argument SEL requestDidStartSelector; + // Will be called when a request receives response headers with the request as the argument + SEL requestDidReceiveResponseHeadersSelector; + // Will be called when a request completes with the request as the argument SEL requestDidFinishSelector; @@ -88,6 +92,7 @@ @property (assign,setter=setDownloadProgressDelegate:) id downloadProgressDelegate; @property (assign) SEL requestDidStartSelector; +@property (assign) SEL requestDidReceiveResponseHeadersSelector; @property (assign) SEL requestDidFinishSelector; @property (assign) SEL requestDidFailSelector; @property (assign) SEL queueDidFinishSelector; diff --git a/Classes/ASINetworkQueue.m b/Classes/ASINetworkQueue.m index 9e341a8a..c3f833a7 100644 --- a/Classes/ASINetworkQueue.m +++ b/Classes/ASINetworkQueue.m @@ -66,6 +66,7 @@ - (void)reset [self setDownloadProgressDelegate:nil]; [self setUploadProgressDelegate:nil]; [self setRequestDidStartSelector:NULL]; + [self setRequestDidReceiveResponseHeadersSelector:NULL]; [self setRequestDidFailSelector:NULL]; [self setRequestDidFinishSelector:NULL]; [self setQueueDidFinishSelector:NULL]; @@ -197,45 +198,54 @@ - (void)addOperation:(NSOperation *)operation } -- (void)requestDidStart:(ASIHTTPRequest *)request +- (void)requestStarted:(ASIHTTPRequest *)request { if ([self requestDidStartSelector]) { [[self delegate] performSelector:[self requestDidStartSelector] withObject:request]; } } -- (void)requestDidFail:(ASIHTTPRequest *)request +- (void)requestDidReceiveResponseHeaders:(ASIHTTPRequest *)request +{ + if ([self requestDidReceiveResponseHeadersSelector]) { + [[self delegate] performSelector:[self requestDidReceiveResponseHeadersSelector] withObject:request]; + } +} + + +- (void)requestFinished:(ASIHTTPRequest *)request { [self setRequestsCount:[self requestsCount]-1]; [self updateNetworkActivityIndicator]; - if ([self requestDidFailSelector]) { - [[self delegate] performSelector:[self requestDidFailSelector] withObject:request]; + if ([self requestDidFinishSelector]) { + [[self delegate] performSelector:[self requestDidFinishSelector] withObject:request]; } if ([self requestsCount] == 0) { if ([self queueDidFinishSelector]) { [[self delegate] performSelector:[self queueDidFinishSelector] withObject:self]; } } - if ([self shouldCancelAllRequestsOnFailure] && [self requestsCount] > 0) { - [self cancelAllOperations]; - } - } -- (void)requestDidFinish:(ASIHTTPRequest *)request +- (void)requestFailed:(ASIHTTPRequest *)request { [self setRequestsCount:[self requestsCount]-1]; [self updateNetworkActivityIndicator]; - if ([self requestDidFinishSelector]) { - [[self delegate] performSelector:[self requestDidFinishSelector] withObject:request]; + if ([self requestDidFailSelector]) { + [[self delegate] performSelector:[self requestDidFailSelector] withObject:request]; } if ([self requestsCount] == 0) { if ([self queueDidFinishSelector]) { [[self delegate] performSelector:[self queueDidFinishSelector] withObject:self]; } } + if ([self shouldCancelAllRequestsOnFailure] && [self requestsCount] > 0) { + [self cancelAllOperations]; + } + } + - (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes { [self setBytesDownloadedSoFar:[self bytesDownloadedSoFar]+bytes]; @@ -252,12 +262,12 @@ - (void)request:(ASIHTTPRequest *)request didSendBytes:(long long)bytes } } -- (void)request:(ASIHTTPRequest *)request resetDownloadContentLength:(long long)newLength +- (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength { [self setTotalBytesToDownload:[self totalBytesToDownload]+newLength]; } -- (void)request:(ASIHTTPRequest *)request resetUploadContentLength:(long long)newLength +- (void)request:(ASIHTTPRequest *)request incrementUploadSizeBy:(long long)newLength { [self setTotalBytesToUpload:[self totalBytesToUpload]+newLength]; } @@ -323,6 +333,7 @@ - (id)copyWithZone:(NSZone *)zone @synthesize uploadProgressDelegate; @synthesize downloadProgressDelegate; @synthesize requestDidStartSelector; +@synthesize requestDidReceiveResponseHeadersSelector; @synthesize requestDidFinishSelector; @synthesize requestDidFailSelector; @synthesize queueDidFinishSelector; diff --git a/Classes/ASIProgressDelegate.h b/Classes/ASIProgressDelegate.h index 58c9a065..fe7fe2b6 100644 --- a/Classes/ASIProgressDelegate.h +++ b/Classes/ASIProgressDelegate.h @@ -30,8 +30,8 @@ - (void)request:(ASIHTTPRequest *)request didSendBytes:(long long)bytes; // Called when a request needs to change the length of the content to download -- (void)request:(ASIHTTPRequest *)request resetDownloadContentLength:(long long)newLength; +- (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength; // Called when a request needs to change the length of the content to upload -- (void)request:(ASIHTTPRequest *)request resetUploadContentLength:(long long)newLength; +- (void)request:(ASIHTTPRequest *)request incrementUploadSizeBy:(long long)newLength; @end diff --git a/Mac Sample/AppDelegate.h b/Mac Sample/AppDelegate.h index f7a6a234..5686a46e 100644 --- a/Mac Sample/AppDelegate.h +++ b/Mac Sample/AppDelegate.h @@ -57,5 +57,16 @@ - (IBAction)throttleBandwidth:(id)sender; +- (void)updateBandwidthUsageIndicator; +- (void)URLFetchWithProgressComplete:(ASIHTTPRequest *)request; +- (void)URLFetchWithProgressFailed:(ASIHTTPRequest *)request; +- (void)imageFetch1Complete:(ASIHTTPRequest *)request; +- (void)imageFetch2Complete:(ASIHTTPRequest *)request; +- (void)imageFetch3Complete:(ASIHTTPRequest *)request; +- (void)topSecretFetchComplete:(ASIHTTPRequest *)request; +- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo; +- (void)postFinished:(ASIHTTPRequest *)request; +- (void)postFailed:(ASIHTTPRequest *)request; + @property (retain, nonatomic) ASIHTTPRequest *bigFetchRequest; @end diff --git a/Mac Sample/AppDelegate.m b/Mac Sample/AppDelegate.m index 84d3a95c..bdcbdc34 100644 --- a/Mac Sample/AppDelegate.m +++ b/Mac Sample/AppDelegate.m @@ -16,8 +16,7 @@ - (id)init { [super init]; networkQueue = [[ASINetworkQueue alloc] init]; - NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateBandwidthUsageIndicator) userInfo:nil repeats:YES]; - timer = nil; + [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateBandwidthUsageIndicator) userInfo:nil repeats:YES]; return self; } @@ -206,7 +205,7 @@ - (IBAction)fetchTopSecretInformation:(id)sender } -- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)request +- (void)topSecretFetchComplete:(ASIHTTPRequest *)request { if (![request error]) { [topSecretInfo setStringValue:[request responseString]]; @@ -243,7 +242,8 @@ - (IBAction)dismissAuthSheet:(id)sender { [[NSApplication sharedApplication] endSheet: loginWindow returnCode: [(NSControl*)sender tag]]; } -- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo { +- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo +{ ASIHTTPRequest *request = (ASIHTTPRequest *)contextInfo; if (returnCode == NSOKButton) { if ([request authenticationNeeded] == ASIProxyAuthenticationNeeded) { diff --git a/Mac.xcodeproj/project.pbxproj b/Mac.xcodeproj/project.pbxproj index c8ee04a1..0ec44816 100644 --- a/Mac.xcodeproj/project.pbxproj +++ b/Mac.xcodeproj/project.pbxproj @@ -635,6 +635,7 @@ }; C01FCF4B08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = B515507810BD56E800608267 /* strict.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; COPY_PHASE_STRIP = NO; @@ -654,6 +655,7 @@ }; C01FCF4C08A954540054247B /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = B515507810BD56E800608267 /* strict.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; diff --git a/strict.xcconfig b/strict.xcconfig index 4da6b5eb..f36501e0 100644 --- a/strict.xcconfig +++ b/strict.xcconfig @@ -13,11 +13,11 @@ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES GCC_WARN_ABOUT_RETURN_TYPE = YES //GCC_WARN_MISSING_PARENTHESES = YES GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES -//GCC_WARN_ABOUT_MISSING_NEWLINE = YES +GCC_WARN_ABOUT_MISSING_NEWLINE = YES GCC_WARN_SIGN_COMPARE = YES GCC_WARN_STRICT_SELECTOR_MATCH = missing value GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES -//GCC_WARN_UNDECLARED_SELECTOR = YES +GCC_WARN_UNDECLARED_SELECTOR = YES GCC_WARN_UNUSED_FUNCTION = YES GCC_WARN_UNUSED_LABEL = YES GCC_WARN_UNUSED_VALUE = YES