Class: Coolio::Listener

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

Overview

Listeners wait for incoming connections. When a listener receives a connection it fires the on_connection event with the newly accepted socket as a parameter.

Direct Known Subclasses

Server, TCPListener, UNIXListener

Instance Method Summary collapse

Methods inherited from IOWatcher

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

Methods included from Meta

#event_callback, #watcher_delegate

Methods inherited from Watcher

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

Constructor Details

#initialize(listen_socket) ⇒ Listener

Returns a new instance of Listener.



14
15
16
17
# File 'lib/cool.io/listener.rb', line 14

def initialize(listen_socket)
  @listen_socket = listen_socket
  super(@listen_socket)
end

Instance Method Details

#closeObject

Close the listener



29
30
31
32
# File 'lib/cool.io/listener.rb', line 29

def close
  detach if attached?
  @listen_socket.close
end

#filenoObject

Returns an integer representing the underlying numeric file descriptor



20
21
22
# File 'lib/cool.io/listener.rb', line 20

def fileno
  @listen_socket.fileno
end

#listen(backlog) ⇒ Object



24
25
26
# File 'lib/cool.io/listener.rb', line 24

def listen(backlog)
  @listen_socket.listen(backlog)
end

#on_connection(socket) ⇒ Object

Called whenever the server receives a new connection



35
# File 'lib/cool.io/listener.rb', line 35

def on_connection(socket); end