From 94edafdbfcc39586a510cae8f6b411c6196d9cfc Mon Sep 17 00:00:00 2001
From: Nathan Kinsinger <[email protected]>
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 files 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
-- 
1.7.0+GitX



--Nathan

http://brotherbard.com/





Reply via email to