summaryrefslogtreecommitdiff
path: root/ext/io
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-12 06:08:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-12 06:08:39 +0000
commit1baa57b00331e5bedd6253dbf4dadc490a480f81 (patch)
tree4a029ca42865a528db25076f23f7711da30a7bde /ext/io
parenta4f7274423dcf7a7ce5a727e69c18fc2e83d40cc (diff)
wait.c: poll over nread
* ext/io/wait/wait.c (io_ready_p, io_wait_readable): try polling first and check FIONREAD optionally to see if EOF. [ruby-core:36805] [Feature #4849] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/io')
-rw-r--r--ext/io/wait/wait.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/ext/io/wait/wait.c b/ext/io/wait/wait.c
index d166962..c48104f 100644
--- a/ext/io/wait/wait.c
+++ b/ext/io/wait/wait.c
@@ -105,14 +105,13 @@ static VALUE
io_ready_p(VALUE io)
{
rb_io_t *fptr;
- ioctl_arg n;
+ struct timeval tv = {0, 0};
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
if (rb_io_read_pending(fptr)) return Qtrue;
- if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qnil;
- if (ioctl(fptr->fd, FIONREAD, &n)) return Qnil;
- if (n > 0) return Qtrue;
+ if (wait_for_single_fd(fptr, RB_WAITFD_IN, &tv))
+ return Qtrue;
return Qfalse;
}
@@ -131,7 +130,6 @@ static VALUE
io_wait_readable(int argc, VALUE *argv, VALUE io)
{
rb_io_t *fptr;
- ioctl_arg n;
struct timeval timerec;
struct timeval *tv;
@@ -139,10 +137,12 @@ io_wait_readable(int argc, VALUE *argv, VALUE io)
rb_io_check_readable(fptr);
tv = get_timeout(argc, argv, &timerec);
if (rb_io_read_pending(fptr)) return Qtrue;
- if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
- wait_for_single_fd(fptr, RB_WAITFD_IN, tv);
- if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
- if (n > 0) return io;
+ if (wait_for_single_fd(fptr, RB_WAITFD_IN, tv)) {
+ ioctl_arg n;
+ if (!FIONREAD_POSSIBLE_P(fptr->fd)) return io;
+ if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
+ if (n > 0) return io;
+ }
return Qnil;
}