Class Connector
In: lib/network/connector.rb
Parent: Session
Connector
Session
dot/f_26.png

The Connector class handles outgoing connections

Methods

handle_close   init   new  

Public Class methods

Create a new Connector object

server
The reactor this Connector is associated with.
address
The address to connect to.
returns
An Connector object

[Source]

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

Public Instance methods

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

[Source]

# File lib/network/connector.rb, line 60
  def handle_close
    @sock.close
  rescue Exception
    log.error "Connector#handle_close"
    log.error $!
  end

init is called before using the Connector

returns
true is acceptor is properly initialized

[Source]

# 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 =~ /win32/
      @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

[Validate]