mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/io-nonblock] Rename io_nonblock_mode
and extract set_fcntl_flags
https://github.com/ruby/io-nonblock/commit/22f08574df
This commit is contained in:
parent
589f1c1d55
commit
0dfd5d19f3
1 changed files with 14 additions and 9 deletions
|
@ -19,14 +19,14 @@
|
|||
|
||||
#ifdef F_GETFL
|
||||
static int
|
||||
io_nonblock_mode(int fd)
|
||||
get_fcntl_flags(int fd)
|
||||
{
|
||||
int f = fcntl(fd, F_GETFL);
|
||||
if (f == -1) rb_sys_fail(0);
|
||||
return f;
|
||||
}
|
||||
#else
|
||||
#define io_nonblock_mode(fd) ((void)(fd), 0)
|
||||
#define get_fcntl_flags(fd) ((void)(fd), 0)
|
||||
#endif
|
||||
|
||||
#ifdef F_GETFL
|
||||
|
@ -41,7 +41,7 @@ rb_io_nonblock_p(VALUE io)
|
|||
{
|
||||
rb_io_t *fptr;
|
||||
GetOpenFile(io, fptr);
|
||||
if (io_nonblock_mode(fptr->fd) & O_NONBLOCK)
|
||||
if (get_fcntl_flags(fptr->fd) & O_NONBLOCK)
|
||||
return Qtrue;
|
||||
return Qfalse;
|
||||
}
|
||||
|
@ -50,6 +50,13 @@ rb_io_nonblock_p(VALUE io)
|
|||
#endif
|
||||
|
||||
#ifdef F_SETFL
|
||||
static void
|
||||
set_fcntl_flags(int fd, int f)
|
||||
{
|
||||
if (fcntl(fd, F_SETFL, f) == -1)
|
||||
rb_sys_fail(0);
|
||||
}
|
||||
|
||||
static int
|
||||
io_nonblock_set(int fd, int f, int nb)
|
||||
{
|
||||
|
@ -63,8 +70,7 @@ io_nonblock_set(int fd, int f, int nb)
|
|||
return 0;
|
||||
f &= ~O_NONBLOCK;
|
||||
}
|
||||
if (fcntl(fd, F_SETFL, f) == -1)
|
||||
rb_sys_fail(0);
|
||||
set_fcntl_flags(fd, f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -123,7 +129,7 @@ rb_io_nonblock_set(VALUE io, VALUE nb)
|
|||
if (RTEST(nb))
|
||||
rb_io_set_nonblock(fptr);
|
||||
else
|
||||
io_nonblock_set(fptr->fd, io_nonblock_mode(fptr->fd), RTEST(nb));
|
||||
io_nonblock_set(fptr->fd, get_fcntl_flags(fptr->fd), RTEST(nb));
|
||||
return io;
|
||||
}
|
||||
|
||||
|
@ -131,8 +137,7 @@ static VALUE
|
|||
io_nonblock_restore(VALUE arg)
|
||||
{
|
||||
int *restore = (int *)arg;
|
||||
if (fcntl(restore[0], F_SETFL, restore[1]) == -1)
|
||||
rb_sys_fail(0);
|
||||
set_fcntl_flags(restore[0], restore[1]);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
|
@ -159,7 +164,7 @@ rb_io_nonblock_block(int argc, VALUE *argv, VALUE io)
|
|||
rb_scan_args(argc, argv, "01", &v);
|
||||
nb = RTEST(v);
|
||||
}
|
||||
f = io_nonblock_mode(fptr->fd);
|
||||
f = get_fcntl_flags(fptr->fd);
|
||||
restore[0] = fptr->fd;
|
||||
restore[1] = f;
|
||||
if (!io_nonblock_set(fptr->fd, f, nb))
|
||||
|
|
Loading…
Add table
Reference in a new issue