class H2::Client::TCPSocket

Constants

DEFAULT_TIMEOUT

Public Class Methods

new(addr, port, timeout = DEFAULT_TIMEOUT) click to toggle source

ON_LINUX = !!(RUBY_PLATFORM =~ /linux/)

Calls superclass method
# File lib/h2/client/tcp_socket.rb, line 10
def initialize addr, port, timeout = DEFAULT_TIMEOUT

  # resolve name & pack addr
  family, addr = Socket.getaddrinfo(addr, port, nil, :STREAM, nil, AI_ALL).first.values_at(0,3)
  @_sockaddr = Socket.sockaddr_in port, addr

  super family, SOCK_STREAM

  # allow send before ack
  setsockopt IPPROTO_TCP, TCP_NODELAY, 1

  # cork on linux
  # setsockopt IPPROTO_TCP, TCP_CORK, 1 if ON_LINUX

  handle_wait_writable(timeout){ _connect } if _connect == :wait_writable
end

Public Instance Methods

selector() click to toggle source
# File lib/h2/client/tcp_socket.rb, line 27
def selector
  @selector ||= [self]
end

Private Instance Methods

_connect() click to toggle source
# File lib/h2/client/tcp_socket.rb, line 33
def _connect
  connect_nonblock @_sockaddr
rescue IO::WaitWritable
  :wait_writable
end
handle_wait_writable(timeout) { |== :wait_writable| ... } click to toggle source
# File lib/h2/client/tcp_socket.rb, line 39
def handle_wait_writable timeout, &block
  if IO.select nil, selector, nil, timeout
    begin
      handle_wait_writable(timeout, &block) if yield == :wait_writable
    rescue Errno::EISCONN
    rescue
      close
      raise
    end
  else
    close
    raise Errno::ETIMEDOUT
  end
end