summaryrefslogtreecommitdiff
path: root/ext/-test-/wait_for_single_fd
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-04 09:50:27 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-04 09:50:27 +0000
commit2a989121db8f80aceeadb5d403af79d4b30e1bb8 (patch)
treef9e7ac9a210649fcd0cb7407453d94964796bc9e /ext/-test-/wait_for_single_fd
parent8a98c57ff064ac8f1555be414e28df418685ca30 (diff)
* ext/-test-/wait_for_single_fd: New. for testing
rb_wait_for_single_fd() internal function. The patch was written by Eric Wong. [ruby-core:35991] * test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-/wait_for_single_fd')
-rw-r--r--ext/-test-/wait_for_single_fd/depend2
-rw-r--r--ext/-test-/wait_for_single_fd/extconf.rb1
-rw-r--r--ext/-test-/wait_for_single_fd/wait_for_single_fd.c30
3 files changed, 33 insertions, 0 deletions
diff --git a/ext/-test-/wait_for_single_fd/depend b/ext/-test-/wait_for_single_fd/depend
new file mode 100644
index 0000000..d9cd50a
--- /dev/null
+++ b/ext/-test-/wait_for_single_fd/depend
@@ -0,0 +1,2 @@
+wait_for_single_fd.o: $(top_srcdir)/thread.c \
+ $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/io.h
diff --git a/ext/-test-/wait_for_single_fd/extconf.rb b/ext/-test-/wait_for_single_fd/extconf.rb
new file mode 100644
index 0000000..1a28b23
--- /dev/null
+++ b/ext/-test-/wait_for_single_fd/extconf.rb
@@ -0,0 +1 @@
+create_makefile("-test-/wait_for_single_fd/wait_for_single_fd")
diff --git a/ext/-test-/wait_for_single_fd/wait_for_single_fd.c b/ext/-test-/wait_for_single_fd/wait_for_single_fd.c
new file mode 100644
index 0000000..d406724
--- /dev/null
+++ b/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);
+}