Skip to content

Commit

Permalink
Critical bug fix for GCD version: Under the right circumstances, the …
Browse files Browse the repository at this point in the history
…socket would stop reading data.
  • Loading branch information
robbiehanson committed Jan 18, 2011
1 parent 46ebc7f commit fa28d48
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions GCD/GCDAsyncSocket.m
Expand Up @@ -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;
Expand Down Expand Up @@ -3632,6 +3634,11 @@ - (void)doReadData
socketFDBytesAvailable = 0;
else
socketFDBytesAvailable -= bytesRead;

if (socketFDBytesAvailable == 0)
{
waiting = YES;
}
}
}

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit fa28d48

Please sign in to comment.