From 2e549a18f82f98465bbf3cd9367f1cdb61f7565f Mon Sep 17 00:00:00 2001 From: Nathan Kinsinger Date: Fri, 19 Feb 2010 22:30:02 -0700 Subject: [PATCH] Fix for "Remote host closed connection" exception EINTR errors are recoverable, just need to read() again. Randomly while looking at files in the file browser the contents view will be empty or files will not be shown when clicking a discloser triangle. Seems to happen more when running in XCode than when running by itself. --- NSFileHandleExt.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/NSFileHandleExt.m b/NSFileHandleExt.m index 2772855..6d30cc9 100644 --- a/NSFileHandleExt.m +++ b/NSFileHandleExt.m @@ -33,8 +33,14 @@ 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