posix_mq RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [ANN] posix_mq 2.3.0 - POSIX Message Queues for Ruby
@ 2016-02-02 23:34  7% Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-02-02 23:34 UTC (permalink / raw)
  To: ruby-talk, ruby-posix-mq

POSIX message queues allow local processes to exchange data in the form
of messages.  This API is distinct from that provided by System V
message queues, but provides similar functionality.

* http://bogomips.org/ruby_posix_mq/
* mailto:ruby-posix-mq@bogomips.org
* git clone git://bogomips.org/ruby_posix_mq.git
* Atom feed: http://bogomips.org/ruby_posix_mq/NEWS.atom.xml
* archives: http://bogomips.org/ruby-posix-mq/
  nntp://news.public-inbox.org/inbox.comp.lang.ruby.posix-mq
* gem install -v 2.3.0 posix_mq

Changes:

    Ruby posix_mq 2.3.0 - updates for Ruby 2.3+

    This release updates our POSIX_MQ#close to match the idempotent
    IO#close behavior under Ruby 2.3 and later.  Previous Ruby versions
    continue to be supported, but POSIX_MQ#close remains non-idempotent
    when built against old Ruby versions.

    4 changes since v2.2.0:

          enable frozen_string_literal for Ruby 2.3+
          support idempotent POSIX_MQ#close
          README: remove cgit and ssoma references
          build: use '--local' domain for dev gem install

Have fun!

^ permalink raw reply	[relevance 7%]

* [PATCH] support idempotent POSIX_MQ#close
@ 2016-02-02 22:54  6% Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-02-02 22:54 UTC (permalink / raw)
  To: ruby-posix-mq

IO#close under Ruby 2.3 is idempotent, we shall follow suit
with POSIX_MQ#close
---
 ext/posix_mq/extconf.rb | 11 +++++++++++
 ext/posix_mq/posix_mq.c | 10 +++++++++-
 test/test_posix_mq.rb   | 16 +++++++++++++++-
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/ext/posix_mq/extconf.rb b/ext/posix_mq/extconf.rb
index eb799b2..d433d1d 100644
--- a/ext/posix_mq/extconf.rb
+++ b/ext/posix_mq/extconf.rb
@@ -14,4 +14,15 @@
 have_func("__mq_oshandle")
 have_func("mq_timedsend")
 have_func("mq_timedreceive")
+
+r, w = IO.pipe
+r.close
+w.close
+begin
+  r.close
+  $CPPFLAGS += ' -DIDEMPOTENT_IO_CLOSE=1'
+rescue IOError
+  $CPPFLAGS += ' -DIDEMPOTENT_IO_CLOSE=0'
+end
+
 create_makefile("posix_mq_ext")
diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c
index 5e1b3b8..0567676 100644
--- a/ext/posix_mq/posix_mq.c
+++ b/ext/posix_mq/posix_mq.c
@@ -824,7 +824,15 @@ static VALUE setattr(VALUE self, VALUE astruct)
  */
 static VALUE _close(VALUE self)
 {
-	struct posix_mq *mq = get(self, 1);
+	struct posix_mq *mq;
+
+	if (IDEMPOTENT_IO_CLOSE) { /* defined in extconf.rb */
+		mq = get(self, 0);
+		if (!mq || (mq->des == MQD_INVALID))
+			return Qnil;
+	} else {
+		mq = get(self, 1);
+	}
 
 	if (! MQ_IO_CLOSE(mq)) {
 		if (mq_close(mq->des) < 0)
diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb
index d726d36..e831012 100644
--- a/test/test_posix_mq.rb
+++ b/test/test_posix_mq.rb
@@ -152,7 +152,21 @@ def test_open
       assert_equal true, mq.send("HI", 0)
       assert_equal 1, mq.attr.curmsgs
       assert_nil mq.close
-      assert_raises(IOError) { mq.close }
+
+      r, w = IO.pipe
+      w.close
+      r.close
+      idempotent_close = begin
+        r.close
+        true
+      rescue IOError
+        false
+      end
+      if idempotent_close
+        2.times { assert_nil mq.close }
+      else
+        assert_raises(IOError) { mq.close }
+      end
     end
     assert @mq.closed?
     @mq = nil
-- 
EW


^ permalink raw reply related	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-02-02 22:54  6% [PATCH] support idempotent POSIX_MQ#close Eric Wong
2016-02-02 23:34  7% [ANN] posix_mq 2.3.0 - POSIX Message Queues for Ruby Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/ruby_posix_mq.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).