about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-25 18:02:16 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-25 18:02:16 -0800
commit6ab4331f8137e949ab57f014f96ff3918a315044 (patch)
tree356f21e15b75235cb734c56ea592fdd8fc678eb9
parent3a0323b642ee054319a5e64ffe28e089bbd013e4 (diff)
downloadkgio-6ab4331f8137e949ab57f014f96ff3918a315044.tar.gz
Retrieving the file descriptor may have side-effects on
certain Ruby implementations (e.g. Rubinius), so ensure
our errno is preserved before calling rb_io_wait_*able().
-rw-r--r--ext/kgio/wait.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/ext/kgio/wait.c b/ext/kgio/wait.c
index abc10a3..c6ed610 100644
--- a/ext/kgio/wait.c
+++ b/ext/kgio/wait.c
@@ -21,8 +21,10 @@ static ID id_wait_rd, id_wait_wr;
  */
 static VALUE kgio_wait_readable(VALUE self)
 {
+        int fd = my_fileno(self);
+
         errno = EAGAIN;
-        if (!rb_io_wait_readable(my_fileno(self)))
+        if (!rb_io_wait_readable(fd))
                 rb_sys_fail("kgio_wait_readable");
 
         return self;
@@ -39,8 +41,10 @@ static VALUE kgio_wait_readable(VALUE self)
  */
 static VALUE kgio_wait_writable(VALUE self)
 {
+        int fd = my_fileno(self);
+
         errno = EAGAIN;
-        if (!rb_io_wait_writable(my_fileno(self)))
+        if (!rb_io_wait_writable(fd))
                 rb_sys_fail("kgio_wait_writable");
 
         return self;