mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
91af3e00d1
commit
b9a91334c5
8 changed files with 113 additions and 19 deletions
|
@ -194,8 +194,7 @@ udp_send(int argc, VALUE *argv, VALUE sock)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* udpsocket.recvfrom_nonblock(maxlen) => [mesg, sender_inet_addr]
|
||||
* udpsocket.recvfrom_nonblock(maxlen, flags) => [mesg, sender_inet_addr]
|
||||
* udpsocket.recvfrom_nonblock(maxlen [, flags [, options]) => [mesg, sender_inet_addr]
|
||||
*
|
||||
* Receives up to _maxlen_ bytes from +udpsocket+ using recvfrom(2) after
|
||||
* O_NONBLOCK is set for the underlying file descriptor.
|
||||
|
@ -211,6 +210,7 @@ udp_send(int argc, VALUE *argv, VALUE sock)
|
|||
* === Parameters
|
||||
* * +maxlen+ - the number of bytes to receive from the socket
|
||||
* * +flags+ - zero or more of the +MSG_+ options
|
||||
* * +options+ - keyword hash, supporting `exception: false`
|
||||
*
|
||||
* === Example
|
||||
* require 'socket'
|
||||
|
@ -238,6 +238,10 @@ udp_send(int argc, VALUE *argv, VALUE sock)
|
|||
* it is extended by IO::WaitReadable.
|
||||
* So IO::WaitReadable can be used to rescue the exceptions for retrying recvfrom_nonblock.
|
||||
*
|
||||
* By specifying `exception: false`, the options hash allows you to indicate
|
||||
* that recvmsg_nonblock should not raise an IO::WaitWritable exception, but
|
||||
* return the symbol :wait_writable instead.
|
||||
*
|
||||
* === See
|
||||
* * Socket#recvfrom
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue