### Home Classes Methods

### In Files

- lib/cool.io/listener.rb

### Parent

IOWatcher

### Methods

- ::new
- #close
- #fileno
- #listen
- #on_connection
- #on_readable

### Class/Module Index

Quicksearch

- Coolio
- Coolio::AsyncWatcher
- Coolio::Connections
- Coolio::DNSResolver
- Coolio::DNSResolver::Timeout
- Coolio::DSL
- Coolio::DSL::ConnectionBuilder
- Coolio::IO
- Coolio::IO::Watcher
- Coolio::IOWatcher
- Coolio::Listener
- Coolio::Loop
- Coolio::Meta
- Coolio::Server
- Coolio::Socket
- Coolio::Socket::Connector
- Coolio::TCPListener
- Coolio::TCPServer
- Coolio::TCPSocket
- Coolio::TCPSocket::TCPConnectResolver
- Coolio::TCPSocket::TCPConnectSocket
- Coolio::TimerWatcher
- Coolio::UNIXListener
- Coolio::UNIXServer
- Coolio::UNIXSocket
- Cool
- Cool::Coolness
- Cool::IOThunk
- Object
- Thread

No matching classes.

# Coolio::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 Class Methods

new(listen_socket) click to toggle source

    # File lib/cool.io/listener.rb, line 14
    def initialize(listen_socket)
      @listen_socket = listen_socket
      super(@listen_socket)
    end

### Public Instance Methods

close() click to toggle source

Close the listener

    # File lib/cool.io/listener.rb, line 29
    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/cool.io/listener.rb, line 20
    def fileno
      @listen_socket.fileno
    end

listen(backlog) click to toggle source

    # File lib/cool.io/listener.rb, line 24
    def listen(backlog)
      @listen_socket.listen(backlog)
    end

on_connection(socket) click to toggle source

Called whenever the server receives a new connection

    # File lib/cool.io/listener.rb, line 35
    def on_connection(socket); end

### Protected Instance Methods

on_readable() click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.