Pings are also wrapped with own sync.Mutex.
This commit is contained in:
parent
e39cceace6
commit
5a0a900995
6
irc.go
6
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())
|
||||
|
@ -43,6 +43,7 @@ type Connection struct {
|
||||
|
||||
QuitMessage string
|
||||
lastMessage time.Time
|
||||
lastMessageMutex sync.Mutex
|
||||
|
||||
VerboseCallbackHandler bool
|
||||
Log *log.Logger
|
||||
|
Loading…
Reference in New Issue
Block a user