Class: LazyGraph::RackServer

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy_graph/rack_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RackServer

Returns a new instance of RackServer.

[View source]

7
8
9
10
11
12
# File 'lib/lazy_graph/rack_server.rb', line 7

def initialize(app)
  @app       = app
  @running   = false
  @threads   = [] #
  @threads_m = Mutex.new
end

Instance Method Details

#start(port: 9292, workers: 4) ⇒ Object

[View source]

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lazy_graph/rack_server.rb', line 14

def start(port: 9292, workers: 4)
  trap_signals

  @port = port
  @workers = workers

  if workers > 1
    puts "Starting Raxx server with #{workers} processes on port #{port}..."
    @server = TCPServer.new(@port)
    @server.listen(1024)

    workers.times do
      fork(&method(:run_accept_loop))
    end
    Process.waitall
  else
    puts "Starting single-process server on port #{port}..."
    @server = TCPServer.new(@port)
    @server.listen(1024)
    run_accept_loop
  end
end