class Thrift::Socket

Attributes

handle[RW]
timeout[RW]

Public Class Methods

new(host='localhost', port=9090, timeout=nil) click to toggle source
# File lib/thrift/transport/socket.rb, line 24
def initialize(host='localhost', port=9090, timeout=nil)
  @host = host
  @port = port
  @timeout = timeout
  @desc = "#{host}:#{port}"
  @handle = nil
end

Public Instance Methods

open() click to toggle source
# File lib/thrift/transport/socket.rb, line 34
def open
  for addrinfo in ::Socket::getaddrinfo(@host, @port, nil, ::Socket::SOCK_STREAM) do
    begin
      socket = ::Socket.new(addrinfo[4], ::Socket::SOCK_STREAM, 0)
      socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
      sockaddr = ::Socket.sockaddr_in(addrinfo[1], addrinfo[3])
      begin
        socket.connect_nonblock(sockaddr)
      rescue Errno::EINPROGRESS
        unless IO.select(nil, [ socket ], nil, @timeout)
          next
        end
        begin
          socket.connect_nonblock(sockaddr)
        rescue Errno::EISCONN
        end
      end
      return @handle = socket
    rescue StandardError => e
      next
    end
  end