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.
# File lib/cool.io/listener.rb, line 14 def initialize(listen_socket) @listen_socket = listen_socket super(@listen_socket) end
Close the listener
# File lib/cool.io/listener.rb, line 29 def close detach if attached? @listen_socket.close end
Returns an integer representing the underlying numeric file descriptor
# File lib/cool.io/listener.rb, line 20 def fileno @listen_socket.fileno end
# File lib/cool.io/listener.rb, line 24 def listen(backlog) @listen_socket.listen(backlog) end
Called whenever the server receives a new connection
# File lib/cool.io/listener.rb, line 35 def on_connection(socket); end
Coolio callback for handling new connections
# File lib/cool.io/listener.rb, line 43 def on_readable begin on_connection @listen_socket.accept_nonblock rescue Errno::EAGAIN, Errno::ECONNABORTED # EAGAIN can be triggered here if the socket is shared between # multiple processes and a thundering herd is woken up to accept # one connection, only one process will get the connection and # the others will be awoken. # ECONNABORTED is documented in accept() manpages but modern TCP # stacks with syncookies and/or accept()-filtering for DoS # protection do not see it. In any case this error is harmless # and we should instead spend our time with clients that follow # through on connection attempts. end end