class HTTP::Timeout::Null

Attributes

options[R]
socket[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/http/timeout/null.rb, line 13
def initialize(options = {})
  @options = options
end

Public Instance Methods

<<(data)
Alias for: write
connect(socket_class, host, port, nodelay = false) click to toggle source

Connects to a socket

# File lib/http/timeout/null.rb, line 18
def connect(socket_class, host, port, nodelay = false)
  @socket = socket_class.open(host, port)
  @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if nodelay
end
connect_ssl() click to toggle source

Starts a SSL connection on a socket

# File lib/http/timeout/null.rb, line 24
def connect_ssl
  @socket.connect
end
readpartial(size) click to toggle source

Read from the socket

# File lib/http/timeout/null.rb, line 42
def readpartial(size)
  @socket.readpartial(size)
rescue EOFError
  :eof
end
start_tls(host, ssl_socket_class, ssl_context) click to toggle source

Configures the SSL connection and starts the connection

# File lib/http/timeout/null.rb, line 29
def start_tls(host, ssl_socket_class, ssl_context)
  @socket = ssl_socket_class.new(socket, ssl_context)
  @socket.hostname = host if @socket.respond_to? :hostname=
  @socket.sync_close = true if @socket.respond_to? :sync_close=

  connect_ssl

  return unless ssl_context.verify_mode == OpenSSL::SSL::VERIFY_PEER

  @socket.post_connection_check(host)
end
write(data) click to toggle source

Write to the socket

# File lib/http/timeout/null.rb, line 49
def write(data)
  @socket.write(data)
end
Also aliased as: <<

Private Instance Methods

rescue_readable() { || ... } click to toggle source

Retry reading

# File lib/http/timeout/null.rb, line 57
def rescue_readable
  yield
rescue IO::WaitReadable
  retry if @socket.to_io.wait_readable(read_timeout)
  raise TimeoutError, "Read timed out after #{read_timeout} seconds"
end
rescue_writable() { || ... } click to toggle source

Retry writing

# File lib/http/timeout/null.rb, line 65
def rescue_writable
  yield
rescue IO::WaitWritable
  retry if @socket.to_io.wait_writable(write_timeout)
  raise TimeoutError, "Write timed out after #{write_timeout} seconds"
end