diff --git a/GCD/GCDAsyncSocket.m b/GCD/GCDAsyncSocket.m index 7fe35325..f2045341 100644 --- a/GCD/GCDAsyncSocket.m +++ b/GCD/GCDAsyncSocket.m @@ -3454,6 +3454,8 @@ - (void)doReadData [partialReadBuffer replaceBytesInRange:NSMakeRange(0, bytesToCopy) withBytes:NULL length:0]; partialReadBufferLength -= bytesToCopy; + LogVerbose(@"copied(%lu) partialReadBufferLength(%lu)", bytesToCopy, partialReadBufferLength); + // Update totals currentRead->bytesDone += bytesToCopy; @@ -3632,6 +3634,11 @@ - (void)doReadData socketFDBytesAvailable = 0; else socketFDBytesAvailable -= bytesRead; + + if (socketFDBytesAvailable == 0) + { + waiting = YES; + } } } @@ -3807,18 +3814,18 @@ - (void)doReadData // Check for errors - if (waiting) + if (error) { - // Monitor the socket for readability (if we're not already doing so) - [self resumeReadSource]; + [self closeWithError:error]; } else if (socketEOF) { [self doReadEOF]; } - else if (error) + else if (waiting) { - [self closeWithError:error]; + // Monitor the socket for readability (if we're not already doing so) + [self resumeReadSource]; } // Do not add any code here without first adding return statements in the error cases above.