mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
903c0f55e9
commit
0a933cf3d4
1 changed files with 6 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue