зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
a4f7274423
Коммит
1baa57b003
|
@ -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>
|
||||
|
||||
* lib/rubygems/test_case.rb: fixed json load error for rubygems tests.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче