Ben Copsey

Fix a recently introduced problem that may have prevented queue delegate methods from being called

@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 23
24 24
25 // Automatically set on build 25 // Automatically set on build
26 -NSString *ASIHTTPRequestVersion = @"v1.7-24 2010-07-18"; 26 +NSString *ASIHTTPRequestVersion = @"v1.7-25 2010-07-22";
27 27
28 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; 28 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
29 29
@@ -63,6 +63,12 @@ static NSError *ASITooMuchRedirectionError; @@ -63,6 +63,12 @@ static NSError *ASITooMuchRedirectionError;
63 static NSMutableArray *bandwidthUsageTracker = nil; 63 static NSMutableArray *bandwidthUsageTracker = nil;
64 static unsigned long averageBandwidthUsedPerSecond = 0; 64 static unsigned long averageBandwidthUsedPerSecond = 0;
65 65
  66 +static SEL queueRequestStartedSelector = nil;
  67 +static SEL queueRequestReceivedResponseHeadersSelector = nil;
  68 +static SEL queueRequestFinishedSelector = nil;
  69 +static SEL queueRequestFailedSelector = nil;
  70 +
  71 +
66 // These are used for queuing persistent connections on the same connection 72 // These are used for queuing persistent connections on the same connection
67 73
68 // Incremented every time we specify we want a new connection 74 // Incremented every time we specify we want a new connection
@@ -220,6 +226,10 @@ static NSOperationQueue *sharedQueue = nil; @@ -220,6 +226,10 @@ static NSOperationQueue *sharedQueue = nil;
220 + (void)initialize 226 + (void)initialize
221 { 227 {
222 if (self == [ASIHTTPRequest class]) { 228 if (self == [ASIHTTPRequest class]) {
  229 + queueRequestStartedSelector = @selector(requestStarted:);
  230 + queueRequestReceivedResponseHeadersSelector = @selector(requestReceivedResponseHeaders:);
  231 + queueRequestFinishedSelector = @selector(requestFinished:);
  232 + queueRequestFailedSelector = @selector(requestFailed:);
223 persistentConnectionsPool = [[NSMutableArray alloc] init]; 233 persistentConnectionsPool = [[NSMutableArray alloc] init];
224 connectionsLock = [[NSRecursiveLock alloc] init]; 234 connectionsLock = [[NSRecursiveLock alloc] init];
225 progressLock = [[NSRecursiveLock alloc] init]; 235 progressLock = [[NSRecursiveLock alloc] init];
@@ -1569,17 +1579,14 @@ static NSOperationQueue *sharedQueue = nil; @@ -1569,17 +1579,14 @@ static NSOperationQueue *sharedQueue = nil;
1569 1579
1570 #pragma mark handling request complete / failure 1580 #pragma mark handling request complete / failure
1571 1581
1572 - 1582 +- (void)callSelectorCallback:(SEL *)selectorPtr withTarget:(id *)targetPtr request:(ASIHTTPRequest *)request
1573 -- (void)callSelectorCallback:(SEL *)selectorPtr withTarget:(id *)targetPtr  
1574 { 1583 {
1575 id target = *targetPtr; 1584 id target = *targetPtr;
1576 SEL selector = *selectorPtr; 1585 SEL selector = *selectorPtr;
1577 - 1586 + NSLog(@"%@",NSStringFromSelector(selector));
1578 - if (selector && target && [target respondsToSelector:selector]) 1587 + if (selector && target && [target respondsToSelector:selector]) {
1579 - {  
1580 [target performSelector:selector withObject:self]; 1588 [target performSelector:selector withObject:self];
1581 } 1589 }
1582 - [self autorelease];  
1583 } 1590 }
1584 1591
1585 // Call a selector for a delegate on the main thread 1592 // Call a selector for a delegate on the main thread
@@ -1591,15 +1598,17 @@ static NSOperationQueue *sharedQueue = nil; @@ -1591,15 +1598,17 @@ static NSOperationQueue *sharedQueue = nil;
1591 if (!*selector || !*target) 1598 if (!*selector || !*target)
1592 return; 1599 return;
1593 1600
1594 - SEL callback = @selector(callSelectorCallback:withTarget:); 1601 + SEL callback = @selector(callSelectorCallback:withTarget:request:);
1595 NSMethodSignature *signature = [ASIHTTPRequest instanceMethodSignatureForSelector:callback]; 1602 NSMethodSignature *signature = [ASIHTTPRequest instanceMethodSignatureForSelector:callback];
1596 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; 1603 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
1597 [invocation setSelector:callback]; 1604 [invocation setSelector:callback];
1598 [invocation setTarget:self]; 1605 [invocation setTarget:self];
1599 [invocation setArgument:&selector atIndex:2]; 1606 [invocation setArgument:&selector atIndex:2];
1600 [invocation setArgument:&target atIndex:3]; 1607 [invocation setArgument:&target atIndex:3];
  1608 + [invocation setArgument:&self atIndex:4];
1601 1609
1602 - [self retain]; // ensure we stay around for the duration of the callback 1610 + // Force the invocation to retain this request until after we have performed the callback
  1611 + [invocation retainArguments];
1603 [invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:[NSThread isMainThread]]; 1612 [invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:[NSThread isMainThread]];
1604 } 1613 }
1605 1614
@@ -1614,8 +1623,7 @@ static NSOperationQueue *sharedQueue = nil; @@ -1614,8 +1623,7 @@ static NSOperationQueue *sharedQueue = nil;
1614 [self callSelectorOnMainThread:&didReceiveResponseHeadersSelector forDelegate:&delegate]; 1623 [self callSelectorOnMainThread:&didReceiveResponseHeadersSelector forDelegate:&delegate];
1615 1624
1616 // Let the queue know we have started 1625 // Let the queue know we have started
1617 - SEL sel = @selector(requestReceivedResponseHeaders:); 1626 + [self callSelectorOnMainThread:&queueRequestReceivedResponseHeadersSelector forDelegate:&queue];
1618 - [self callSelectorOnMainThread:&sel forDelegate:&queue];  
1619 } 1627 }
1620 1628
1621 - (void)requestStarted 1629 - (void)requestStarted
@@ -1627,8 +1635,7 @@ static NSOperationQueue *sharedQueue = nil; @@ -1627,8 +1635,7 @@ static NSOperationQueue *sharedQueue = nil;
1627 [self callSelectorOnMainThread:&didStartSelector forDelegate:&delegate]; 1635 [self callSelectorOnMainThread:&didStartSelector forDelegate:&delegate];
1628 1636
1629 // Let the queue know we have started 1637 // Let the queue know we have started
1630 - SEL sel = @selector(requestStarted:); 1638 + [self callSelectorOnMainThread:&queueRequestStartedSelector forDelegate:&queue];
1631 - [self callSelectorOnMainThread:&sel forDelegate:&queue];  
1632 } 1639 }
1633 1640
1634 // Subclasses might override this method to process the result in the same thread 1641 // Subclasses might override this method to process the result in the same thread
@@ -1645,8 +1652,7 @@ static NSOperationQueue *sharedQueue = nil; @@ -1645,8 +1652,7 @@ static NSOperationQueue *sharedQueue = nil;
1645 [self callSelectorOnMainThread:&didFinishSelector forDelegate:&delegate]; 1652 [self callSelectorOnMainThread:&didFinishSelector forDelegate:&delegate];
1646 1653
1647 // Let the queue know we are done 1654 // Let the queue know we are done
1648 - SEL sel = @selector(requestFinished:); 1655 + [self callSelectorOnMainThread:&queueRequestFinishedSelector forDelegate:&queue];
1649 - [self callSelectorOnMainThread:&sel forDelegate:&queue];  
1650 } 1656 }
1651 1657
1652 1658
@@ -1656,8 +1662,7 @@ static NSOperationQueue *sharedQueue = nil; @@ -1656,8 +1662,7 @@ static NSOperationQueue *sharedQueue = nil;
1656 [self callSelectorOnMainThread:&didFailSelector forDelegate:&delegate]; 1662 [self callSelectorOnMainThread:&didFailSelector forDelegate:&delegate];
1657 1663
1658 // Let the queue know something went wrong 1664 // Let the queue know something went wrong
1659 - SEL sel = @selector(requestFailed:); 1665 + [self callSelectorOnMainThread:&queueRequestFailedSelector forDelegate:&queue];
1660 - [self callSelectorOnMainThread:&sel forDelegate:&queue];  
1661 } 1666 }
1662 1667
1663 // Subclasses might override this method to perform error handling in the same thread 1668 // Subclasses might override this method to perform error handling in the same thread
This diff was suppressed by a .gitattributes entry.