Class: Rev::TCPListener

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

Constant Summary collapse

DEFAULT_BACKLOG =
1024

Instance Method Summary collapse

Methods inherited from Listener

#close, #fileno, #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 Rev::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 Rev::TCPListener out of the existing TCPServer object.



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rev/listener.rb', line 68

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