kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: kgio-public@bogomips.org
Subject: [RFC] use MSG_NOSIGNAL under Linux 2.2+
Date: Fri, 13 Feb 2015 20:12:06 +0000	[thread overview]
Message-ID: <20150213201206.GA20113@dcvr.yhbt.net> (raw)

I don't consider this a serious patch because it only affects
rare error handling paths and is not going to make a difference
in real-world use.  But oh well, I'm low on caffeine right now :x

MSG_NOSIGNAL exists on any machine that supports MSG_DONTWAIT.
While Ruby itself ignore SIGPIPE, this can save a few cycles
inside the kernel by avoiding the no-op signal delivery
in the first place.
---
 ext/kgio/read.c  | 10 ++++++++--
 ext/kgio/write.c |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/ext/kgio/read.c b/ext/kgio/read.c
index 472a592..76b1638 100644
--- a/ext/kgio/read.c
+++ b/ext/kgio/read.c
@@ -5,8 +5,14 @@
 #include "nonblock.h"
 static VALUE sym_wait_readable;
 
+/*
+ * MSG_NOSIGNAL exists on any machine that supports MSG_DONTWAIT.
+ * While Ruby itself ignore SIGPIPE, this can save a few cycles
+ * inside the kernel by avoiding the no-op signal delivery
+ * in the first place.
+ */
 #ifdef USE_MSG_DONTWAIT
-static const int peek_flags = MSG_DONTWAIT|MSG_PEEK;
+static const int peek_flags = MSG_DONTWAIT|MSG_PEEK|MSG_NOSIGNAL;
 
 /* we don't need these variants, we call kgio_autopush_recv directly */
 static inline void kgio_autopush_read(VALUE io) { }
@@ -162,7 +168,7 @@ static VALUE my_recv(int io_wait, int argc, VALUE *argv, VALUE io)
 
 	if (a.len > 0) {
 retry:
-		n = (long)recv(a.fd, a.ptr, a.len, MSG_DONTWAIT);
+		n = (long)recv(a.fd, a.ptr, a.len, MSG_DONTWAIT|MSG_NOSIGNAL);
 		if (read_check(&a, n, "recv", io_wait) != 0)
 			goto retry;
 	}
diff --git a/ext/kgio/write.c b/ext/kgio/write.c
index ce4aa75..c97b049 100644
--- a/ext/kgio/write.c
+++ b/ext/kgio/write.c
@@ -123,7 +123,7 @@ static VALUE my_send(VALUE io, VALUE str, int io_wait)
 
 	prepare_write(&a, io, str);
 retry:
-	n = (long)send(a.fd, a.ptr, a.len, MSG_DONTWAIT);
+	n = (long)send(a.fd, a.ptr, a.len, MSG_DONTWAIT|MSG_NOSIGNAL);
 	if (write_check(&a, n, "send", io_wait) != 0)
 		goto retry;
 	if (TYPE(a.buf) != T_SYMBOL)
-- 
EW

             reply	other threads:[~2015-02-13 20:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-13 20:12 Eric Wong [this message]
2015-02-13 20:33 ` [RFC] use MSG_NOSIGNAL under Linux 2.2+ Eric Wong

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/kgio/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150213201206.GA20113@dcvr.yhbt.net \
    --to=e@80x24.org \
    --cc=kgio-public@bogomips.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/kgio.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).