From 67a59023164bc039129b34a742f06ba376687684 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 17 Feb 2010 00:37:43 -0800 Subject: make POSIX_MQ#dup and POSIX_MQ#clone no-op It'll cause problems for the automatic mq_close() during GC otherwise, as dup(2) on an mqd_t isn't portable. Of course there's no point in cloning or duping, either, as mq_send/mq_receive operations are always atomic at the kernel level and only one thread can have a notification registered for it. --- lib/posix_mq.rb | 12 ++++++++++++ test/test_posix_mq.rb | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/posix_mq.rb b/lib/posix_mq.rb index af31c16..86fa67e 100644 --- a/lib/posix_mq.rb +++ b/lib/posix_mq.rb @@ -66,6 +66,18 @@ class POSIX_MQ nil end if RUBY_PLATFORM =~ /linux/ + # There's no point in ever duping a POSIX_MQ object. + # All send/receive operations are atomic and only one + # native thread may be notified at a time + def dup + self + end + + # There's no point in ever cloning a POSIX_MQ object. + # All send/receive operations are atomic and only one + # native thread may be notified at a time + alias clone dup + end require 'posix_mq_ext' diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb index 42be59a..fa98a9c 100644 --- a/test/test_posix_mq.rb +++ b/test/test_posix_mq.rb @@ -27,6 +27,14 @@ class Test_POSIX_MQ < Test::Unit::TestCase assert @mq.closed? end + def test_dup_clone + @mq = POSIX_MQ.new(@path, :rw) + dup = @mq.dup + assert_equal @mq.object_id, dup.object_id + clone = @mq.clone + assert_equal @mq.object_id, clone.object_id + end + def test_timed_receive interval = 0.01 @mq = POSIX_MQ.new(@path, :rw) -- cgit v1.2.3-24-ge0c7