wait.c: wait_for_single_fd
* ext/io/wait/wait.c (wait_for_single_fd): extract wrapper function of rb_wait_for_single_fd(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
77ea0461c9
commit
b850ec4680
@ -58,6 +58,16 @@ get_timeout(int argc, VALUE *argv, struct timeval *timerec)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
wait_for_single_fd(rb_io_t *fptr, int events, struct timeval *tv)
|
||||||
|
{
|
||||||
|
int i = rb_wait_for_single_fd(fptr->fd, events, tv);
|
||||||
|
if (i < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
|
rb_io_check_closed(fptr);
|
||||||
|
return (i & events);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* io.nread -> int
|
* io.nread -> int
|
||||||
@ -121,7 +131,6 @@ static VALUE
|
|||||||
io_wait_readable(int argc, VALUE *argv, VALUE io)
|
io_wait_readable(int argc, VALUE *argv, VALUE io)
|
||||||
{
|
{
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
int i;
|
|
||||||
ioctl_arg n;
|
ioctl_arg n;
|
||||||
struct timeval timerec;
|
struct timeval timerec;
|
||||||
struct timeval *tv;
|
struct timeval *tv;
|
||||||
@ -131,10 +140,7 @@ io_wait_readable(int argc, VALUE *argv, VALUE io)
|
|||||||
tv = get_timeout(argc, argv, &timerec);
|
tv = get_timeout(argc, argv, &timerec);
|
||||||
if (rb_io_read_pending(fptr)) return Qtrue;
|
if (rb_io_read_pending(fptr)) return Qtrue;
|
||||||
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
|
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
|
||||||
i = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, tv);
|
wait_for_single_fd(fptr, RB_WAITFD_IN, tv);
|
||||||
if (i < 0)
|
|
||||||
rb_sys_fail(0);
|
|
||||||
rb_io_check_closed(fptr);
|
|
||||||
if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
|
if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
|
||||||
if (n > 0) return io;
|
if (n > 0) return io;
|
||||||
return Qnil;
|
return Qnil;
|
||||||
@ -152,19 +158,15 @@ static VALUE
|
|||||||
io_wait_writable(int argc, VALUE *argv, VALUE io)
|
io_wait_writable(int argc, VALUE *argv, VALUE io)
|
||||||
{
|
{
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
int i;
|
|
||||||
struct timeval timerec;
|
struct timeval timerec;
|
||||||
struct timeval *tv;
|
struct timeval *tv;
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_writable(fptr);
|
rb_io_check_writable(fptr);
|
||||||
tv = get_timeout(argc, argv, &timerec);
|
tv = get_timeout(argc, argv, &timerec);
|
||||||
i = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_OUT, tv);
|
if (wait_for_single_fd(fptr, RB_WAITFD_OUT, tv)) {
|
||||||
if (i < 0)
|
|
||||||
rb_sys_fail(0);
|
|
||||||
rb_io_check_closed(fptr);
|
|
||||||
if (i & RB_WAITFD_OUT)
|
|
||||||
return io;
|
return io;
|
||||||
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user