[ruby/net-ftp] Replace Timeout.timeout with socket timeout
Timeout.timeout is inefficient since it spins up a new thread for each invocation, use Socket.tcp's connect_timeout option instead when we aren't using SOCKS (we can't replace Timeout.timeout for SOCKS yet since SOCKSSocket doesn't have a connect_timeout option). https://github.com/ruby/net-ftp/commit/d65910132f
This commit is contained in:
parent
fb819d9331
commit
a86c6cb34d
@ -330,14 +330,19 @@ module Net
|
||||
# SOCKS_SERVER, then a SOCKSSocket is returned, else a Socket is
|
||||
# returned.
|
||||
def open_socket(host, port) # :nodoc:
|
||||
return Timeout.timeout(@open_timeout, OpenTimeout) {
|
||||
if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
|
||||
@passive = true
|
||||
if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
|
||||
@passive = true
|
||||
Timeout.timeout(@open_timeout, OpenTimeout) do
|
||||
SOCKSSocket.open(host, port)
|
||||
else
|
||||
Socket.tcp(host, port)
|
||||
end
|
||||
}
|
||||
else
|
||||
begin
|
||||
Socket.tcp host, port, nil, nil, connect_timeout: @open_timeout
|
||||
rescue Errno::ETIMEDOUT #raise Net:OpenTimeout instead for compatibility with previous versions
|
||||
raise Net::OpenTimeout, "Timeout to open TCP connection to "\
|
||||
"#{host}:#{port} (exceeds #{@open_timeout} seconds)"
|
||||
end
|
||||
end
|
||||
end
|
||||
private :open_socket
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user