Ruby 1.9.3p327(2012-11-10revision37606)
ext/-test-/wait_for_single_fd/wait_for_single_fd.c
Go to the documentation of this file.
00001 #include "ruby/ruby.h"
00002 #include "ruby/io.h"
00003 
00004 static VALUE
00005 wait_for_single_fd(VALUE ign, VALUE fd, VALUE events, VALUE timeout)
00006 {
00007     struct timeval tv;
00008     struct timeval *tvp = NULL;
00009     int rc;
00010 
00011     if (!NIL_P(timeout)) {
00012         tv = rb_time_timeval(timeout);
00013         tvp = &tv;
00014     }
00015 
00016     rc = rb_wait_for_single_fd(NUM2INT(fd), NUM2INT(events), tvp);
00017     if (rc == -1)
00018         rb_sys_fail("rb_wait_for_single_fd");
00019     return INT2NUM(rc);
00020 }
00021 
00022 void
00023 Init_wait_for_single_fd(void)
00024 {
00025     rb_define_const(rb_cObject, "RB_WAITFD_IN", INT2NUM(RB_WAITFD_IN));
00026     rb_define_const(rb_cObject, "RB_WAITFD_OUT", INT2NUM(RB_WAITFD_OUT));
00027     rb_define_const(rb_cObject, "RB_WAITFD_PRI", INT2NUM(RB_WAITFD_PRI));
00028     rb_define_singleton_method(rb_cIO, "wait_for_single_fd",
00029                                wait_for_single_fd, 3);
00030 }
00031