wait.c: get_timeout
* ext/io/wait/wait.c (get_timeout): extract function to get timeout value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2c292588ba
commit
f7dca1d7cd
@ -44,6 +44,20 @@ static VALUE io_wait_readable _((int argc, VALUE *argv, VALUE io));
|
|||||||
static VALUE io_wait_writable _((int argc, VALUE *argv, VALUE io));
|
static VALUE io_wait_writable _((int argc, VALUE *argv, VALUE io));
|
||||||
void Init_wait _((void));
|
void Init_wait _((void));
|
||||||
|
|
||||||
|
static struct timeval *
|
||||||
|
get_timeout(int argc, VALUE *argv, struct timeval *timerec)
|
||||||
|
{
|
||||||
|
VALUE timeout = Qnil;
|
||||||
|
rb_check_arity(argc, 0, 1);
|
||||||
|
if (!argc || NIL_P(timeout = argv[0])) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*timerec = rb_time_interval(timeout);
|
||||||
|
return timerec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* io.nread -> int
|
* io.nread -> int
|
||||||
@ -109,21 +123,12 @@ io_wait_readable(int argc, VALUE *argv, VALUE io)
|
|||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
int i;
|
int i;
|
||||||
ioctl_arg n;
|
ioctl_arg n;
|
||||||
VALUE timeout;
|
|
||||||
struct timeval timerec;
|
struct timeval timerec;
|
||||||
struct timeval *tv;
|
struct timeval *tv;
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_readable(fptr);
|
rb_io_check_readable(fptr);
|
||||||
rb_scan_args(argc, argv, "01", &timeout);
|
tv = get_timeout(argc, argv, &timerec);
|
||||||
if (NIL_P(timeout)) {
|
|
||||||
tv = NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
timerec = rb_time_interval(timeout);
|
|
||||||
tv = &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);
|
i = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, tv);
|
||||||
@ -148,21 +153,12 @@ io_wait_writable(int argc, VALUE *argv, VALUE io)
|
|||||||
{
|
{
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
int i;
|
int i;
|
||||||
VALUE timeout;
|
|
||||||
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);
|
||||||
rb_scan_args(argc, argv, "01", &timeout);
|
tv = get_timeout(argc, argv, &timerec);
|
||||||
if (NIL_P(timeout)) {
|
|
||||||
tv = NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
timerec = rb_time_interval(timeout);
|
|
||||||
tv = &timerec;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_OUT, tv);
|
i = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_OUT, tv);
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user