зеркало из https://github.com/github/ruby.git
* ext/io/wait/wait.c (io_nread): returns number of bytes available
for read. response to feature request #936 in [ruby-core:20917]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
95327358ce
Коммит
d33298e524
|
@ -1,3 +1,8 @@
|
|||
Mon Dec 29 18:02:45 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* ext/io/wait/wait.c (io_nread): returns number of bytes available
|
||||
for read. response to feature request #936 in [ruby-core:20917].
|
||||
|
||||
Mon Dec 29 17:52:16 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* ext/io/wait/wait.c (io_ready_p): updated to follow RDoc.
|
||||
|
|
|
@ -42,6 +42,31 @@ void Init_wait _((void));
|
|||
|
||||
EXTERN struct timeval rb_time_interval _((VALUE time));
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* io.nread -> int
|
||||
*
|
||||
* Returns number of bytes that can be read without blocking.
|
||||
* Returns zero if no information available.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
io_nread(VALUE io)
|
||||
{
|
||||
rb_io_t *fptr;
|
||||
int len;
|
||||
ioctl_arg n;
|
||||
|
||||
GetOpenFile(io, fptr);
|
||||
rb_io_check_readable(fptr);
|
||||
len = rb_io_read_pending(fptr);
|
||||
if (len > 0) return len;
|
||||
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0);
|
||||
if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0);
|
||||
if (n > 0) return ioctl_arg2num(n);
|
||||
return INT2FIX(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* io.ready? -> true, false or nil
|
||||
|
@ -137,6 +162,7 @@ io_wait(int argc, VALUE *argv, VALUE io)
|
|||
void
|
||||
Init_wait()
|
||||
{
|
||||
rb_define_method(rb_cIO, "nread", io_nread, 0);
|
||||
rb_define_method(rb_cIO, "ready?", io_ready_p, 0);
|
||||
rb_define_method(rb_cIO, "wait", io_wait, -1);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче