From d64ac2686c3c1ff1eea4534100dca8fd73228a62 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 1 Mar 2011 08:51:28 +0000 Subject: POSIX_MQ#send returns +true+ on success This is to be consistent with POSIX_MQ#trysend --- ext/posix_mq/posix_mq.c | 11 ++++++++--- test/test_posix_mq.rb | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c index e9ae590..73cd815 100644 --- a/ext/posix_mq/posix_mq.c +++ b/ext/posix_mq/posix_mq.c @@ -509,9 +509,10 @@ static void setup_send_buffer(struct rw_args *x, VALUE buffer) } static VALUE _send(int sflags, int argc, VALUE *argv, VALUE self); + /* * call-seq: - * mq.send(string [,priority[, timeout]]) => nil + * mq.send(string [,priority[, timeout]]) => true * * Inserts the given +string+ into the message queue with an optional, * unsigned integer +priority+. If the optional +timeout+ is specified, @@ -524,7 +525,7 @@ static VALUE _send(int sflags, int argc, VALUE *argv, VALUE self); */ static VALUE my_send(int argc, VALUE *argv, VALUE self) { - _send(0, argc, argv, self); + return _send(0, argc, argv, self); } static VALUE _send(int sflags, int argc, VALUE *argv, VALUE self) @@ -549,7 +550,7 @@ static VALUE _send(int sflags, int argc, VALUE *argv, VALUE self) rb_sys_fail("mq_send"); } - return (sflags & PMQ_TRY) ? Qtrue : Qnil; + return Qtrue; } /* @@ -558,6 +559,10 @@ static VALUE _send(int sflags, int argc, VALUE *argv, VALUE self) * * Inserts the given +string+ into the message queue with a * default priority of 0 and no timeout. + * + * Returns itself so its calls may be chained. This use is only + * recommended only for users who expect blocking behavior from + * the queue. */ static VALUE send0(VALUE self, VALUE buffer) { diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb index ec9ba03..d48238c 100644 --- a/test/test_posix_mq.rb +++ b/test/test_posix_mq.rb @@ -155,7 +155,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase @mq = mq assert mq.kind_of?(POSIX_MQ) assert_equal @path, mq.name - assert_nil mq.send("HI", 0) + assert_equal true, mq.send("HI", 0) assert_equal 1, mq.attr.curmsgs assert_nil mq.close assert_raises(IOError) { mq.close } @@ -208,21 +208,21 @@ class Test_POSIX_MQ < Test::Unit::TestCase def test_send_receive @mq = POSIX_MQ.new @path, IO::CREAT|IO::RDWR, 0666 - assert_nil @mq.send("hello", 0) + assert_equal true, @mq.send("hello", 0) assert_equal [ "hello", 0 ], @mq.receive end def test_send_receive_buf buf = "" @mq = POSIX_MQ.new @path, IO::CREAT|IO::RDWR, 0666 - assert_nil @mq.send("hello", 0) + assert_equal true, @mq.send("hello", 0) assert_equal [ "hello", 0 ], @mq.receive(buf) assert_equal "hello", buf end def test_send_receive_prio @mq = POSIX_MQ.new @path, IO::CREAT|IO::RDWR, 0666 - assert_nil @mq.send("hello", 2) + assert_equal true, @mq.send("hello", 2) assert_equal [ "hello", 2 ], @mq.receive end -- cgit v1.2.3-24-ge0c7