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

This commit is contained in:
Mattt Thompson 2012-09-14 09:21:23 -07:00
parent 40c73c6588
commit a4508ac997
2 changed files with 14 additions and 6 deletions

View file

@ -314,6 +314,11 @@ didReceiveResponse:(NSURLResponse *)response
} else { } else {
if ([[self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey] length] > 0) { if ([[self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey] length] > 0) {
self.outputStream = [NSOutputStream outputStreamToMemory]; self.outputStream = [NSOutputStream outputStreamToMemory];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
for (NSString *runLoopMode in self.runLoopModes) {
[self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode];
}
} }
} }
} }

View file

@ -179,7 +179,11 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
self.request = urlRequest; self.request = urlRequest;
self.outputStream = [NSOutputStream outputStreamToMemory]; self.outputStream = [NSOutputStream outputStreamToMemory];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
for (NSString *runLoopMode in self.runLoopModes) {
[self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode];
}
self.state = AFOperationReadyState; self.state = AFOperationReadyState;
return self; return self;
@ -253,6 +257,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
} }
- (void)setOutputStream:(NSOutputStream *)outputStream { - (void)setOutputStream:(NSOutputStream *)outputStream {
if (_outputStream == outputStream) {
return;
}
[self willChangeValueForKey:@"outputStream"]; [self willChangeValueForKey:@"outputStream"];
[outputStream retain]; [outputStream retain];
@ -262,11 +270,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
} }
_outputStream = outputStream; _outputStream = outputStream;
[self didChangeValueForKey:@"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 #if __IPHONE_OS_VERSION_MIN_REQUIRED