sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: sleepy-penguin@bogomips.org
Subject: [PATCH] doc: tests and examples for changing pipe size in Linux
Date: Wed, 22 Mar 2017 07:19:18 +0000	[thread overview]
Message-ID: <20170322071918.24555-1-e@80x24.org> (raw)

We will not implement "pipe_size" as an accessor in a core
class like the "io_splice" RubyGem did.
---
 ext/sleepy_penguin/splice.c | 10 ++++++++++
 test/test_pipesize.rb       | 22 ++++++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 test/test_pipesize.rb

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
-- 
EW


                 reply	other threads:[~2017-03-22  7:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/sleepy_penguin/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170322071918.24555-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=sleepy-penguin@bogomips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/sleepy_penguin.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).