Class: Sorta::Http::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/sorta/http/server.rb

Constant Summary collapse

CPU_COUNT =
Etc.nprocessors

Instance Method Summary collapse

Constructor Details

#initialize(app, **options) ⇒ Server

Returns a new instance of Server.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sorta/http/server.rb', line 14

def initialize(app, **options)
  @app = app
  @options = options
  @cpu_count = options[:workers] || CPU_COUNT
  @port = options[:port] || 8080
  @host = options[:host] || 'localhost'
  @logger = options[:logger] || Logger.new

  init_pipe
  init_workers
  # TODO: init_supervisor
end

Instance Method Details

#runObject



27
28
29
30
# File 'lib/sorta/http/server.rb', line 27

def run
  tcp_server = TCPServer.new(@host, @port)
  loop { @pipe.send(tcp_server.accept, move: true) }
end