about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-06-15 02:39:13 +0000
committerEric Wong <normalperson@yhbt.net>2011-06-15 02:39:13 +0000
commit9159f70862e3e6a76d821c4a70bc68a603793a49 (patch)
treef3ef5c6c5dfc73f54ebd7e71d4f56e29d16396a6
parent6d6f704e29d7bf1e95f1c9c60cbab82ec3d430d2 (diff)
downloadkgio-9159f70862e3e6a76d821c4a70bc68a603793a49.tar.gz
Kgio::File may be used to open FIFOs, so non-blocking
I/O is still useful in that context.
-rw-r--r--ext/kgio/tryopen.c2
-rw-r--r--test/test_tryopen.rb8
2 files changed, 10 insertions, 0 deletions
diff --git a/ext/kgio/tryopen.c b/ext/kgio/tryopen.c
index 26f1986..16f47fb 100644
--- a/ext/kgio/tryopen.c
+++ b/ext/kgio/tryopen.c
@@ -124,6 +124,7 @@ retry:
 void init_kgio_tryopen(void)
 {
         VALUE mKgio = rb_define_module("Kgio");
+        VALUE mPipeMethods = rb_const_get(mKgio, rb_intern("PipeMethods"));
         VALUE cFile;
         VALUE tmp;
         VALUE *ptr;
@@ -144,6 +145,7 @@ void init_kgio_tryopen(void)
          */
         cFile = rb_define_class_under(mKgio, "File", rb_cFile);
         rb_define_singleton_method(cFile, "tryopen", s_tryopen, -1);
+        rb_include_module(cFile, mPipeMethods);
 
         if (!rb_funcall(cFile, rb_intern("method_defined?"), 1,
                         ID2SYM(id_to_path)))
diff --git a/test/test_tryopen.rb b/test/test_tryopen.rb
index e60cb27..380026d 100644
--- a/test/test_tryopen.rb
+++ b/test/test_tryopen.rb
@@ -36,6 +36,14 @@ class TestTryopen < Test::Unit::TestCase
     assert_equal "FOO", tmp.sysread(3)
   end
 
+  def test_tryopen_try_readwrite
+    tmp = Tempfile.new "tryopen"
+    file = Kgio::File.tryopen(tmp.path, IO::RDWR)
+    assert_nil file.kgio_trywrite("FOO")
+    file.rewind
+    assert_equal "FOO", file.kgio_tryread(3)
+  end
+
   def test_tryopen_mode
     tmp = Tempfile.new "tryopen"
     path = tmp.path