Skip to content

Commit

Permalink
Defer cancellation to run on the request thread.
Browse files Browse the repository at this point in the history
Cancellation ends up addressing runloop objects and CF objects (and also accesses the runloop for the current thread), at least some of which will only work on the thread the request is running on.

For example, cancel calls cancelLoad which calls destroyReadStream which needs to access the runloop for the request for this:

[[self readStream] removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]];
  • Loading branch information
jogu authored and pokeb committed Jul 27, 2010
1 parent 20c7cb3 commit b10f5e2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Classes/ASIHTTPRequest.m
Expand Up @@ -506,11 +506,14 @@ - (void)setQueue:(id)newQueue

#pragma mark get information about this request

- (void)cancel
// cancel the request - this must be run on the same thread as the request is running on
- (void)cancelOnRequestThread
{
#if DEBUG_REQUEST_STATUS
NSLog(@"Request cancelled: %@",self);
#endif

[self autorelease];

[[self cancelledLock] lock];

Expand All @@ -529,6 +532,14 @@ - (void)cancel
[[self cancelledLock] unlock];
}

- (void)cancel
{
[self retain];
[self performSelector:@selector(cancelOnRequestThread)
onThread:[[self class] threadForRequest:self]
withObject:nil
waitUntilDone:NO];
}

// Call this method to get the received data as an NSString. Don't use for binary data!
- (NSString *)responseString
Expand Down

0 comments on commit b10f5e2

Please sign in to comment.