# # connectiondiag.rb # -- Rica Connection Diagnostic module # NISHI Takao # # $Id: connectiondiag.rb,v 1.2 2001/10/02 09:42:00 zophos Exp $ # require 'rica' require 'timeout' module Rica class Pinger include Event PING_INTERVAL_SEC=180 def initialize(eventProc) @eventProc=eventProc @server=nil @servername=nil @queue=Queue.new @thread=nil end def start if(@thread.nil?) sendPing end end def stop unless(@thread.nil?) begin @thread.kill rescue TreadError end @thread=nil end end def default_action(msg) @queue.push(msg) end def recv_on_link(msg) # end def on_link_closed(msg) self.stop end def on_recv_rpl_endofmotd(msg) @server=msg.server @servername=msg.from self.start self.default_action(msg) end alias on_recv_err_nomotd on_recv_rpl_endofmotd private def sendPing @thread=Thread.start do loop do begin timeout(PING_INTERVAL_SEC){ @queue.pop } rescue if((!@server.nil?)&&(!@servername.nil?)) @eventProc.cmnd_ping(@server,@servername) end end end end end end class ConnectionDiag