summaryrefslogtreecommitdiff
path: root/lib/net
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-31 01:09:30 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-31 01:09:30 +0000
commitc5e8627f658c88b2403e7b20637cf25e31feff88 (patch)
tree0f2b153ac4fb185912f23f4ce60c5c2f99f28d0d /lib/net
parent69a1db96fe63ff3071cb3d272675a1d0470aab01 (diff)
Revert "lib/net/http.rb: use connect_timeout instead of Timeout"
This reverts commit 69a1db96fe63ff3071cb3d272675a1d0470aab01. getaddrinfo(3) doesn't support timeout. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/ftp.rb16
-rw-r--r--lib/net/http.rb17
-rw-r--r--lib/net/pop.rb6
-rw-r--r--lib/net/smtp.rb6
4 files changed, 18 insertions, 27 deletions
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index ae0e8d4db1..e68d825dcf 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -329,18 +329,14 @@ module Net
# SOCKS_SERVER, then a SOCKSSocket is returned, else a Socket is
# returned.
def open_socket(host, port) # :nodoc:
- if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
- @passive = true
- return Timeout.timeout(@open_timeout, OpenTimeout) {
+ return Timeout.timeout(@open_timeout, OpenTimeout) {
+ if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
+ @passive = true
SOCKSSocket.open(host, port)
- }
- else
- begin
- return Socket.tcp(host, port, connect_timeout: @open_timeout)
- rescue Errno::ETIMEDOUT
- raise OpenTimeout, "execution expired"
+ else
+ Socket.tcp(host, port)
end
- end
+ }
end
private :open_socket
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 8ba15e4054..31cbb7a866 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -942,15 +942,14 @@ module Net #:nodoc:
end
D "opening connection to #{conn_address}:#{conn_port}..."
- begin
- 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
- raise e, "Failed to open TCP connection to " +
- "#{conn_address}:#{conn_port} (#{e.message})"
- end
+ s = Timeout.timeout(@open_timeout, Net::OpenTimeout) {
+ begin
+ TCPSocket.open(conn_address, conn_port, @local_host, @local_port)
+ rescue => e
+ raise e, "Failed to open TCP connection to " +
+ "#{conn_address}:#{conn_port} (#{e.message})"
+ end
+ }
s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
D "opened"
if use_ssl?
diff --git a/lib/net/pop.rb b/lib/net/pop.rb
index f3009f9926..a6374cd78c 100644
--- a/lib/net/pop.rb
+++ b/lib/net/pop.rb
@@ -541,10 +541,8 @@ module Net
# internal method for Net::POP3.start
def do_start(account, password) # :nodoc:
- begin
- s = Socket.tcp(@address, port, connect_timeout: @open_timeout)
- rescue Errno::ETIMEDOUT
- raise Net::OpenTimeout, "execution expired"
+ s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
+ TCPSocket.open(@address, port)
end
if use_ssl?
raise 'openssl library not installed' unless defined?(OpenSSL)
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index ff205b4e28..86b55d278b 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -545,10 +545,8 @@ module Net
check_auth_method(authtype || DEFAULT_AUTH_TYPE)
check_auth_args user, secret
end
- begin
- s = Socket.tcp(@address, @port, connect_timeout: @open_timeout)
- rescue Errno::ETIMEDOUT
- raise Net::OpenTimeout, "execution expired"
+ s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
+ tcp_socket(@address, @port)
end
logging "Connection opened: #{@address}:#{@port}"
@socket = new_internet_message_io(tls? ? tlsconnect(s) : s)