ruby-changes:38450
From: nobu <ko1@a...>
Date: Mon, 18 May 2015 19:30:56 +0900 (JST)
Subject: [ruby-changes:38450] nobu:r50531 (trunk): nonblock.c: just yield if the flag is not changed
nobu 2015-05-18 19:30:36 +0900 (Mon, 18 May 2015) New Revision: 50531 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50531 Log: 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. Modified files: trunk/ext/io/nonblock/nonblock.c Index: ext/io/nonblock/nonblock.c =================================================================== --- ext/io/nonblock/nonblock.c (revision 50530) +++ ext/io/nonblock/nonblock.c (revision 50531) @@ -50,21 +50,22 @@ rb_io_nonblock_p(VALUE io) https://github.com/ruby/ruby/blob/trunk/ext/io/nonblock/nonblock.c#L50 #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 *ar https://github.com/ruby/ruby/blob/trunk/ext/io/nonblock/nonblock.c#L122 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/