### Home Classes Methods

### In Files

- lib/cool.io/server.rb

### Parent

Coolio::Listener

### Methods

- ::new
- #fileno
- #on_connection

### 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::Server

### Public Class Methods

new(listen_socket, klass = Socket, *args, &block) click to toggle source

Servers listen for incoming connections and create new connection objects whenever incoming connections are received. The default class for new connections is a Socket, but any subclass of IOWatcher is acceptable.

    # File lib/cool.io/server.rb, line 12
    def initialize(listen_socket, klass = Socket, *args, &block)
      # Ensure the provided class responds to attach
      unless klass.allocate.is_a? IO
        raise ArgumentError, "can't convert #{klass} to Coolio::IO"
      end

      # Verify the arity of the provided arguments
      arity = klass.instance_method(:initialize).arity
      expected = arity >= 0 ? arity : -(arity + 1)

      if (arity >= 0 and args.size + 1 != expected) or (arity < 0 and args.size + 1 < expected)
        raise ArgumentError, "wrong number of arguments for #{klass}#initialize (#{args.size+1} for #{expected})"
      end

      @klass, @args, @block = klass, args, block
      super(listen_socket)
    end

### Public Instance Methods

fileno() click to toggle source

Returns an integer representing the underlying numeric file descriptor

    # File lib/cool.io/server.rb, line 31
    def fileno
      @listen_socket.fileno
    end

### Protected Instance Methods

on_connection(socket) click to toggle source

    # File lib/cool.io/server.rb, line 39
    def on_connection(socket)
      connection = @klass.new(socket, *@args).attach(evloop)
      connection.__send__(:on_connect)
      @block.call(connection) if @block
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.