Class: Coolio::Server

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

Direct Known Subclasses

TCPServer, UNIXServer

Instance Method Summary collapse

Methods inherited from Listener

#close, #listen

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(listen_socket, klass = Socket, *args, &block) ⇒ Server

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.


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

Instance Method Details

#filenoObject

Returns an integer representing the underlying numeric file descriptor


31
32
33
# File 'lib/cool.io/server.rb', line 31

def fileno
  @listen_socket.fileno
end