OpenBSD's limit is less than 128.
* test/socket/test_nonblock: use smaller buffer for sendmsg
Patch-by: Jeremy Evans <code@jeremyevans.net>
[ruby-core:70016] [Bug #11364]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* time: Object#timeout has been deprecated a long time ago, use
Timeout.timeout.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This reduces GC overhead and makes the API more consistent
with IO#read and IO#read_nonblock.
* ext/socket/basicsocket.c (bsock_recv): document outbuf
* ext/socket/unixsocket.c (unix_recvfrom): ditto
* ext/socket/init.c (rsock_strbuf, recvfrom_locktmp): new functions
(rsock_s_recvfrom): support destination buffer as 3rd arg
(rsock_s_recvfrom_nonblock): ditto
* string.c (rb_str_locktmp_ensure): export for internal ext
* test/socket/test_nonblock.rb: test recv_nonblock
* test/socket/test_unix.rb: test recv
[ruby-core:69543] [Feature #11242]
Benchmark results:
user system total real
alloc 0.130000 0.280000 0.410000 ( 0.420656)
extbuf 0.100000 0.220000 0.320000 ( 0.318708)
-------------------8<--------------------
require 'socket'
require 'benchmark'
nr = 100000
msg = ' ' * 16384
size = msg.bytesize
buf = ' ' * size
UNIXSocket.pair(:DGRAM) do |a, b|
Benchmark.bmbm do |x|
x.report('alloc') do
nr.times do
b.send(msg, 0)
a.recv(size, 0)
end
end
x.report('extbuf') do
nr.times do
b.send(msg, 0)
a.recv(size, 0, buf)
end
end
end
end
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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
We want to test the IO::WaitWritable behavior, so silently
discarding Errno::EMSGSIZE prevents the test from being
effective.
[ruby-core:69466]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
sendmsg_nonblock was not tested on any of my systems due to the
common 64K limit. I also don't believe UDP sockets are at all
a useful candidate for sendmsg_nonblock testing since they
should never block on sending.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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
* ext/socket/socket.c (sock_connect_nonblock): do not raise EISCONN
[ruby-core:68926] [Feature #11072]
* test/socket/test_nonblock.rb: check non-EISCONN on 2nd connect
This is to reduce exceptions for code which issues a
(IMHO, unnecessary) second connect() syscall.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This is for consistency with accept_nonblock arguments and gives a
minor speedup from avoiding exceptions.
[ruby-core:68838] [Feature #11024]
* ext/openssl/ossl_ssl.c (ossl_ssl_connect_nonblock):
support `exception: false'
* (get_no_exception): move function location
* ext/socket/socket.c (sock_connect_nonblock):
support `exception: false'
* test/openssl/test_pair.rb (test_connect_accept_nonblock_no_exception):
test `exception: false' on connect,
rename from `test_accept_nonblock_no_exception'
* test/socket/test_nonblock.rb (test_connect_nonblock_no_exception):
new test
Benchmark results:
default 0.050000 0.100000 0.150000 ( 0.151307)
exception: false 0.030000 0.080000 0.110000 ( 0.108840)
----------------------------8<-----------------------
require 'socket'
require 'benchmark'
require 'io/wait'
require 'tmpdir'
host = '127.0.0.1'
serv = TCPServer.new(host, 0) # UNIX sockets may not hit EINPROGRESS
nr = 5000 # few iterations to avoid running out of ports
addr = serv.getsockname
pid = fork do
begin
serv.accept.close
rescue => e
warn "#$$: #{e.message} (#{e.class})"
end while true
end
at_exit { Process.kill(:TERM, pid) }
serv.close
Benchmark.bmbm do |x|
x.report("default") do
nr.times do
s = Socket.new(:INET, :STREAM)
s.setsockopt(:SOL_SOCKET, :SO_REUSEADDR, 1)
begin
s.connect_nonblock(addr)
rescue IO::WaitWritable
s.wait_writable
end
s.close
end
end
x.report("exception: false") do
nr.times do
s = Socket.new(:INET, :STREAM)
s.setsockopt(:SOL_SOCKET, :SO_REUSEADDR, 1)
case s.connect_nonblock(addr, exception: false)
when :wait_writable
s.wait_writable
end
s.close
end
end
end
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This is analogous to functionality found in IO#read_nonblock and
IO#wait_nonblock. Raising exceptions for common failures on
non-blocking servers is expensive and makes $DEBUG too noisy.
Benchmark results:
user system total real
default 2.790000 0.870000 3.660000 ( 3.671597)
exception: false 1.120000 0.800000 1.920000 ( 1.922032)
exception: false (cached arg) 0.820000 0.770000 1.590000 ( 1.589267)
--------------------- benchmark script ------------------------
require 'socket'
require 'benchmark'
require 'tmpdir'
nr = 1000000
Dir.mktmpdir('nb_bench') do |path|
sock_path = "#{path}/test.sock"
s = UNIXServer.new(sock_path)
Benchmark.bmbm do |x|
x.report("default") do
nr.times do
begin
s.accept_nonblock
rescue IO::WaitReadable
end
end
end
x.report("exception: false") do
nr.times do
begin
s.accept_nonblock(exception: false)
rescue IO::WaitReadable
abort "should not raise"
end
end
end
x.report("exception: false (cached arg)") do
arg = { exception: false }
nr.times do
begin
s.accept_nonblock(arg)
rescue IO::WaitReadable
abort "should not raise"
end
end
end
end
end
* ext/socket/init.c (rsock_s_accept_nonblock):
support exception: false
[ruby-core:66385] [Feature #10532]
* ext/socket/init.c (rsock_init_socket_init): define new symbols
* ext/socket/rubysocket.h: adjust prototype
* ext/socket/socket.c (sock_accept_nonblock): support exception: false
* ext/openssl/ossl_ssl.c (ossl_ssl_accept_nonblock): ditto
* ext/socket/socket.c (Init_socket): adjust accept_nonblock definition
* ext/openssl/ossl_ssl.c (Init_ossl_ssl): ditto
* ext/socket/tcpserver.c (rsock_init_tcpserver): ditto
* ext/socket/unixserver.c (rsock_init_unixserver): ditto
* ext/socket/tcpserver.c (tcp_accept_nonblock): adjust
rsock_s_accept_nonblock call
* ext/socket/unixserver.c (unix_accept_nonblock): ditto
* ext/openssl/ossl_ssl.c (ossl_start_ssl): support no_exception
* ext/openssl/ossl_ssl.c (ossl_ssl_connect): adjust ossl_start_ssl call
* ext/openssl/ossl_ssl.c (ossl_ssl_connect_nonblock): ditto
* ext/openssl/ossl_ssl.c (ossl_ssl_accept): ditto
* test/socket/test_nonblock.rb (test_accept_nonblock): test for
"exception :false"
* test/socket/test_tcp.rb (test_accept_nonblock): new test
* test/socket/test_unix.rb (test_accept_nonblock): ditto
* test/openssl/test_pair.rb (test_accept_nonblock_no_exception): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
controls_num to raise NotImplementedError appropriately.
(bsock_recvmsg_internal): Raise NotImplementedError if
:scm_rights=>true is given on platforms which don't have
4.4BSD style control message.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is a result of hacks at the CodeFest Akihabara 2006 hosted by FSIJ.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
BasicSocket#recv_nonblock.
(udp_recvfrom_nonblock): renamed from ip_recvfrom_nonblock.
IPSocket#recvfrom_nonblock is moved to UDPSocket#recvfrom_nonblock.
(unix_recvfrom_nonblock): removed.
UNIXSocket#recvfrom_nonblock is removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10403 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
too. (tested on NetBSD 3.0)
(s_recvfrom_nonblock): extracted from sock_recvfrom_nonblock.
(sock_recvfrom_nonblock): use s_recvfrom_nonblock.
(ip_recvfrom_nonblock): new method: IPSocket#recvfrom_nonblock
(unix_recvfrom_nonblock): new method: UNIXSocket#recvfrom_nonblock
(s_accept_nonblock): extracted from sock_accept_nonblock.
(sock_accept_nonblock): use s_accept_nonblock.
(tcp_accept_nonblock): new method: TCPServer#accept_nonblock
(unix_accept_nonblock): new method: UNIXServer#accept_nonblock
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e