summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-28 05:15:54 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-28 05:15:54 +0000
commit09f27873ed653bd4afb5538b669e2362f3b1bf6e (patch)
tree1dab78cb5c936ea9c4ee349e7415617e96371c8a
parent8a7da58c0fe28af09ce0631d6ada79e47cc7b98f (diff)
* lib/net/protocol.rb: Add OpenTimeout subclass of Timeout::Error
* lib/net/pop.rb: Modernize Timeout usage. Patch by Eric Wong. Use Net::OpenTimeout instead of Timeout::Error. [Bug #5765] * lib/net/http.rb: ditto * lib/net/smtp.rb: ditto * lib/net/telnet.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog18
-rw-r--r--lib/net/http.rb9
-rw-r--r--lib/net/pop.rb4
-rw-r--r--lib/net/protocol.rb1
-rw-r--r--lib/net/smtp.rb4
-rw-r--r--lib/net/telnet.rb11
-rw-r--r--test/net/http/test_https.rb2
7 files changed, 34 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 67e31ac1e9..2156986f55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+Tue Feb 28 14:15:29 2012 Eric Hodel <drbrain@segment7.net>
+
+ * lib/net/protocol.rb: Add OpenTimeout subclass of Timeout::Error
+ * lib/net/pop.rb: Modernize Timeout usage. Patch by Eric Wong.
+ Use Net::OpenTimeout instead of Timeout::Error. [Bug #5765]
+ * lib/net/http.rb: ditto
+ * lib/net/smtp.rb: ditto
+ * lib/net/telnet.rb: ditto
+
+Tue Feb 28 14:06:36 2012 Eric Hodel <drbrain@segment7.net>
+
+ * lib/net/protocol.rb: Add OpenTimeout subclass of Timeout::Error
+ * lib/net/pop.rb: Modernize Timeout usage. Patch by Eric Wong.
+ Use Net::OpenTimeout instead of Timeout::Error. [Bug #5765]
+ * lib/net/http.rb: ditto
+ * lib/net/smtp.rb: ditto
+ * lib/net/telnet.rb: ditto
+
Tue Feb 28 13:51:12 2012 Eric Hodel <drbrain@segment7.net>
* lib/net/http.rb: Retry HTTP requests for additional network errors.
diff --git a/lib/net/http.rb b/lib/net/http.rb
index d6182d9052..65816f52e8 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -360,9 +360,6 @@ module Net #:nodoc:
#
class HTTP < Protocol
- class OpenTimeout < Timeout::Error
- end
-
# :stopdoc:
Revision = %q$Revision$.split[1]
HTTPVersion = '1.1'
@@ -791,7 +788,7 @@ module Net #:nodoc:
def connect
D "opening connection to #{conn_address()}..."
- s = timeout(@open_timeout, OpenTimeout) {
+ s = Timeout.timeout(@open_timeout, Net::OpenTimeout) {
TCPSocket.open(conn_address(), conn_port())
}
D "opened"
@@ -829,7 +826,7 @@ module Net #:nodoc:
end
# Server Name Indication (SNI) RFC 3546
s.hostname = @address if s.respond_to? :hostname=
- timeout(@open_timeout, OpenTimeout) { s.connect }
+ Timeout.timeout(@open_timeout, Net::OpenTimeout) { s.connect }
if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
s.post_connection_check(@address)
end
@@ -1363,7 +1360,7 @@ module Net #:nodoc:
rescue IOError, EOFError,
Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE,
OpenSSL::SSL::SSLError, Timeout::Error => exception
- raise if OpenTimeout === exception
+ raise if Net::OpenTimeout === exception
if count == 0 && IDEMPOTENT_METHODS_.include?(req.method)
count += 1
diff --git a/lib/net/pop.rb b/lib/net/pop.rb
index be1eed1297..c015338ced 100644
--- a/lib/net/pop.rb
+++ b/lib/net/pop.rb
@@ -542,7 +542,9 @@ module Net
# internal method for Net::POP3.start
def do_start(account, password) # :nodoc:
- s = timeout(@open_timeout) { TCPSocket.open(@address, port) }
+ s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
+ TCPSocket.open(@address, port)
+ end
if use_ssl?
raise 'openssl library not installed' unless defined?(OpenSSL)
context = OpenSSL::SSL::SSLContext.new
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index ab0e70e609..0a54536407 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -44,6 +44,7 @@ module Net # :nodoc:
class ProtoCommandError < ProtocolError; end
class ProtoRetriableError < ProtocolError; end
ProtocRetryError = ProtoRetriableError
+ class OpenTimeout < Timeout::Error; end
class BufferedIO #:nodoc: internal use only
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index eaa010115f..2d4c0eae6d 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -546,7 +546,9 @@ module Net
check_auth_method(authtype || DEFAULT_AUTH_TYPE)
check_auth_args user, secret
end
- s = timeout(@open_timeout) { tcp_socket(@address, @port) }
+ 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)
check_response critical { recv_response() }
diff --git a/lib/net/telnet.rb b/lib/net/telnet.rb
index fe463c63dc..25fbac2728 100644
--- a/lib/net/telnet.rb
+++ b/lib/net/telnet.rb
@@ -9,8 +9,7 @@
# For documentation, see Net::Telnet.
#
-require "socket"
-require "timeout"
+require "net/protocol"
require "English"
module Net
@@ -347,12 +346,12 @@ module Net
if @options["Timeout"] == false
@sock = TCPSocket.open(@options["Host"], @options["Port"])
else
- timeout(@options["Timeout"]) do
+ Timeout.timeout(@options["Timeout"], Net::OpenTimeout) do
@sock = TCPSocket.open(@options["Host"], @options["Port"])
end
end
- rescue TimeoutError
- raise TimeoutError, "timed out while opening a connection to the host"
+ rescue Net::OpenTimeout
+ raise Net::OpenTimeout, "timed out while opening a connection to the host"
rescue
@log.write($ERROR_INFO.to_s + "\n") if @options.has_key?("Output_log")
@dumplog.log_dump('#', $ERROR_INFO.to_s + "\n") if @options.has_key?("Dump_log")
@@ -508,7 +507,7 @@ module Net
# into a regular expression. Used only if Match and
# Prompt are not specified.
# Timeout:: the number of seconds to wait for data from the host
- # before raising a TimeoutError. If set to false,
+ # before raising a Timeout::Error. If set to false,
# no timeout will occur. If not specified, the
# Timeout option value specified when this instance
# was created will be used, or, failing that, the
diff --git a/test/net/http/test_https.rb b/test/net/http/test_https.rb
index a911160fa0..49e5ecbeb0 100644
--- a/test/net/http/test_https.rb
+++ b/test/net/http/test_https.rb
@@ -119,7 +119,7 @@ class TestNetHTTPS < Test::Unit::TestCase
conn.open_timeout = 0.01
th = Thread.new do
- assert_raise(Net::HTTP::OpenTimeout) {
+ assert_raise(Net::OpenTimeout) {
conn.get('/')
}
end