Skip to content

Commit 68bd786

Browse files
committed
Fixes bug where GCDAsyncSocket may stop reading. Fixes issue robbiehanson#30 and issue robbiehanson#34
1 parent 0bc9afc commit 68bd786

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

GCD/GCDAsyncSocket.m

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4157,10 +4157,8 @@ - (void)doReadData
41574157
return;
41584158
}
41594159

4160-
BOOL done = NO; // Completed read operation
4161-
BOOL waiting = NO; // Ran out of data, waiting for more
4162-
BOOL socketEOF = (flags & kSocketHasReadEOF) ? YES : NO; // Nothing more to via socket (end of file)
4163-
NSError *error = nil; // Error occured
4160+
BOOL done = NO; // Completed read operation
4161+
NSError *error = nil; // Error occured
41644162

41654163
NSUInteger totalBytesReadForCurrentRead = 0;
41664164

@@ -4257,7 +4255,10 @@ - (void)doReadData
42574255
// STEP 2 - READ FROM SOCKET
42584256
//
42594257

4260-
if (!done && !waiting && !socketEOF && !error && hasBytesAvailable)
4258+
BOOL socketEOF = (flags & kSocketHasReadEOF) ? YES : NO; // Nothing more to via socket (end of file)
4259+
BOOL waiting = !done && !error && !socketEOF && !hasBytesAvailable; // Ran out of data, waiting for more
4260+
4261+
if (!done && !error && !socketEOF && !waiting && hasBytesAvailable)
42614262
{
42624263
NSAssert((partialReadBufferLength == 0), @"Invalid logic");
42634264

@@ -4600,7 +4601,7 @@ - (void)doReadData
46004601

46014602
} // if (bytesRead > 0)
46024603

4603-
} // if (!done && !error && hasBytesAvailable)
4604+
} // if (!done && !error && !socketEOF && !waiting && hasBytesAvailable)
46044605

46054606

46064607
if (!done && currentRead->readLength == 0 && currentRead->term == nil)
@@ -4612,16 +4613,7 @@ - (void)doReadData
46124613
done = (totalBytesReadForCurrentRead > 0);
46134614
}
46144615

4615-
// Only one of the following can possibly be true:
4616-
//
4617-
// - waiting
4618-
// - socketEOF
4619-
// - socketError
4620-
// - maxoutError
4621-
//
4622-
// They may all be false.
4623-
// One of the above may be true even if done is true.
4624-
// This might be the case if we completed read type #1 via data from the prebuffer.
4616+
// Check to see if we're done, or if we've made progress
46254617

46264618
if (done)
46274619
{

GCD/Xcode/ConnectTest/Desktop/ConnectTest/ConnectTestAppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
5151
}
5252
#else
5353
{
54-
NSString *host = @"deusty.com";
54+
NSString *host = @"google.com";
5555
uint16_t port = 80;
5656

5757

0 commit comments

Comments
 (0)