Browse Source

[Issue #507] Fixing potential issues with output stream runloop scheduling

Mattt Thompson 13 years ago
parent
commit
a4508ac997
2 changed files with 14 additions and 6 deletions
  1. 5 0
      AFNetworking/AFHTTPRequestOperation.m
  2. 9 6
      AFNetworking/AFURLConnectionOperation.m

+ 5 - 0
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];
+                }
             }
         }
     }

+ 9 - 6
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