diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-29 02:24:18 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-29 02:24:18 +0000 |
commit | d8bbb5eda83f92bfa6045bc5165f7578e524a2f5 (patch) | |
tree | 77defb6e5c5cc03585e032b243a0c8513fd671eb /ext/socket/init.c | |
parent | 1dd4c763c06532cc520013275bd976f477ec3b85 (diff) | |
download | ruby-d8bbb5eda83f92bfa6045bc5165f7578e524a2f5.tar.gz |
socket: avoid redundant fcntl on Linux
* ext/socket/ancdata.c (bsock_sendmsg_internal,
bsock_recvmsg_internal):
avoid redundant fcntl on Linux
[ruby-core:69154] [Feature #11145]
* ext/socket/init.c (rsock_s_recvfrom_nonblock): ditto
* ext/socket/rubysocket.h (MSG_DONTWAIT_RELIABLE): new macro
MSG_DONTWAIT is enough to force non-blocking I/O under Linux,
so avoid changing the state of a socket. This will allow certain
threads to do a non-destructive non-blocking "peek" while others
block (without relying on an extra ppoll syscall).
We shall be conservative about enabling this feature since some
OSes may have incomplete support for MSG_DONTWAIT. I shall
defer to a FreeBSD expert to enable that for FreeBSD.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/init.c')
-rw-r--r-- | ext/socket/init.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c index 317dd67479..455652d082 100644 --- a/ext/socket/init.c +++ b/ext/socket/init.c @@ -211,7 +211,10 @@ rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type str = rb_tainted_str_new(0, buflen); rb_io_check_closed(fptr); - rb_io_set_nonblock(fptr); + + if (!MSG_DONTWAIT_RELIABLE) + rb_io_set_nonblock(fptr); + len0 = alen; slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, &buf.addr, &alen); if (slen != -1 && len0 < alen) |