class HTTP::Timeout::PerOperation

Constants

CONNECT_TIMEOUT
READ_TIMEOUT
WRITE_TIMEOUT

Attributes

connect_timeout[R]
read_timeout[R]
write_timeout[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method HTTP::Timeout::Null.new
# File lib/http/timeout/per_operation.rb, line 15
def initialize(*args)
  super

  @read_timeout = options.fetch(:read_timeout, READ_TIMEOUT)
  @write_timeout = options.fetch(:write_timeout, WRITE_TIMEOUT)
  @connect_timeout = options.fetch(:connect_timeout, CONNECT_TIMEOUT)
end

Public Instance Methods

connect(socket_class, host, port, nodelay = false) click to toggle source
# File lib/http/timeout/per_operation.rb, line 23
def connect(socket_class, host, port, nodelay = false)
  ::Timeout.timeout(connect_timeout, TimeoutError) do
    @socket = socket_class.open(host, port)
    @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if nodelay
  end
end
connect_ssl() click to toggle source
# File lib/http/timeout/per_operation.rb, line 30
def connect_ssl
  rescue_readable(@connect_timeout) do
    rescue_writable(@connect_timeout) do
      @socket.connect_nonblock
    end
  end
end
readpartial(size) click to toggle source

Read data from the socket

# File lib/http/timeout/per_operation.rb, line 41
def readpartial(size)
  rescue_readable do
    @socket.read_nonblock(size)
  end
rescue EOFError
  :eof
end
write(data) click to toggle source

Write data to the socket

# File lib/http/timeout/per_operation.rb, line 50
def write(data)
  rescue_writable do
    @socket.write_nonblock(data)
  end
rescue EOFError
  :eof
end