Issue #11024 has been reported by Eric Wong.

----------------------------------------
Feature #11024: [PATCH] connect_nonblock supports "exception: false"
https://bugs.ruby-lang.org/issues/11024

* 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:

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.#{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/