lib/httpx/io/tcp.rb in httpx-0.7.0 vs lib/httpx/io/tcp.rb in httpx-0.8.0
- old
+ new
@@ -9,10 +9,12 @@
attr_reader :ip, :port
attr_reader :addresses
+ attr_reader :state
+
alias_method :host, :ip
def initialize(origin, addresses, options)
@state = :idle
@hostname = origin.host
@@ -39,10 +41,14 @@
@ip = @addresses[@ip_index]
end
@io ||= build_socket
end
+ def interests
+ :w
+ end
+
def to_io
@io.to_io
end
def protocol
@@ -65,11 +71,11 @@
raise e if @ip_index <= 0
@ip_index -= 1
retry
rescue Errno::ETIMEDOUT => e
- raise ConnectTimeout, e.message if @ip_index <= 0
+ raise ConnectTimeoutError, e.message if @ip_index <= 0
@ip_index -= 1
retry
rescue Errno::EINPROGRESS,
Errno::EALREADY,
@@ -80,10 +86,11 @@
# :nocov:
def read(size, buffer)
@io.read_nonblock(size, buffer)
buffer.bytesize
rescue ::IO::WaitReadable
+ buffer.clear
0
rescue EOFError
nil
end
@@ -98,10 +105,13 @@
end
# :nocov:
else
def read(size, buffer)
ret = @io.read_nonblock(size, buffer, exception: false)
- return 0 if ret == :wait_readable
+ if ret == :wait_readable
+ buffer.clear
+ return 0
+ end
return if ret.nil?
buffer.bytesize
end