mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
lib/net/http.rb: use connect_timeout instead of Timeout
lib/net/pop.rb: ditto lib/net/ftp.rb: ditto lib/net/smtp.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f964fd3fa5
commit
69a1db96fe
4 changed files with 27 additions and 18 deletions
|
@ -329,14 +329,18 @@ module Net
|
||||||
# SOCKS_SERVER, then a SOCKSSocket is returned, else a Socket is
|
# SOCKS_SERVER, then a SOCKSSocket is returned, else a Socket is
|
||||||
# returned.
|
# returned.
|
||||||
def open_socket(host, port) # :nodoc:
|
def open_socket(host, port) # :nodoc:
|
||||||
return Timeout.timeout(@open_timeout, OpenTimeout) {
|
|
||||||
if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
|
if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
|
||||||
@passive = true
|
@passive = true
|
||||||
|
return Timeout.timeout(@open_timeout, OpenTimeout) {
|
||||||
SOCKSSocket.open(host, port)
|
SOCKSSocket.open(host, port)
|
||||||
else
|
|
||||||
Socket.tcp(host, port)
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
return Socket.tcp(host, port, connect_timeout: @open_timeout)
|
||||||
|
rescue Errno::ETIMEDOUT
|
||||||
|
raise OpenTimeout, "execution expired"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
private :open_socket
|
private :open_socket
|
||||||
|
|
||||||
|
|
|
@ -942,14 +942,15 @@ module Net #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
D "opening connection to #{conn_address}:#{conn_port}..."
|
D "opening connection to #{conn_address}:#{conn_port}..."
|
||||||
s = Timeout.timeout(@open_timeout, Net::OpenTimeout) {
|
|
||||||
begin
|
begin
|
||||||
TCPSocket.open(conn_address, conn_port, @local_host, @local_port)
|
s = Socket.tcp(conn_address, conn_port, @local_host, @local_port, connect_timeout: @open_timeout)
|
||||||
|
rescue Errno::ETIMEDOUT => e
|
||||||
|
raise Net::OpenTimeout, "Failed to open TCP connection to " +
|
||||||
|
"#{conn_address}:#{conn_port} (#{e.message})"
|
||||||
rescue => e
|
rescue => e
|
||||||
raise e, "Failed to open TCP connection to " +
|
raise e, "Failed to open TCP connection to " +
|
||||||
"#{conn_address}:#{conn_port} (#{e.message})"
|
"#{conn_address}:#{conn_port} (#{e.message})"
|
||||||
end
|
end
|
||||||
}
|
|
||||||
s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
||||||
D "opened"
|
D "opened"
|
||||||
if use_ssl?
|
if use_ssl?
|
||||||
|
|
|
@ -541,8 +541,10 @@ module Net
|
||||||
|
|
||||||
# internal method for Net::POP3.start
|
# internal method for Net::POP3.start
|
||||||
def do_start(account, password) # :nodoc:
|
def do_start(account, password) # :nodoc:
|
||||||
s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
|
begin
|
||||||
TCPSocket.open(@address, port)
|
s = Socket.tcp(@address, port, connect_timeout: @open_timeout)
|
||||||
|
rescue Errno::ETIMEDOUT
|
||||||
|
raise Net::OpenTimeout, "execution expired"
|
||||||
end
|
end
|
||||||
if use_ssl?
|
if use_ssl?
|
||||||
raise 'openssl library not installed' unless defined?(OpenSSL)
|
raise 'openssl library not installed' unless defined?(OpenSSL)
|
||||||
|
|
|
@ -545,8 +545,10 @@ module Net
|
||||||
check_auth_method(authtype || DEFAULT_AUTH_TYPE)
|
check_auth_method(authtype || DEFAULT_AUTH_TYPE)
|
||||||
check_auth_args user, secret
|
check_auth_args user, secret
|
||||||
end
|
end
|
||||||
s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
|
begin
|
||||||
tcp_socket(@address, @port)
|
s = Socket.tcp(@address, @port, connect_timeout: @open_timeout)
|
||||||
|
rescue Errno::ETIMEDOUT
|
||||||
|
raise Net::OpenTimeout, "execution expired"
|
||||||
end
|
end
|
||||||
logging "Connection opened: #{@address}:#{@port}"
|
logging "Connection opened: #{@address}:#{@port}"
|
||||||
@socket = new_internet_message_io(tls? ? tlsconnect(s) : s)
|
@socket = new_internet_message_io(tls? ? tlsconnect(s) : s)
|
||||||
|
|
Loading…
Reference in a new issue