From a4508ac997f8e0a1ac41bd3f9d3e01403eed03b5 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 14 Sep 2012 09:21:23 -0700 Subject: [PATCH] [Issue #507] Fixing potential issues with output stream runloop scheduling --- AFNetworking/AFHTTPRequestOperation.m | 5 +++++ AFNetworking/AFURLConnectionOperation.m | 15 +++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 1456eca..db62120 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -314,6 +314,11 @@ didReceiveResponse:(NSURLResponse *)response } else { if ([[self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey] length] > 0) { self.outputStream = [NSOutputStream outputStreamToMemory]; + + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + for (NSString *runLoopMode in self.runLoopModes) { + [self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode]; + } } } } diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index e1c0a4b..073c211 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -179,7 +179,11 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat self.request = urlRequest; self.outputStream = [NSOutputStream outputStreamToMemory]; - + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + for (NSString *runLoopMode in self.runLoopModes) { + [self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode]; + } + self.state = AFOperationReadyState; return self; @@ -253,6 +257,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } - (void)setOutputStream:(NSOutputStream *)outputStream { + if (_outputStream == outputStream) { + return; + } + [self willChangeValueForKey:@"outputStream"]; [outputStream retain]; @@ -262,11 +270,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } _outputStream = outputStream; [self didChangeValueForKey:@"outputStream"]; - - NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; - for (NSString *runLoopMode in self.runLoopModes) { - [self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode]; - } } #if __IPHONE_OS_VERSION_MIN_REQUIRED