about summary refs log tree commit homepage
path: root/ext/kgio/read_write.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/kgio/read_write.c')
-rw-r--r--ext/kgio/read_write.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/ext/kgio/read_write.c b/ext/kgio/read_write.c
index 8960035..571eed8 100644
--- a/ext/kgio/read_write.c
+++ b/ext/kgio/read_write.c
@@ -14,6 +14,7 @@ static VALUE eErrno_EPIPE, eErrno_ECONNRESET;
 NORETURN(static void raise_empty_bt(VALUE, const char *));
 NORETURN(static void my_eof_error(void));
 NORETURN(static void wr_sys_fail(const char *));
+NORETURN(static void rd_sys_fail(const char *));
 
 static void raise_empty_bt(VALUE err, const char *msg)
 {
@@ -42,6 +43,15 @@ static void wr_sys_fail(const char *msg)
         rb_sys_fail(msg);
 }
 
+static void rd_sys_fail(const char *msg)
+{
+        if (errno == ECONNRESET) {
+                errno = 0;
+                raise_empty_bt(eErrno_ECONNRESET, msg);
+        }
+        rb_sys_fail(msg);
+}
+
 static void prepare_read(struct io_args *a, int argc, VALUE *argv, VALUE io)
 {
         VALUE length;
@@ -78,7 +88,7 @@ static int read_check(struct io_args *a, long n, const char *msg, int io_wait)
                                 return 0;
                         }
                 }
-                rb_sys_fail(msg);
+                rd_sys_fail(msg);
         }
         rb_str_set_len(a->buf, n);
         if (n == 0)