class Connector

The Connector class handles outgoing connections

Public Class Methods

new(server, address) click to toggle source

Create a new Connector object

server

The reactor this Connector is associated with.

address

The address to connect to.

returns

An Connector object

# File lib/network/connector.rb, line 30
def initialize(server, address)
  @address = address
  super(server)
end

Public Instance Methods

handle_close() click to toggle source

#handle_close is called when a close event occurs for this Connector.

# File lib/network/connector.rb, line 60
def handle_close
  @sock.close
rescue Exception
  log.error "Connector#handle_close"
  log.error $!
end
init() click to toggle source

init is called before using the Connector

returns

true is acceptor is properly initialized

# File lib/network/connector.rb, line 37
def init
  # Open a socket for the server to connect on.
  @sock = TCPSocket.new(@address , @server.port)
  @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
  @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, false)
  unless RUBY_PLATFORM =~ %rwin32/
    @sock.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
  end
  c = Connection.new(@server, @sock)
  if c.init
    log.info "(#{c.object_id}) Connection made."
    publish(c)
    true
  else
    false
  end
rescue Exception
  log.error "Connector#init"
  log.error $!
  false
end