From 6f170547d3a61730a6561690b1c8cae8f8b9bebf Mon Sep 17 00:00:00 2001 From: tj Date: Sat, 16 Oct 2010 20:43:59 +0200 Subject: [PATCH] Fix the pinger/ticker code a bit. Thanks soul9 ;) --- irc.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/irc.go b/irc.go index 9c5d260..ee44014 100644 --- a/irc.go +++ b/irc.go @@ -76,15 +76,17 @@ func writer(irc *IRCConnection) { //Pings the server if we have not recived any messages for 5 minutes func pinger(i *IRCConnection) { - i.ticker = time.Tick(1000 * 1000 * 1000 * 60 * 4) //Every 4 minutes - i.ticker2 = time.Tick(1000 * 1000 * 1000 * 60 * 15) //Every 15 minutes + i.ticker = time.Tick(1000 * 1000 * 1000 * 60 * 1) //Tick every minute. + i.ticker2 = time.Tick(1000 * 1000 * 1000 * 60 * 15) //Tick every 15 minutes. for { select { case <-i.ticker: - if time.Seconds()-i.lastMessage > 60*4 { + //Ping if we haven't recived anything from the server within 4 minutes + if time.Seconds()-i.lastMessage >= 60*4 { i.SendRaw(fmt.Sprintf("PING %d", time.Nanoseconds())) } case <-i.ticker2: + //Ping every 15 minutes. i.SendRaw(fmt.Sprintf("PING %d", time.Nanoseconds())) } }