Project

General

Profile

Feature #16381 ยป resolv.patch

kirs (Kir Shatrov), 11/29/2019 01:24 PM

View differences:

lib/net/http.rb
# Net::OpenTimeout exception. The default value is 60 seconds.
attr_accessor :open_timeout
# Specify the DNS name resolution timeout in seconds. If the name
# cannot be resolved in this many seconds, it raises a
# SocketError exception. The default value is set by operation system.
attr_accessor :resolv_timeout
# Number of seconds to wait for one block to be read (via one read(2)
# call). Any number may be used, including Floats for fractional
# seconds. If the HTTP object cannot read data in this many seconds,
......
end
D "opening connection to #{conn_address}:#{conn_port}..."
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 = begin
Socket.tcp(conn_address, conn_port, @local_host, @local_port, connect_timeout: @open_timeout, resolv_timeout: @resolv_timeout)
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?
spec/ruby/library/net/http/http/resolv_timeout_spec.rb
require_relative '../../../../spec_helper'
require 'net/http'
describe "Net::HTTP#resolv_timeout" do
it "returns the seconds to wait until reading one block" do
net = Net::HTTP.new("localhost")
net.resolv_timeout.should eql(nil)
net.resolv_timeout = 10
net.resolv_timeout.should eql(10)
end
end
describe "Net::HTTP#resolv_timeout=" do
it "sets the seconds to wait till the connection is open" do
net = Net::HTTP.new("localhost")
net.resolv_timeout = 10
net.resolv_timeout.should eql(10)
end
it "returns the newly set value" do
net = Net::HTTP.new("localhost")
(net.resolv_timeout = 10).should eql(10)
end
end
spec/ruby/library/socket/socket/tcp_spec.rb
connection.close
end
end
it 'accepts tcp timeout' do
@client = Socket.tcp(@host, @port, resolv_timeout: 1)
@client.write('hello')
@client.close
end
end
    (1-1/1)