1#include "ruby/ruby.h"
2#include "ruby/io.h"
3
4static VALUE
5wait_for_single_fd(VALUE ign, VALUE fd, VALUE events, VALUE timeout)
6{
7    struct timeval tv;
8    struct timeval *tvp = NULL;
9    int rc;
10
11    if (!NIL_P(timeout)) {
12	tv = rb_time_timeval(timeout);
13	tvp = &tv;
14    }
15
16    rc = rb_wait_for_single_fd(NUM2INT(fd), NUM2INT(events), tvp);
17    if (rc == -1)
18	rb_sys_fail("rb_wait_for_single_fd");
19    return INT2NUM(rc);
20}
21
22void
23Init_wait_for_single_fd(void)
24{
25    rb_define_const(rb_cObject, "RB_WAITFD_IN", INT2NUM(RB_WAITFD_IN));
26    rb_define_const(rb_cObject, "RB_WAITFD_OUT", INT2NUM(RB_WAITFD_OUT));
27    rb_define_const(rb_cObject, "RB_WAITFD_PRI", INT2NUM(RB_WAITFD_PRI));
28    rb_define_singleton_method(rb_cIO, "wait_for_single_fd",
29                               wait_for_single_fd, 3);
30}
31