sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: sleepy.penguin@librelist.org
Subject: [sleepy.penguin] [PATCH] do not propagate Errno::EINTR into Ruby
Date: Thu, 2 May 2013 22:38:13 +0000	[thread overview]
Message-ID: <20130502223813.GA21671@dcvr.yhbt.net> (raw)
In-Reply-To: <20130502223813.GA21671@dcvr.yhbt.net>

To be consistent with I/O wrappers in Ruby, Ruby-land should
never see EINTR from kevent or epoll_wait.  We will just return
zero events if our timeout expired soon after we got signaled.
---
 ext/sleepy_penguin/epoll.c  | 8 ++++++--
 ext/sleepy_penguin/kqueue.c | 8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/ext/sleepy_penguin/epoll.c b/ext/sleepy_penguin/epoll.c
index 90ecc2c..9010e2d 100644
--- a/ext/sleepy_penguin/epoll.c
+++ b/ext/sleepy_penguin/epoll.c
@@ -147,8 +147,12 @@ static VALUE epwait_result(struct ep_per_thread *ept, int n)
 	struct epoll_event *epoll_event = ept->events;
 	VALUE obj_events, obj;
 
-	if (n < 0)
-		rb_sys_fail("epoll_wait");
+	if (n < 0) {
+		if (errno == EINTR)
+			n = 0;
+		else
+			rb_sys_fail("epoll_wait");
+	}
 
 	for (i = n; --i >= 0; epoll_event++) {
 		obj_events = UINT2NUM(epoll_event->events);
diff --git a/ext/sleepy_penguin/kqueue.c b/ext/sleepy_penguin/kqueue.c
index 155204b..4d5785f 100644
--- a/ext/sleepy_penguin/kqueue.c
+++ b/ext/sleepy_penguin/kqueue.c
@@ -158,8 +158,12 @@ static VALUE kevent_result(struct kq_per_thread *kpt, int nevents)
 	int i;
 	struct kevent *event = kpt->events;
 
-	if (nevents < 0)
-		rb_sys_fail("kevent");
+	if (nevents < 0) {
+		if (errno == EINTR)
+			nevents = 0;
+		else
+			rb_sys_fail("kevent");
+	}
 
 	for (i = nevents; --i >= 0; event++)
 		yield_kevent(event);
-- 
Eric Wong


           reply	other threads:[~2013-05-02 22:38 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20130502223813.GA21671@dcvr.yhbt.net>]

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=20130502223813.GA21671@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=sleepy.penguin@librelist.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).