Class: Reel::Server

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO
Defined in:
lib/reel/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port, &callback) ⇒ Server

Returns a new instance of Server.



5
6
7
8
9
10
# File 'lib/reel/server.rb', line 5

def initialize(host, port, &callback)
  # This is actually an evented Celluloid::IO::TCPServer
  @server = TCPServer.new(host, port)
  @callback = callback
  run!
end

Instance Method Details

#finalizeObject



12
13
14
# File 'lib/reel/server.rb', line 12

def finalize
  @server.close
end

#handle_connection(socket) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/reel/server.rb', line 20

def handle_connection(socket)
  connection = Connection.new(socket)
  begin
    connection.read_request
    @callback[connection]
  end while connection.alive?
rescue EOFError
  # Client disconnected prematurely
  # FIXME: should probably do something here
end

#runObject



16
17
18
# File 'lib/reel/server.rb', line 16

def run
  loop { handle_connection! @server.accept }
end