ruby-changes:54445
From: glass <ko1@a...>
Date: Mon, 31 Dec 2018 10:09:34 +0900 (JST)
Subject: [ruby-changes:54445] glass:r66660 (trunk): Revert "lib/net/http.rb: use connect_timeout instead of Timeout"
glass 2018-12-31 10:09:30 +0900 (Mon, 31 Dec 2018) New Revision: 66660 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66660 Log: Revert "lib/net/http.rb: use connect_timeout instead of Timeout" This reverts commit 69a1db96fe63ff3071cb3d272675a1d0470aab01. getaddrinfo(3) doesn't support timeout. Modified files: trunk/lib/net/ftp.rb trunk/lib/net/http.rb trunk/lib/net/pop.rb trunk/lib/net/smtp.rb Index: lib/net/smtp.rb =================================================================== --- lib/net/smtp.rb (revision 66659) +++ lib/net/smtp.rb (revision 66660) @@ -545,10 +545,8 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/smtp.rb#L545 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) Index: lib/net/ftp.rb =================================================================== --- lib/net/ftp.rb (revision 66659) +++ lib/net/ftp.rb (revision 66660) @@ -329,18 +329,14 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L329 # 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 Index: lib/net/pop.rb =================================================================== --- lib/net/pop.rb (revision 66659) +++ lib/net/pop.rb (revision 66660) @@ -541,10 +541,8 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/pop.rb#L541 # 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) Index: lib/net/http.rb =================================================================== --- lib/net/http.rb (revision 66659) +++ lib/net/http.rb (revision 66660) @@ -942,15 +942,14 @@ module Net #:nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L942 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? -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/