From 0a933cf3d4d6d82bfa69a53639acb55771d83ff6 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 18 May 2015 10:30:36 +0000 Subject: 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 --- ext/io/nonblock/nonblock.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'ext/io/nonblock/nonblock.c') diff --git a/ext/io/nonblock/nonblock.c b/ext/io/nonblock/nonblock.c index 2c5c298126..2509329f6c 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 -- cgit v1.2.3