Class: Coolio::TCPListener

Inherits:
Listener show all
Defined in:
lib/cool.io/listener.rb

Instance Method Summary collapse

Methods inherited from Listener

#close, #fileno, #listen, #on_connection

Methods inherited from IOWatcher

#attach, #detach, #disable, #enable, #on_readable, #on_writable

Methods included from Meta

#event_callback, #watcher_delegate

Methods inherited from Watcher

#attach, #attached?, #detach, #disable, #enable, #enabled?, #evloop

Constructor Details

#initialize(addr, port = nil, options = {}) ⇒ TCPListener

Create a new Coolio::TCPListener on the specified address and port. Accepts the following options:

:backlog - Max size of the pending connection queue (default 1024)
:reverse_lookup - Retain BasicSocket's reverse DNS functionality (default false)

If the specified address is an TCPServer object, it will ignore the port and :backlog option and create a new Coolio::TCPListener out of the existing TCPServer object.



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/cool.io/listener.rb', line 84

def initialize(addr, port = nil, options = {})
  BasicSocket.do_not_reverse_lookup = true unless options[:reverse_lookup]
  options[:backlog] ||= DEFAULT_BACKLOG

  listen_socket = if ::TCPServer === addr
    addr
  else
    raise ArgumentError, "port must be an integer" if nil == port
    ::TCPServer.new(addr, port)
  end
  listen_socket.instance_eval { listen(options[:backlog]) }
  super(listen_socket)
end