Ben Copsey

Move remaining blocks calls onto the main thread, tweaks

@@ -529,7 +529,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -529,7 +529,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
529 - (void)setHeadersReceivedBlock:(ASIHTTPRequestBlock)aReceivedBlock; 529 - (void)setHeadersReceivedBlock:(ASIHTTPRequestBlock)aReceivedBlock;
530 - (void)setCompletionBlock:(ASIHTTPRequestBlock)aCompletionBlock; 530 - (void)setCompletionBlock:(ASIHTTPRequestBlock)aCompletionBlock;
531 - (void)setFailedBlock:(ASIHTTPRequestBlock)aFailedBlock; 531 - (void)setFailedBlock:(ASIHTTPRequestBlock)aFailedBlock;
532 -- (void)setBytesReceivedBlock:(ASIHTTPRequestProgressBlock) aBytesReceivedBlock; 532 +- (void)setBytesReceivedBlock:(ASIHTTPRequestProgressBlock)aBytesReceivedBlock;
533 - (void)setBytesSentBlock:(ASIHTTPRequestProgressBlock)aBytesSentBlock; 533 - (void)setBytesSentBlock:(ASIHTTPRequestProgressBlock)aBytesSentBlock;
534 - (void)setDownloadSizeIncrementedBlock:(ASIHTTPRequestSizeBlock) aDownloadSizeIncrementedBlock; 534 - (void)setDownloadSizeIncrementedBlock:(ASIHTTPRequestSizeBlock) aDownloadSizeIncrementedBlock;
535 - (void)setUploadSizeIncrementedBlock:(ASIHTTPRequestSizeBlock) anUploadSizeIncrementedBlock; 535 - (void)setUploadSizeIncrementedBlock:(ASIHTTPRequestSizeBlock) anUploadSizeIncrementedBlock;
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 #import "ASIDataCompressor.h" 24 #import "ASIDataCompressor.h"
25 25
26 // Automatically set on build 26 // Automatically set on build
27 -NSString *ASIHTTPRequestVersion = @"v1.7-119 2010-10-18"; 27 +NSString *ASIHTTPRequestVersion = @"v1.7-120 2010-10-23";
28 28
29 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; 29 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
30 30
@@ -1433,8 +1433,6 @@ static NSOperationQueue *sharedQueue = nil; @@ -1433,8 +1433,6 @@ static NSOperationQueue *sharedQueue = nil;
1433 [self removeTemporaryDownloadFile]; 1433 [self removeTemporaryDownloadFile];
1434 } 1434 }
1435 [self removeTemporaryUncompressedDownloadFile]; 1435 [self removeTemporaryUncompressedDownloadFile];
1436 -  
1437 -  
1438 } 1436 }
1439 1437
1440 // Clean up any temporary file used to store request body for streaming 1438 // Clean up any temporary file used to store request body for streaming
@@ -1576,24 +1574,22 @@ static NSOperationQueue *sharedQueue = nil; @@ -1576,24 +1574,22 @@ static NSOperationQueue *sharedQueue = nil;
1576 1574
1577 #if NS_BLOCKS_AVAILABLE 1575 #if NS_BLOCKS_AVAILABLE
1578 if (bytesReceivedBlock) { 1576 if (bytesReceivedBlock) {
1579 - __block ASIHTTPRequest *blockCopy = self; 1577 + [ASIHTTPRequest performSelector:@selector(callBytesReceivedBlockWithLength:) onTarget:&self withObject:nil amount:&value];
1580 - bytesReceivedBlock(blockCopy, value, blockCopy->contentLength + blockCopy->partialDownloadSize);  
1581 } 1578 }
1582 #endif 1579 #endif
1583 [self setLastBytesRead:bytesReadSoFar]; 1580 [self setLastBytesRead:bytesReadSoFar];
1584 } 1581 }
1585 1582
1586 #if NS_BLOCKS_AVAILABLE 1583 #if NS_BLOCKS_AVAILABLE
1587 -- (void)callBytesReceivedBlockWithBytes:(unsigned long long)bytes ofTotal:(unsigned long long)total 1584 +- (void)callBytesReceivedBlockWithLength:(unsigned long long)value
1588 { 1585 {
1589 - if (bytesReceivedBlock) { 1586 + if (bytesReceivedBlock) {
1590 __block ASIHTTPRequest *blockCopy = self; 1587 __block ASIHTTPRequest *blockCopy = self;
1591 - bytesReceivedBlock(blockCopy, bytes, blockCopy->contentLength + blockCopy->partialDownloadSize); 1588 + bytesReceivedBlock(blockCopy, value, blockCopy->contentLength + blockCopy->partialDownloadSize);
1592 - } 1589 + }
1593 } 1590 }
1594 #endif 1591 #endif
1595 1592
1596 -  
1597 - (void)updateUploadProgress 1593 - (void)updateUploadProgress
1598 { 1594 {
1599 if ([self isCancelled] || [self totalBytesSent] == 0) { 1595 if ([self isCancelled] || [self totalBytesSent] == 0) {
@@ -1631,11 +1627,20 @@ static NSOperationQueue *sharedQueue = nil; @@ -1631,11 +1627,20 @@ static NSOperationQueue *sharedQueue = nil;
1631 1627
1632 #if NS_BLOCKS_AVAILABLE 1628 #if NS_BLOCKS_AVAILABLE
1633 if(bytesSentBlock){ 1629 if(bytesSentBlock){
  1630 + [ASIHTTPRequest performSelector:@selector(callBytesSentBlockWithLength:) onTarget:&self withObject:nil amount:&value];
  1631 + }
  1632 + #endif
  1633 +}
  1634 +
  1635 +#if NS_BLOCKS_AVAILABLE
  1636 +- (void)callBytesSentBlockWithLength:(unsigned long long)value
  1637 +{
  1638 + if (bytesSentBlock) {
1634 __block ASIHTTPRequest *blockCopy = self; 1639 __block ASIHTTPRequest *blockCopy = self;
1635 bytesSentBlock(blockCopy, value, blockCopy->postLength); 1640 bytesSentBlock(blockCopy, value, blockCopy->postLength);
1636 } 1641 }
1637 - #endif  
1638 } 1642 }
  1643 +#endif
1639 1644
1640 1645
1641 - (void)incrementDownloadSizeBy:(long long)length 1646 - (void)incrementDownloadSizeBy:(long long)length
@@ -1645,12 +1650,22 @@ static NSOperationQueue *sharedQueue = nil; @@ -1645,12 +1650,22 @@ static NSOperationQueue *sharedQueue = nil;
1645 1650
1646 #if NS_BLOCKS_AVAILABLE 1651 #if NS_BLOCKS_AVAILABLE
1647 if(downloadSizeIncrementedBlock){ 1652 if(downloadSizeIncrementedBlock){
1648 - __block ASIHTTPRequest *blockCopy = self; 1653 + [ASIHTTPRequest performSelector:@selector(callDownloadSizeIncrementedBlockWithLength:) onTarget:&self withObject:nil amount:&length];
1649 - downloadSizeIncrementedBlock(blockCopy, length);  
1650 } 1654 }
1651 #endif 1655 #endif
1652 } 1656 }
1653 1657
  1658 +#if NS_BLOCKS_AVAILABLE
  1659 +- (void)callDownloadSizeIncrementedBlockWithLength:(unsigned long long)length
  1660 +{
  1661 + if (downloadSizeIncrementedBlock) {
  1662 + __block ASIHTTPRequest *blockCopy = self;
  1663 + downloadSizeIncrementedBlock(blockCopy, length);
  1664 + }
  1665 +}
  1666 +#endif
  1667 +
  1668 +
1654 1669
1655 - (void)incrementUploadSizeBy:(long long)length 1670 - (void)incrementUploadSizeBy:(long long)length
1656 { 1671 {
@@ -1659,11 +1674,20 @@ static NSOperationQueue *sharedQueue = nil; @@ -1659,11 +1674,20 @@ static NSOperationQueue *sharedQueue = nil;
1659 1674
1660 #if NS_BLOCKS_AVAILABLE 1675 #if NS_BLOCKS_AVAILABLE
1661 if(uploadSizeIncrementedBlock){ 1676 if(uploadSizeIncrementedBlock){
  1677 + [ASIHTTPRequest performSelector:@selector(callUploadSizeIncrementedBlockWithLength:) onTarget:&self withObject:nil amount:&length];
  1678 + }
  1679 + #endif
  1680 +}
  1681 +
  1682 +#if NS_BLOCKS_AVAILABLE
  1683 +- (void)callUploadSizeIncrementedBlockWithLength:(unsigned long long)length
  1684 +{
  1685 + if(uploadSizeIncrementedBlock){
1662 __block ASIHTTPRequest *blockCopy = self; 1686 __block ASIHTTPRequest *blockCopy = self;
1663 uploadSizeIncrementedBlock(blockCopy, length); 1687 uploadSizeIncrementedBlock(blockCopy, length);
1664 } 1688 }
1665 - #endif  
1666 } 1689 }
  1690 +#endif
1667 1691
1668 1692
1669 -(void)removeUploadProgressSoFar 1693 -(void)removeUploadProgressSoFar
@@ -1675,12 +1699,13 @@ static NSOperationQueue *sharedQueue = nil; @@ -1675,12 +1699,13 @@ static NSOperationQueue *sharedQueue = nil;
1675 1699
1676 #if NS_BLOCKS_AVAILABLE 1700 #if NS_BLOCKS_AVAILABLE
1677 if(bytesSentBlock){ 1701 if(bytesSentBlock){
1678 - __block ASIHTTPRequest *blockCopy = self; 1702 + [ASIHTTPRequest performSelector:@selector(callBytesSentBlockWithLength:) onTarget:&self withObject:nil amount:&progressToRemove];
1679 - bytesSentBlock(blockCopy, progressToRemove, blockCopy->postLength); 1703 +
1680 } 1704 }
1681 #endif 1705 #endif
1682 } 1706 }
1683 1707
  1708 +
1684 + (void)performSelector:(SEL)selector onTarget:(id *)target withObject:(id)object amount:(void *)amount 1709 + (void)performSelector:(SEL)selector onTarget:(id *)target withObject:(id)object amount:(void *)amount
1685 { 1710 {
1686 if ([*target respondsToSelector:selector]) { 1711 if ([*target respondsToSelector:selector]) {
@@ -1826,13 +1851,6 @@ static NSOperationQueue *sharedQueue = nil; @@ -1826,13 +1851,6 @@ static NSOperationQueue *sharedQueue = nil;
1826 if (queue && [queue respondsToSelector:@selector(request:willRedirectToURL:)]) { 1851 if (queue && [queue respondsToSelector:@selector(request:willRedirectToURL:)]) {
1827 [queue performSelector:@selector(request:willRedirectToURL:) withObject:self withObject:newURL]; 1852 [queue performSelector:@selector(request:willRedirectToURL:) withObject:self withObject:newURL];
1828 } 1853 }
1829 -  
1830 - #if NS_BLOCKS_AVAILABLE  
1831 - if(startedBlock){  
1832 - __block ASIHTTPRequest *blockCopy = self;  
1833 - startedBlock(blockCopy);  
1834 - }  
1835 - #endif  
1836 } 1854 }
1837 1855
1838 /* ALWAYS CALLED ON MAIN THREAD! */ 1856 /* ALWAYS CALLED ON MAIN THREAD! */
@@ -1938,12 +1956,6 @@ static NSOperationQueue *sharedQueue = nil; @@ -1938,12 +1956,6 @@ static NSOperationQueue *sharedQueue = nil;
1938 } 1956 }
1939 1957
1940 [failedRequest performSelectorOnMainThread:@selector(reportFailure) withObject:nil waitUntilDone:[NSThread isMainThread]]; 1958 [failedRequest performSelectorOnMainThread:@selector(reportFailure) withObject:nil waitUntilDone:[NSThread isMainThread]];
1941 -  
1942 - #if NS_BLOCKS_AVAILABLE  
1943 - if (failureBlock) {  
1944 - failureBlock(self);  
1945 - }  
1946 - #endif  
1947 1959
1948 if (!inProgress) 1960 if (!inProgress)
1949 { 1961 {
This diff was suppressed by a .gitattributes entry.