lib/httpx/io/tcp.rb in httpx-0.6.3 vs lib/httpx/io/tcp.rb in httpx-0.6.4

- old
+ new

@@ -39,14 +39,10 @@ @ip = @addresses[@ip_index] end @io ||= build_socket end - def scheme - "http" - end - def to_io @io.to_io end def protocol @@ -68,16 +64,22 @@ rescue Errno::EHOSTUNREACH => e raise e if @ip_index <= 0 @ip_index -= 1 retry + rescue Errno::ETIMEDOUT => e + raise ConnectTimeout, e.message if @ip_index <= 0 + + @ip_index -= 1 + retry rescue Errno::EINPROGRESS, Errno::EALREADY, ::IO::WaitReadable end if RUBY_VERSION < "2.3" + # :nocov: def read(size, buffer) @io.read_nonblock(size, buffer) buffer.bytesize rescue ::IO::WaitReadable 0 @@ -92,10 +94,11 @@ rescue ::IO::WaitWritable 0 rescue EOFError nil end + # :nocov: else def read(size, buffer) ret = @io.read_nonblock(size, buffer, exception: false) return 0 if ret == :wait_readable return if ret.nil? @@ -129,14 +132,16 @@ def closed? @state == :idle || @state == :closed end + # :nocov: def inspect id = @io.closed? ? "closed" : @io.fileno "#<TCP(fd: #{id}): #{@ip}:#{@port} (state: #{@state})>" end + # :nocov: private def build_socket Socket.new(@ip.family, :STREAM, 0) @@ -152,12 +157,10 @@ end do_transition(nextstate) end def do_transition(nextstate) - log(level: 1) do - log_transition_state(nextstate) - end + log(level: 1) { log_transition_state(nextstate) } @state = nextstate end def log_transition_state(nextstate) case nextstate