Skip to content

Commit

Permalink
Fix for the occasional "Remote host closed connection" exception whil…
Browse files Browse the repository at this point in the history
…e looking at files in the file browser.

Seems to happen more when running in XCode than when running by itself. This randomly causes the contents view to be empty or the files to not be shown when clicking a discloser triangle.

EINTR errors are recoverable, just need to read() again.
  • Loading branch information
brotherbard committed Nov 16, 2009
1 parent 0914c3a commit 6611c70
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions NSFileHandleExt.m
Expand Up @@ -36,8 +36,14 @@ -(NSString*)readLine {
while (n > 0) {
n = read(fd, buffer + bytesReceived++, 1);

if (n < 0)
[[NSException exceptionWithName:@"Socket error" reason:@"Remote host closed connection" userInfo:nil] raise];
if (n < 0) {
if (errno == EINTR) {
n = 1;
bytesReceived--;
} else {
[[NSException exceptionWithName:@"Socket error" reason:@"Remote host closed connection" userInfo:nil] raise];
}
}

if (bytesReceived >= bufferSize) {
// Make buffer bigger
Expand Down

0 comments on commit 6611c70

Please sign in to comment.