From 4148b8846521f6cdbe35bc79a63e0512f65fe346 Mon Sep 17 00:00:00 2001 From: normal Date: Sun, 17 May 2015 05:56:07 +0000 Subject: 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 --- test/socket/test_nonblock.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/socket') 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 -- cgit v1.2.3