From 5d5033afa9052dc0d60e743f07bc694f008182b3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 20 May 2011 14:22:37 -0700 Subject: event_machine: disconnect idle clients at on SIGQUIT Since it's cheap to maintain keepalive clients with EM, we need a way of disconnecting them in a timely fashion on rare SIGQUIT events. --- lib/rainbows/event_machine.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index b136518..025b795 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -74,11 +74,11 @@ module Rainbows::EventMachine conns = EM.instance_variable_get(:@conns) or raise RuntimeError, "EM @conns instance variable not accessible!" Rainbows::EventMachine::Server.const_set(:CUR, conns) + Rainbows.at_quit do + EM.next_tick { conns.each_value { |c| client_class === c and c.quit } } + end EM.add_periodic_timer(1) do - unless Rainbows.tick - conns.each_value { |c| client_class === c and c.quit } - EM.stop if conns.empty? && EM.reactor_running? - end + EM.stop if ! Rainbows.tick && conns.empty? && EM.reactor_running? end LISTENERS.map! do |s| EM.watch(s, Rainbows::EventMachine::Server) do |c| -- cgit v1.2.3-24-ge0c7