Class: Adelnor::ThreadedServer
- Inherits:
-
BaseServer
- Object
- BaseServer
- Adelnor::ThreadedServer
- Defined in:
- lib/adelnor/threaded_server.rb
Instance Method Summary collapse
- #handle_thread ⇒ Object
-
#initialize(rack_app, port, options = {}) ⇒ ThreadedServer
constructor
A new instance of ThreadedServer.
- #run ⇒ Object
Methods inherited from BaseServer
#handle, #rack_data, #read_request_message, run, #welcome_message
Constructor Details
#initialize(rack_app, port, options = {}) ⇒ ThreadedServer
Returns a new instance of ThreadedServer.
7 8 9 10 11 12 |
# File 'lib/adelnor/threaded_server.rb', line 7 def initialize(rack_app, port, = {}) super(rack_app, port, ) @thread_queue = Queue.new @pool_size = [:thread_pool] end |
Instance Method Details
#handle_thread ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/adelnor/threaded_server.rb', line 26 def handle_thread tid = Thread.current.object_id puts "[#{tid}] Thread started" loop do client = @thread_queue.pop handle(client) client.close end end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/adelnor/threaded_server.rb', line 14 def run @pool_size.times do Thread.new { handle_thread } end loop do client, = @socket.accept @thread_queue.push(client) end end |