diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index e483f3e..5885369 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -739,16 +739,20 @@ didReceiveResponse:(NSURLResponse *)response while (totalNumberOfBytesWritten < length) { numberOfBytesWritten = [self.outputStream write:&dataBuffer[0] maxLength:length]; if (numberOfBytesWritten == -1) { - [self.connection cancel]; - [self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:self.outputStream.streamError]; - return; - } else { - totalNumberOfBytesWritten += numberOfBytesWritten; + break; } + + totalNumberOfBytesWritten += numberOfBytesWritten; } break; } + + if (self.outputStream.streamError) { + [self.connection cancel]; + [self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:self.outputStream.streamError]; + return; + } } dispatch_async(dispatch_get_main_queue(), ^{