From fa93a16ede574df6159497a526153a9978b66dd1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 25 Oct 2009 16:34:33 -0700 Subject: eventmachine: get basic tests working log reopens, graceful shutdown, HTTP error responses should all be working now. --- lib/rainbows/event_machine.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'lib/rainbows/event_machine.rb') diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index 2cc0f15..176bf51 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -37,6 +37,11 @@ module Rainbows alias write send_data alias receive_data on_read + def quit + super + close_connection_after_writing + end + def app_call begin (@env[RACK_INPUT] = @input).rewind @@ -54,7 +59,7 @@ module Rainbows # keepalive requests are always body-less, so @input is unchanged @hp.headers(@env, @buf) and next else - @state = :close + quit end return end while true @@ -89,6 +94,11 @@ module Rainbows @em_conns = conns end + def close + detach + @l.close + end + def notify_readable return if @em_conns.size >= @limit begin @@ -109,8 +119,14 @@ module Rainbows EM.run { conns = EM.instance_variable_get(:@conns) or raise RuntimeError, "EM @conns instance variable not accessible!" - EM.add_periodic_timer(1) { worker.tmp.chmod(m = 0 == m ? 1 : 0) } - LISTENERS.each { |s| EM.attach(s, Server, s, conns) } + EM.add_periodic_timer(1) do + worker.tmp.chmod(m = 0 == m ? 1 : 0) + unless G.alive + conns.each_value { |client| Client === client and client.quit } + EM.stop if conns.empty? && EM.reactor_running? + end + end + LISTENERS.map! { |s| EM.attach(s, Server, s, conns) } } end -- cgit v1.2.3-24-ge0c7