class Rev::Listener

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.

Public Instance Methods

close() click to toggle source

Close the listener

# File lib/rev/listener.rb, line 25
def close
  detach if attached?
  @listen_socket.close
end
fileno() click to toggle source

Returns an integer representing the underlying numeric file descriptor

# File lib/rev/listener.rb, line 20
def fileno
  @listen_socket.fileno
end
on_connection(socket) click to toggle source

Called whenever the server receives a new connection

# File lib/rev/listener.rb, line 31
def on_connection(socket); end

Protected Instance Methods

on_readable() click to toggle source

Rev callback for handling new connections

# File lib/rev/listener.rb, line 39
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

Public Class Methods

new(listen_socket) click to toggle source
# File lib/rev/listener.rb, line 14
def initialize(listen_socket)
  @listen_socket = listen_socket
  super(@listen_socket)
end