From: Eric Wong <normalperson@yhbt.net>
To: ruby.posix.mq@librelist.com
Subject: Re: [PATCH 3/3] Add a sleep in alarm test in current Ruby.
Date: Tue, 3 Jul 2012 17:59:47 -0700 [thread overview]
Message-ID: <20120704005947.GA20834@dcvr.yhbt.net> (raw)
In-Reply-To: 20120704002017.GA14457@dcvr.yhbt.net
Eric Wong <normalperson@yhbt.net> wrote:
> Fwiw, I'm not sure if this is a good test, either. Since I
> wrote this code, I've come to believe normal API methods should
> not raise Errno::EINTR. I've changed a few of my other libraries
> (sleepy_penguin, kgio) to avoid EINTR but missed this one.
Something like this
>From 535c9541fdba10a9572b63efc0d0502d009da94c Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Tue, 3 Jul 2012 17:57:44 -0700
Subject: [PATCH] change blocking functions to not return EINTR
This is an API change.
---
ext/posix_mq/posix_mq.c | 12 +++++++++++-
test/test_posix_mq.rb | 10 ++++++----
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c
index 2958352..df667e3 100644
--- a/ext/posix_mq/posix_mq.c
+++ b/ext/posix_mq/posix_mq.c
@@ -542,8 +542,11 @@ static VALUE _send(int sflags, int argc, VALUE *argv, VALUE self)
x.timeout = convert_timeout(&expire, timeout);
x.msg_prio = NIL_P(prio) ? 0 : NUM2UINT(prio);
+retry:
rv = (mqd_t)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
if (rv == MQD_INVALID) {
+ if (errno == EINTR)
+ goto retry;
if (errno == EAGAIN && (sflags & PMQ_TRY))
return Qfalse;
rb_sys_fail("mq_send");
@@ -574,9 +577,13 @@ static VALUE send0(VALUE self, VALUE buffer)
x.timeout = NULL;
x.msg_prio = 0;
+retry:
rv = (mqd_t)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
- if (rv == MQD_INVALID)
+ if (rv == MQD_INVALID) {
+ if (errno == EINTR)
+ goto retry;
rb_sys_fail("mq_send");
+ }
return self;
}
@@ -678,8 +685,11 @@ static VALUE _receive(int rflags, int argc, VALUE *argv, VALUE self)
x.msg_len = (size_t)mq->attr.mq_msgsize;
x.des = mq->des;
+retry:
r = (ssize_t)rb_thread_blocking_region(xrecv, &x, RUBY_UBF_IO, 0);
if (r < 0) {
+ if (errno == EINTR)
+ goto retry;
if (errno == EAGAIN && (rflags & PMQ_TRY))
return Qnil;
rb_sys_fail("mq_receive");
diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb
index 5b78c22..8d6b014 100644
--- a/test/test_posix_mq.rb
+++ b/test/test_posix_mq.rb
@@ -118,16 +118,18 @@ class Test_POSIX_MQ < Test::Unit::TestCase
end
alarm or return warn "alarm() not found in #{libcs.inspect}"
alarms = 0
- trap("ALRM") { alarms += 1 }
+ trap("ALRM") do
+ alarms += 1
+ Thread.new { @mq.send("HI") }
+ end
interval = 1
alarm.call interval
@mq = POSIX_MQ.new(@path, :rw)
assert ! @mq.nonblock?
t0 = Time.now
- a = nil
- assert_raises(Errno::EINTR) { a = @mq.receive }
+ a = @mq.receive
elapsed = Time.now - t0
- assert_nil a
+ assert_equal(["HI", 0], a)
assert elapsed >= interval, elapsed.inspect
assert elapsed < 1.10, elapsed.inspect
assert_equal 1, alarms
next prev parent reply other threads:[~2012-07-04 1:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-03 20:13 [PATCH 1/3] Fix call to DL::Function.new in tests Hleb Valoshka
2012-07-03 20:13 ` [PATCH 2/3] Add libc names for Debian GNU/kFreeBSD and FreeBSD " Hleb Valoshka
2012-07-03 20:13 ` [PATCH 3/3] Add a sleep in alarm test in current Ruby Hleb Valoshka
2012-07-04 0:20 ` Eric Wong
2012-07-04 0:59 ` Eric Wong [this message]
2012-07-04 13:39 ` Hleb Valoshka
2012-07-12 8:03 ` Hleb Valoshka
2012-07-12 8:09 ` Eric Wong
2012-07-12 13:46 ` Hleb Valoshka
2012-07-12 19:46 ` Eric Wong
2012-07-13 7:21 ` Eric Wong
2012-07-13 16:46 ` Hleb Valoshka
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/ruby_posix_mq/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120704005947.GA20834@dcvr.yhbt.net \
--to=normalperson@yhbt.net \
--cc=ruby.posix.mq@librelist.com \
/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/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).