Adding @try/@catch with autorelease pool for exceptions
Wrapping -start in lock
This commit is contained in:
parent
680fcd5071
commit
a466c27886
1 changed files with 26 additions and 15 deletions
|
|
@ -119,9 +119,18 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
|
|
||||||
+ (void)networkRequestThreadEntryPoint:(id)__unused object {
|
+ (void)networkRequestThreadEntryPoint:(id)__unused object {
|
||||||
do {
|
do {
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *exceptionPool = [[NSAutoreleasePool alloc] init];
|
||||||
[[NSRunLoop currentRunLoop] run];
|
NSException *caughtException = nil;
|
||||||
[pool drain];
|
@try {
|
||||||
|
NSAutoreleasePool *runLoopPool = [[NSAutoreleasePool alloc] init];
|
||||||
|
[[NSRunLoop currentRunLoop] run];
|
||||||
|
[runLoopPool drain];
|
||||||
|
}
|
||||||
|
@catch(NSException *e) { caughtException = e; }
|
||||||
|
if(caughtException) {
|
||||||
|
NSLog(NSLocalizedString(@"Unhandled exception on %@ networking thread: %@, userInfo: %@", nil), NSStringFromClass([self class]), caughtException, [caughtException userInfo]);
|
||||||
|
}
|
||||||
|
[exceptionPool drain];
|
||||||
} while (YES);
|
} while (YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -280,13 +289,13 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)start {
|
- (void)start {
|
||||||
if (![self isReady]) {
|
[self.lock lock];
|
||||||
return;
|
if ([self isReady]) {
|
||||||
|
self.state = AFHTTPOperationExecutingState;
|
||||||
|
|
||||||
|
[self performSelector:@selector(operationDidStart) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];
|
||||||
}
|
}
|
||||||
|
[self.lock unlock];
|
||||||
self.state = AFHTTPOperationExecutingState;
|
|
||||||
|
|
||||||
[self performSelector:@selector(operationDidStart) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:YES modes:[self.runLoopModes allObjects]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)operationDidStart {
|
- (void)operationDidStart {
|
||||||
|
|
@ -318,11 +327,13 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
|
|
||||||
self.cancelled = YES;
|
self.cancelled = YES;
|
||||||
|
|
||||||
[self.connection cancel];
|
if (self.connection) {
|
||||||
|
[self.connection cancel];
|
||||||
|
|
||||||
// We must send this delegate protcol message ourselves since the above [self.connection cancel] causes the connection to never send another message to its delegate.
|
// We must send this delegate protcol message ourselves since the above [self.connection cancel] causes the connection to never send another message to its delegate.
|
||||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
||||||
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]];
|
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[self.lock unlock];
|
[self.lock unlock];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue