From 5a0a9009952b97fb28dc2b1f37799936db0a9439 Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Tue, 3 Oct 2017 02:19:13 +0500 Subject: [PATCH] Pings are also wrapped with own sync.Mutex. --- irc.go | 6 ++++-- irc_struct.go | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/irc.go b/irc.go index eb9174d..1b52f34 100644 --- a/irc.go +++ b/irc.go @@ -74,9 +74,9 @@ func (irc *Connection) readLoop() { irc.Log.Printf("<-- %s\n", strings.TrimSpace(msg)) } - irc.Lock() + irc.lastMessageMutex.Lock() irc.lastMessage = time.Now() - irc.Unlock() + irc.lastMessageMutex.Unlock() event, err := parseToEvent(msg) event.Connection = irc if err == nil { @@ -166,9 +166,11 @@ func (irc *Connection) pingLoop() { select { case <-ticker.C: //Ping if we haven't received anything from the server within the keep alive period + irc.lastMessageMutex.Lock() if time.Since(irc.lastMessage) >= irc.KeepAlive { irc.SendRawf("PING %d", time.Now().UnixNano()) } + irc.lastMessageMutex.Unlock() case <-ticker2.C: //Ping at the ping frequency irc.SendRawf("PING %d", time.Now().UnixNano()) diff --git a/irc_struct.go b/irc_struct.go index f161a18..22d08d8 100644 --- a/irc_struct.go +++ b/irc_struct.go @@ -43,6 +43,7 @@ type Connection struct { QuitMessage string lastMessage time.Time + lastMessageMutex sync.Mutex VerboseCallbackHandler bool Log *log.Logger