# 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
# 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
# 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
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 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