From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] sendmsg_nonblock "exception: false"
Date: Tue, 2 Jun 2015 02:35:17 +0000 [thread overview]
Message-ID: <1433212517-17371-1-git-send-email-e@80x24.org> (raw)
---
ext/socket/ancdata.c | 23 +++++++++++++++++++----
test/socket/test_nonblock.rb | 1 +
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index 277a1e8..5459218 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -3,6 +3,7 @@
#include <time.h>
int rsock_cmsg_cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */
+static VALUE sym_exception, sym_wait_writable;
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
static VALUE rb_cAncillaryData;
@@ -1133,6 +1134,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
VALUE data, vflags, dest_sockaddr;
struct msghdr mh;
struct iovec iov;
+ VALUE opts = Qnil;
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
VALUE controls = Qnil;
VALUE controls_str = 0;
@@ -1140,6 +1142,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
#endif
int flags;
ssize_t ss;
+ int ex = 1;
GetOpenFile(sock, fptr);
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
@@ -1151,11 +1154,15 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
if (argc == 0)
rb_raise(rb_eArgError, "mesg argument required");
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
- rb_scan_args(argc, argv, "12*", &data, &vflags, &dest_sockaddr, &controls);
+ rb_scan_args(argc, argv, "12*:", &data, &vflags, &dest_sockaddr, &controls,
+ &opts);
#else
- rb_scan_args(argc, argv, "12", &data, &vflags, &dest_sockaddr);
+ rb_scan_args(argc, argv, "12:", &data, &vflags, &dest_sockaddr, &opts);
#endif
+ if (!NIL_P(opts) && Qfalse == rb_hash_lookup2(opts, sym_exception, Qundef))
+ ex = 0;
+
StringValue(data);
if (!NIL_P(controls)) {
@@ -1287,8 +1294,13 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
rb_io_check_closed(fptr);
goto retry;
}
- if (nonblock && (errno == EWOULDBLOCK || errno == EAGAIN))
- rb_readwrite_sys_fail(RB_IO_WAIT_WRITABLE, "sendmsg(2) would block");
+ if (nonblock && (errno == EWOULDBLOCK || errno == EAGAIN)) {
+ if (ex) {
+ rb_readwrite_sys_fail(RB_IO_WAIT_WRITABLE,
+ "sendmsg(2) would block");
+ }
+ return sym_wait_writable;
+ }
rb_sys_fail("sendmsg(2)");
}
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
@@ -1839,4 +1851,7 @@ rsock_init_ancdata(void)
rb_define_method(rb_cAncillaryData, "ipv6_pktinfo_addr", ancillary_ipv6_pktinfo_addr, 0);
rb_define_method(rb_cAncillaryData, "ipv6_pktinfo_ifindex", ancillary_ipv6_pktinfo_ifindex, 0);
#endif
+#undef rb_intern
+ sym_exception = ID2SYM(rb_intern("exception"));
+ sym_wait_writable = ID2SYM(rb_intern("wait_writable"));
}
diff --git a/test/socket/test_nonblock.rb b/test/socket/test_nonblock.rb
index 4b1f209..11bdb9c 100644
--- a/test/socket/test_nonblock.rb
+++ b/test/socket/test_nonblock.rb
@@ -282,6 +282,7 @@ class TestSocketNonblock < Test::Unit::TestCase
assert_raises(IO::WaitWritable) do
loop { s1.sendmsg_nonblock(buf) }
end
+ assert_equal :wait_writable, s1.sendmsg_nonblock(buf, exception: false)
end
else
skip "UNIXSocket.pair(:SEQPACKET) not implemented on this platform"
--
EW
reply other threads:[~2015-06-02 2:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1433212517-17371-1-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.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.
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).