From 6611c7093d8e4fa003c08a890f76727b875468a5 Mon Sep 17 00:00:00 2001 From: brotherbard Date: Sat, 14 Nov 2009 16:57:02 -0700 Subject: [PATCH] Fix for the occasional "Remote host closed connection" exception while 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. --- NSFileHandleExt.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/NSFileHandleExt.m b/NSFileHandleExt.m index 463c687ae..55f970093 100644 --- a/NSFileHandleExt.m +++ b/NSFileHandleExt.m @@ -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