Class: Rev::Server

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

Direct Known Subclasses

TCPServer, UNIXServer

Instance Method Summary collapse

Methods inherited from IOWatcher

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

Methods inherited from Watcher

#attach, #attached?, #detach, #disable, #enable, event_callback, #evloop, watcher_delegate

Constructor Details

#initialize(listen_socket, klass = Socket, *args, &block) ⇒ Server

Returns a new instance of Server.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rev/server.rb', line 11

def initialize(listen_socket, klass = Socket, *args, &block)
  # Ensure the provided class responds to attach
  unless (klass.instance_method(:attach) rescue nil)
    raise ArgumentError, "provided class must respond to 'attach'"
  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