From: nobu@... Date: 2015-04-11T02:13:48+00:00 Subject: [ruby-core:68838] [Ruby trunk - Feature #11024] [PATCH] connect_nonblock supports "exception: false" Issue #11024 has been updated by Nobuyoshi Nakada. I see, no problems then. As a side note, the benchmark failed unless `host` is "127.0.0.1" on OSX. ---------------------------------------- Feature #11024: [PATCH] connect_nonblock supports "exception: false" https://bugs.ruby-lang.org/issues/11024#change-52101 * Author: Eric Wong * Status: Open * Priority: Normal * Assignee: Nobuyoshi Nakada ---------------------------------------- This is for consistency with accept_nonblock arguments and gives a minor speedup from avoiding exceptions: Results: | user | system | total | real -----------------|----------:|----------:|----------:|-----------: default | 0.050000 | 0.100000 | 0.150000 |( 0.151307) exception: false | 0.030000 | 0.080000 | 0.110000 |( 0.108840) --------------------------------------------------- ~~~ruby require 'socket' require 'benchmark' require 'io/wait' require 'tmpdir' host = "127.#{rand 255}.#{rand 255}.#{rand(254) + 1}" serv = TCPServer.new(host, 0) nr = 5000 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 ~~~ ---Files-------------------------------- 0001-connect_nonblock-supports-exception-false.patch (9.14 KB) -- https://bugs.ruby-lang.org/