Jamie Pinkham

modified blocks, got rid of retain cycle

... ... @@ -66,11 +66,11 @@ extern NSString* const NetworkRequestErrorDomain;
extern unsigned long const ASIWWANBandwidthThrottleAmount;
#if NS_BLOCKS_AVAILABLE
typedef void (^ASIHTTPRequestBlock)(ASIHTTPRequest *request);
typedef void (^ASIHTTPRequestBlock)();
//typedef BOOL (^ASIHTTPRequestAuthenticationBlock)(ASIHTTPRequest *request);
typedef void (^ASIHTTPRequestSizeBlock)(ASIHTTPRequest *request, long long size);
typedef void (^ASIHTTPRequestProgressBlock)(ASIHTTPRequest *request, unsigned long long size, unsigned long long total);
typedef void (^ASIHTTPRequestDataReceivedBlock)(ASIHTTPRequest *request, NSData *data);
typedef void (^ASIHTTPRequestSizeBlock)(long long size);
typedef void (^ASIHTTPRequestProgressBlock)(unsigned long long size, unsigned long long total);
typedef void (^ASIHTTPRequestDataReceivedBlock)(NSData *data);
#endif
@interface ASIHTTPRequest : NSOperation <NSCopying> {
... ...
... ... @@ -1582,7 +1582,7 @@ static NSOperationQueue *sharedQueue = nil;
#if NS_BLOCKS_AVAILABLE
if(bytesReceivedBlock){
__block ASIHTTPRequest *blockCopy = self;
bytesReceivedBlock(blockCopy, bytesReadSoFar, blockCopy->contentLength + blockCopy->partialDownloadSize);
bytesReceivedBlock(bytesReadSoFar, blockCopy->contentLength + blockCopy->partialDownloadSize);
}
#endif
[self setLastBytesRead:bytesReadSoFar];
... ... @@ -1626,7 +1626,7 @@ static NSOperationQueue *sharedQueue = nil;
#if NS_BLOCKS_AVAILABLE
if(bytesSentBlock){
__block ASIHTTPRequest *blockCopy = self;
bytesSentBlock(blockCopy, value, blockCopy->postLength);
bytesSentBlock(value, blockCopy->postLength);
}
#endif
}
... ... @@ -1638,8 +1638,7 @@ static NSOperationQueue *sharedQueue = nil;
[ASIHTTPRequest performSelector:@selector(request:incrementDownloadSizeBy:) onTarget:&downloadProgressDelegate withObject:self amount:&length];
#if NS_BLOCKS_AVAILABLE
if(downloadSizeIncrementedBlock){
__block ASIHTTPRequest *blockCopy = self;
downloadSizeIncrementedBlock(blockCopy, length);
downloadSizeIncrementedBlock(length);
}
#endif
}
... ... @@ -1651,8 +1650,7 @@ static NSOperationQueue *sharedQueue = nil;
[ASIHTTPRequest performSelector:@selector(request:incrementUploadSizeBy:) onTarget:&uploadProgressDelegate withObject:self amount:&length];
#if NS_BLOCKS_AVAILABLE
if(uploadSizeIncrementedBlock){
__block ASIHTTPRequest *blockCopy = self;
uploadSizeIncrementedBlock(blockCopy, length);
uploadSizeIncrementedBlock(length);
}
#endif
}
... ... @@ -1667,7 +1665,7 @@ static NSOperationQueue *sharedQueue = nil;
#if NS_BLOCKS_AVAILABLE
if(bytesSentBlock){
__block ASIHTTPRequest *blockCopy = self;
bytesSentBlock(blockCopy, progressToRemove, blockCopy->postLength);
bytesSentBlock(progressToRemove, blockCopy->postLength);
}
#endif
}
... ... @@ -2870,8 +2868,7 @@ static NSOperationQueue *sharedQueue = nil;
#if NS_BLOCKS_AVAILABLE
if(dataReceivedBlock){
NSData *data = [NSData dataWithBytes:buffer length:bytesRead];
__block ASIHTTPRequest *blockCopy = self;
dataReceivedBlock(blockCopy, data);
dataReceivedBlock(data);
}
#endif
... ...
... ... @@ -17,14 +17,12 @@
- (IBAction)fetchThreeImages:(id)sender
{
ASIHTTPRequestSizeBlock sizeBlock = ^(ASIHTTPRequest *request, long long size){
NSDictionary *userInfo = [request userInfo];
NSLog(@"request - %@ named = %@ download size incremented %lld", request, [userInfo valueForKey:@"name"], size);
ASIHTTPRequestSizeBlock sizeBlock = ^(long long size){
NSLog(@"download size incremented %lld", size);
};
ASIHTTPRequestProgressBlock bytesBlock = ^(ASIHTTPRequest *request, unsigned long long size, unsigned long long total){
NSDictionary *userInfo = [request userInfo];
NSLog(@"request - %@ named - %@ downloaded bytes size %llu of total: %llu", request, [userInfo valueForKey:@"name"], size, total);
ASIHTTPRequestProgressBlock bytesBlock = ^(unsigned long long size, unsigned long long total){
NSLog(@"downloaded bytes size %llu of total: %llu", size, total);
};
[imageView1 setImage:nil];
... ...
... ... @@ -34,15 +34,15 @@
NSLog(@"headers recieved");
}];
[request setBytesReceivedBlock:^(ASIHTTPRequest *aRequest, unsigned long long length, unsigned long long total){
[request setBytesReceivedBlock:^(unsigned long long length, unsigned long long total){
NSLog(@"bytes received:%llu of total: %llu", length, total);
}];
[request setDownloadSizeIncrementedBlock:^(ASIHTTPRequest *aRequest, long long length){
[request setDownloadSizeIncrementedBlock:^(long long length){
NSLog(@"download size incremented:%lld", length);
}];
[request setDataReceivedBlock:^(ASIHTTPRequest *aRequest, NSData *data){
[request setDataReceivedBlock:^(NSData *data){
[recievedData appendData:data];
NSLog(@"data - %@", recievedData);
}];
... ...
... ... @@ -20,17 +20,17 @@
[request setPostValue:@"test" forKey:@"value2"];
[request setPostValue:@"test" forKey:@"value3"];
[request setTimeOutSeconds:20];
[request setBytesSentBlock:^(ASIHTTPRequest *request, unsigned long long length, unsigned long long total){
[request setBytesSentBlock:^(unsigned long long length, unsigned long long total){
NSLog(@"sent %llu bytes of %llu total", length, total);
}];
[request setUploadSizeIncrementedBlock:^(ASIHTTPRequest *request, long long length){
[request setUploadSizeIncrementedBlock:^(long long length){
NSLog(@"upload size incremented = %lld",length);
}];
/*[request setUploadProgressDelegate:progressIndicator];
[request setUploadProgressDelegate:progressIndicator];
[request setDelegate:self];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setDidFinishSelector:@selector(uploadFinished:)];*/
[request setDidFinishSelector:@selector(uploadFinished:)];
//Create a 256KB file
NSData *data = [[[NSMutableData alloc] initWithLength:256*1024] autorelease];
... ...