Fix the pinger/ticker code a bit. Thanks soul9 ;)
This commit is contained in:
parent
0b332411b6
commit
6f170547d3
8
irc.go
8
irc.go
@ -76,15 +76,17 @@ func writer(irc *IRCConnection) {
|
|||||||
|
|
||||||
//Pings the server if we have not recived any messages for 5 minutes
|
//Pings the server if we have not recived any messages for 5 minutes
|
||||||
func pinger(i *IRCConnection) {
|
func pinger(i *IRCConnection) {
|
||||||
i.ticker = time.Tick(1000 * 1000 * 1000 * 60 * 4) //Every 4 minutes
|
i.ticker = time.Tick(1000 * 1000 * 1000 * 60 * 1) //Tick every minute.
|
||||||
i.ticker2 = time.Tick(1000 * 1000 * 1000 * 60 * 15) //Every 15 minutes
|
i.ticker2 = time.Tick(1000 * 1000 * 1000 * 60 * 15) //Tick every 15 minutes.
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-i.ticker:
|
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()))
|
i.SendRaw(fmt.Sprintf("PING %d", time.Nanoseconds()))
|
||||||
}
|
}
|
||||||
case <-i.ticker2:
|
case <-i.ticker2:
|
||||||
|
//Ping every 15 minutes.
|
||||||
i.SendRaw(fmt.Sprintf("PING %d", time.Nanoseconds()))
|
i.SendRaw(fmt.Sprintf("PING %d", time.Nanoseconds()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user