Class: Coolio::TCPServer

Inherits:
Server show all
Defined in:
lib/cool.io/server.rb

Overview

TCP server class. Listens on the specified host and port and creates new connection objects of the given class. This is the most common server class. Note that the new connection objects will be bound by default to the same event loop that the server is attached to. Optionally, it can also take any existing core TCPServer object as host and create a Coolio::TCPServer out of it.

Instance Method Summary collapse

Methods inherited from Server

#fileno

Methods inherited from Listener

#close, #fileno, #listen, #on_connection

Methods inherited from IOWatcher

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

Methods included from Meta

#event_callback, #watcher_delegate

Methods inherited from Watcher

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

Constructor Details

#initialize(host, port = nil, klass = TCPSocket, *args, &block) ⇒ TCPServer

Returns a new instance of TCPServer.



52
53
54
55
56
57
58
59
60
61
# File 'lib/cool.io/server.rb', line 52

def initialize(host, port = nil, klass = TCPSocket, *args, &block)
  listen_socket = if ::TCPServer === host
    host
  else
    raise ArgumentError, "port must be an integer" if nil == port
    ::TCPServer.new(host, port)
  end
  listen_socket.instance_eval { listen(DEFAULT_BACKLOG) } # Change listen backlog to 1024
  super(listen_socket, klass, *args, &block)
end