ruby-changes:38186
From: nobu <ko1@a...>
Date: Sun, 12 Apr 2015 23:21:28 +0900 (JST)
Subject: [ruby-changes:38186] nobu:r50262 (trunk): wait.c: poll over nread
nobu 2015-04-12 15:08:39 +0900 (Sun, 12 Apr 2015) New Revision: 50262 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50262 Log: 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] Modified files: trunk/ChangeLog trunk/ext/io/wait/wait.c Index: ChangeLog =================================================================== --- ChangeLog (revision 50261) +++ ChangeLog (revision 50262) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Apr 12 15:08:13 2015 Nobuyoshi Nakada <nobu@r...> + + * 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] + Sun Apr 12 14:53:23 2015 SHIBATA Hiroshi <shibata.hiroshi@g...> * lib/rubygems/test_case.rb: fixed json load error for rubygems tests. Index: ext/io/wait/wait.c =================================================================== --- ext/io/wait/wait.c (revision 50261) +++ ext/io/wait/wait.c (revision 50262) @@ -105,14 +105,13 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/io/wait/wait.c#L105 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 https://github.com/ruby/ruby/blob/trunk/ext/io/wait/wait.c#L130 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, https://github.com/ruby/ruby/blob/trunk/ext/io/wait/wait.c#L137 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; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/