* 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
This commit is contained in:
nobu 2015-04-12 06:08:39 +00:00
Родитель a4f7274423
Коммит 1baa57b003
2 изменённых файлов: 15 добавлений и 9 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Sun Apr 12 15:08:13 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@gmail.com> Sun Apr 12 14:53:23 2015 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* lib/rubygems/test_case.rb: fixed json load error for rubygems tests. * lib/rubygems/test_case.rb: fixed json load error for rubygems tests.

Просмотреть файл

@ -105,14 +105,13 @@ static VALUE
io_ready_p(VALUE io) io_ready_p(VALUE io)
{ {
rb_io_t *fptr; rb_io_t *fptr;
ioctl_arg n; struct timeval tv = {0, 0};
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
rb_io_check_readable(fptr); rb_io_check_readable(fptr);
if (rb_io_read_pending(fptr)) return Qtrue; if (rb_io_read_pending(fptr)) return Qtrue;
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qnil; if (wait_for_single_fd(fptr, RB_WAITFD_IN, &tv))
if (ioctl(fptr->fd, FIONREAD, &n)) return Qnil; return Qtrue;
if (n > 0) return Qtrue;
return Qfalse; return Qfalse;
} }
@ -131,7 +130,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;
ioctl_arg n;
struct timeval timerec; struct timeval timerec;
struct timeval *tv; struct timeval *tv;
@ -139,10 +137,12 @@ io_wait_readable(int argc, VALUE *argv, VALUE io)
rb_io_check_readable(fptr); rb_io_check_readable(fptr);
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 (wait_for_single_fd(fptr, RB_WAITFD_IN, tv)) {
wait_for_single_fd(fptr, RB_WAITFD_IN, tv); ioctl_arg n;
if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0); if (!FIONREAD_POSSIBLE_P(fptr->fd)) return io;
if (n > 0) return io; if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
if (n > 0) return io;
}
return Qnil; return Qnil;
} }