about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-03-22 07:08:29 +0000
committerEric Wong <e@80x24.org>2017-03-22 07:18:22 +0000
commit8b7e3ea07058c25e3870dad85f303a42fac146a8 (patch)
tree34383699957ad4a09b7b180c9be533687310f199
parentfa2cde77287ea63044153994783f34843bbfd7ec (diff)
downloadsleepy_penguin-8b7e3ea07058c25e3870dad85f303a42fac146a8.tar.gz
We will not implement "pipe_size" as an accessor in a core
class like the "io_splice" RubyGem did.
-rw-r--r--ext/sleepy_penguin/splice.c10
-rw-r--r--test/test_pipesize.rb22
2 files changed, 32 insertions, 0 deletions
diff --git a/ext/sleepy_penguin/splice.c b/ext/sleepy_penguin/splice.c
index d291796..ab8c1ff 100644
--- a/ext/sleepy_penguin/splice.c
+++ b/ext/sleepy_penguin/splice.c
@@ -149,6 +149,10 @@ void sleepy_penguin_init_splice(void)
          * fcntl() command constant used to return the size of a pipe.
          * This constant is only defined when running Linux 2.6.35
          * or later.
+         *
+         *        require 'fcntl'
+         *        r, w = IO.pipe
+         *        r.fcntl(SleepyPenguin::F_GETPIPE_SZ) => Integer
          */
         rb_define_const(mod, "F_GETPIPE_SZ", UINT2NUM(F_GETPIPE_SZ));
 
@@ -156,6 +160,12 @@ void sleepy_penguin_init_splice(void)
          * fcntl() command constant used to set the size of a pipe.
          * This constant is only defined when running Linux 2.6.35
          * or later.
+         *
+         * call-seq:
+         *
+         *        require 'fcntl'
+         *        r, w = IO.pipe
+         *        r.fcntl(SleepyPenguin::F_SETPIPE_SZ, 131072)
          */
         rb_define_const(mod, "F_SETPIPE_SZ", UINT2NUM(F_SETPIPE_SZ));
 
diff --git a/test/test_pipesize.rb b/test/test_pipesize.rb
new file mode 100644
index 0000000..c9ff143
--- /dev/null
+++ b/test/test_pipesize.rb
@@ -0,0 +1,22 @@
+# -*- encoding: binary -*-
+require_relative 'helper'
+require 'fcntl'
+
+class TestPipesize < Test::Unit::TestCase
+  def test_pipe_size
+    return unless RUBY_PLATFORM =~ /linux/
+    [ :F_GETPIPE_SZ, :F_SETPIPE_SZ ].each do |c|
+      return unless SleepyPenguin.const_defined?(c)
+    end
+    r, w = pipe = IO.pipe
+    nr = r.fcntl(SleepyPenguin::F_GETPIPE_SZ)
+    assert_kind_of Integer, nr
+    assert_operator nr, :>, 0
+
+    set = 131072
+    r.fcntl(SleepyPenguin::F_SETPIPE_SZ, set)
+    assert_equal set, r.fcntl(SleepyPenguin::F_GETPIPE_SZ)
+  ensure
+    pipe.each(&:close) if pipe
+  end
+end