summaryrefslogtreecommitdiff
path: root/ext/io
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-18 10:30:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-18 10:30:36 +0000
commit0a933cf3d4d6d82bfa69a53639acb55771d83ff6 (patch)
treece9be02886d53941f0d25d248e9c940bd2ab2734 /ext/io
parent903c0f55e97e73bbd78ad81251be6d923c8ccf15 (diff)
nonblock.c: just yield if the flag is not changed
* ext/io/nonblock/nonblock.c (io_nonblock_set): return whether nonblock flag was changed. * ext/io/nonblock/nonblock.c (rb_io_nonblock_block): nothing to restore but just yield unless nonblock flag is changed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50531 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/io')
-rw-r--r--ext/io/nonblock/nonblock.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/ext/io/nonblock/nonblock.c b/ext/io/nonblock/nonblock.c
index 2c5c298..2509329 100644
--- a/ext/io/nonblock/nonblock.c
+++ b/ext/io/nonblock/nonblock.c
@@ -50,21 +50,22 @@ rb_io_nonblock_p(VALUE io)
#endif
#ifdef F_SETFL
-static void
+static int
io_nonblock_set(int fd, int f, int nb)
{
if (nb) {
if ((f & O_NONBLOCK) != 0)
- return;
+ return 0;
f |= O_NONBLOCK;
}
else {
if ((f & O_NONBLOCK) == 0)
- return;
+ return 0;
f &= ~O_NONBLOCK;
}
if (fcntl(fd, F_SETFL, f) == -1)
rb_sys_fail(0);
+ return 1;
}
/*
@@ -121,7 +122,8 @@ rb_io_nonblock_block(int argc, VALUE *argv, VALUE io)
f = io_nonblock_mode(fptr->fd);
restore[0] = fptr->fd;
restore[1] = f;
- io_nonblock_set(fptr->fd, f, nb);
+ if (!io_nonblock_set(fptr->fd, f, nb))
+ return rb_yield(io);
return rb_ensure(rb_yield, io, io_nonblock_restore, (VALUE)restore);
}
#else