[Issue #1288] Adding loop around write to ensure entire length of data is written

This commit is contained in:
Mattt Thompson 2013-09-24 15:40:13 -07:00
parent 8a5f3ef359
commit d1b64cf0bc

View file

@ -721,12 +721,20 @@ didReceiveResponse:(NSURLResponse *)response
{
NSUInteger length = [data length];
while (YES) {
NSUInteger totalNumberOfBytesWritten = 0;
if ([self.outputStream hasSpaceAvailable]) {
const uint8_t *dataBuffer = (uint8_t *)[data bytes];
if ([self.outputStream write:&dataBuffer[0] maxLength:length] == -1) {
[self.connection cancel];
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:self.outputStream.streamError];
return;
NSInteger numberOfBytesWritten = 0;
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;