diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-15 19:38:49 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-15 19:38:49 +0000 |
commit | 4463ca4c4dba623c9bd73e4615b6574c6ec132e9 (patch) | |
tree | 2c2943128de42db8c8eba898a1c402c7d8bf8ca1 /ext/socket/socket.c | |
parent | a94a984089b9815cbf5255d27c3d7c37d8e907b6 (diff) | |
download | ruby-4463ca4c4dba623c9bd73e4615b6574c6ec132e9.tar.gz |
socket: allow exception-free nonblocking sendmsg/recvmsg
As documented before, exceptions are expensive and IO::Wait*able are too
common in socket applications to be the exceptional case. Datagram
sockets deserve the same API which stream sockets are allowed with
read_nonblock and write_nonblock.
Note: this does not offer a performance advantage under optimal
conditions when both ends are equally matched in speed, but it it
does make debug output cleaner by avoiding exceptions whenever
the receiver slows down.
* ext/socket/ancdata.c (bsock_sendmsg_internal, bsock_recvmsg_internal):
support "exception: false" kwarg
* ext/socket/init.c (rsock_s_recvfrom_nonblock):
ditto
* ext/socket/init.c (rsock_s_recvfrom_nonblock): use rsock_opt_false_p
* ext/socket/socket.c (sock_connect_nonblock): ditto
* ext/socket/rubysocket.h (rsock_opt_false_p): new function
* ext/socket/basicsocket.c (bsock_recv_nonblock): update rdoc
* ext/socket/udpsocket.c (udp_recvfrom_nonblock): ditto
* test/socket/test_nonblock.rb: new tests
[ruby-core:69542] [Feature #11229]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r-- | ext/socket/socket.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c index bb23703706..f2d4323a89 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -503,15 +503,13 @@ sock_connect_nonblock(int argc, VALUE *argv, VALUE sock) n = connect(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_SOCKLEN(addr)); if (n < 0) { if (errno == EINPROGRESS) { - if (!NIL_P(opts) && - Qfalse == rb_hash_lookup2(opts, sym_exception, Qundef)) { + if (rsock_opt_false_p(opts, sym_exception)) { return sym_wait_writable; } rb_readwrite_sys_fail(RB_IO_WAIT_WRITABLE, "connect(2) would block"); } if (errno == EISCONN) { - if (!NIL_P(opts) && - Qfalse == rb_hash_lookup2(opts, sym_exception, Qundef)) { + if (rsock_opt_false_p(opts, sym_exception)) { return INT2FIX(0); } } |