diff options
author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
---|---|---|
committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/ext/-test-/wait_for_single_fd/wait_for_single_fd.c |
Fresh start
Diffstat (limited to 'jni/ruby/ext/-test-/wait_for_single_fd/wait_for_single_fd.c')
-rw-r--r-- | jni/ruby/ext/-test-/wait_for_single_fd/wait_for_single_fd.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/jni/ruby/ext/-test-/wait_for_single_fd/wait_for_single_fd.c b/jni/ruby/ext/-test-/wait_for_single_fd/wait_for_single_fd.c new file mode 100644 index 0000000..d406724 --- /dev/null +++ b/jni/ruby/ext/-test-/wait_for_single_fd/wait_for_single_fd.c @@ -0,0 +1,30 @@ +#include "ruby/ruby.h" +#include "ruby/io.h" + +static VALUE +wait_for_single_fd(VALUE ign, VALUE fd, VALUE events, VALUE timeout) +{ + struct timeval tv; + struct timeval *tvp = NULL; + int rc; + + if (!NIL_P(timeout)) { + tv = rb_time_timeval(timeout); + tvp = &tv; + } + + rc = rb_wait_for_single_fd(NUM2INT(fd), NUM2INT(events), tvp); + if (rc == -1) + rb_sys_fail("rb_wait_for_single_fd"); + return INT2NUM(rc); +} + +void +Init_wait_for_single_fd(void) +{ + rb_define_const(rb_cObject, "RB_WAITFD_IN", INT2NUM(RB_WAITFD_IN)); + rb_define_const(rb_cObject, "RB_WAITFD_OUT", INT2NUM(RB_WAITFD_OUT)); + rb_define_const(rb_cObject, "RB_WAITFD_PRI", INT2NUM(RB_WAITFD_PRI)); + rb_define_singleton_method(rb_cIO, "wait_for_single_fd", + wait_for_single_fd, 3); +} |