- @timeout_timer = @timer.add_once(timeout) {
- debug "no PONG from server for #{timeout} seconds, reconnecting"
- begin
- @socket.shutdown
- rescue
- debug "couldn't shutdown connection (already shutdown?)"
+ }
+ @pong_timer = @timer.add(10) {
+ unless @last_ping.nil?
+ diff = Time.now - @last_ping
+ unless diff < @config['server.ping_timeout']
+ debug "no PONG from server for #{diff} seconds, reconnecting"
+ begin
+ @socket.shutdown
+ # TODO
+ # raise an exception to get back to the mainloop
+ rescue
+ debug "couldn't shutdown connection (already shutdown?)"
+ end
+ @last_ping = nil