lib/httpx/io/tcp.rb in httpx-0.11.3 vs lib/httpx/io/tcp.rb in httpx-0.12.0
- old
+ new
@@ -5,21 +5,22 @@
module HTTPX
class TCP
include Loggable
- attr_reader :ip, :port, :addresses, :state
+ attr_reader :ip, :port, :addresses, :state, :interests
alias_method :host, :ip
def initialize(origin, addresses, options)
@state = :idle
@hostname = origin.host
@addresses = addresses
@options = Options.new(options)
@fallback_protocol = @options.fallback_protocol
@port = origin.port
+ @interests = :w
if @options.io
@io = case @options.io
when Hash
@options.io[origin.authority]
else
@@ -37,14 +38,10 @@
@ip = @addresses[@ip_index]
end
@io ||= build_socket
end
- def interests
- :w
- end
-
def to_io
@io.to_io
end
def protocol
@@ -60,23 +57,27 @@
@io = build_socket
end
@io.connect_nonblock(Socket.sockaddr_in(@port, @ip.to_s))
rescue Errno::EISCONN
end
+ @interests = :w
+
transition(:connected)
rescue Errno::EHOSTUNREACH => e
raise e if @ip_index <= 0
@ip_index -= 1
retry
rescue Errno::ETIMEDOUT => e
- raise ConnectTimeoutError, e.message if @ip_index <= 0
+ raise ConnectTimeoutError.new(@options.timeout.connect_timeout, e.message) if @ip_index <= 0
@ip_index -= 1
retry
rescue Errno::EINPROGRESS,
- Errno::EALREADY,
- ::IO::WaitReadable
+ Errno::EALREADY
+ @interests = :w
+ rescue ::IO::WaitReadable
+ @interests = :r
end
if RUBY_VERSION < "2.3"
# :nocov:
def read(size, buffer)