diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-17 05:56:07 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-17 05:56:07 +0000 |
commit | 8ff35b816ae3b44a6f1ee8e8c07e0ab833510b94 (patch) | |
tree | fe6e88a33e929ca7f3f73d12ff7049aa5bd16487 /test/socket/test_nonblock.rb | |
parent | a9ca74cd70bfee429544a7346749abcb2103e0f3 (diff) |
ext/socket/init.c: use SOCK_NONBLOCK if available
This saves a system call by allowing us to use SOCK_NONBLOCK in
Linux when accept4 is available.
Note: I do not agree accept_nonblock should always make accepted
sockets non-blocking, and will propose a future API to allow
controlling whether accepted sockets are non-blocking or not
regardless of how they were created.
* ext/socket/init.c (cloexec_accept): support nonblock flag and
use SOCK_NONBLOCK if possible
* ext/socket/init.c (rsock_s_accept_nonblock): update cloexec_accept call
* ext/socket/init.c (accept_blocking): ditto for blocking
* test/socket/test_nonblock.rb: check nonblock? on accepted socket
[Feature #11138]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/socket/test_nonblock.rb')
-rw-r--r-- | test/socket/test_nonblock.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/test/socket/test_nonblock.rb b/test/socket/test_nonblock.rb index 98de00eed9..526825269e 100644 --- a/test/socket/test_nonblock.rb +++ b/test/socket/test_nonblock.rb @@ -1,5 +1,6 @@ begin require "socket" + require "io/nonblock" rescue LoadError end @@ -24,6 +25,9 @@ class TestSocketNonblock < Test::Unit::TestCase s, sockaddr = serv.accept_nonblock end assert_equal(Socket.unpack_sockaddr_in(c.getsockname), Socket.unpack_sockaddr_in(sockaddr)) + if s.respond_to?(:nonblock?) + assert s.nonblock?, 'accepted socket is non-blocking' + end ensure serv.close if serv c.close if c |