From 983e8ff915118d00b683109df0834733b485086d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 10 Apr 2011 07:04:41 +0000 Subject: read_write: detect closed fd on EINTR Another thread may have killed the descriptor. --- ext/kgio/read_write.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ext/kgio/read_write.c b/ext/kgio/read_write.c index f43942e..26ef779 100644 --- a/ext/kgio/read_write.c +++ b/ext/kgio/read_write.c @@ -76,8 +76,10 @@ static void prepare_read(struct io_args *a, int argc, VALUE *argv, VALUE io) static int read_check(struct io_args *a, long n, const char *msg, int io_wait) { if (n == -1) { - if (errno == EINTR) + if (errno == EINTR) { + a->fd = my_fileno(a->io); return -1; + } rb_str_set_len(a->buf, 0); if (errno == EAGAIN) { if (io_wait) { @@ -307,8 +309,10 @@ static int write_check(struct io_args *a, long n, const char *msg, int io_wait) done: a->buf = Qnil; } else if (n == -1) { - if (errno == EINTR) + if (errno == EINTR) { + a->fd = my_fileno(a->io); return -1; + } if (errno == EAGAIN) { long written = RSTRING_LEN(a->buf) - a->len; -- cgit v1.2.3-24-ge0c7