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.Log.Printf("<-- %s\n", strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
irc.Lock()
|
irc.lastMessageMutex.Lock()
|
||||||
irc.lastMessage = time.Now()
|
irc.lastMessage = time.Now()
|
||||||
irc.Unlock()
|
irc.lastMessageMutex.Unlock()
|
||||||
event, err := parseToEvent(msg)
|
event, err := parseToEvent(msg)
|
||||||
event.Connection = irc
|
event.Connection = irc
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -166,9 +166,11 @@ func (irc *Connection) pingLoop() {
|
|||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
//Ping if we haven't received anything from the server within the keep alive period
|
//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 {
|
if time.Since(irc.lastMessage) >= irc.KeepAlive {
|
||||||
irc.SendRawf("PING %d", time.Now().UnixNano())
|
irc.SendRawf("PING %d", time.Now().UnixNano())
|
||||||
}
|
}
|
||||||
|
irc.lastMessageMutex.Unlock()
|
||||||
case <-ticker2.C:
|
case <-ticker2.C:
|
||||||
//Ping at the ping frequency
|
//Ping at the ping frequency
|
||||||
irc.SendRawf("PING %d", time.Now().UnixNano())
|
irc.SendRawf("PING %d", time.Now().UnixNano())
|
||||||
|
@ -43,6 +43,7 @@ type Connection struct {
|
|||||||
|
|
||||||
QuitMessage string
|
QuitMessage string
|
||||||
lastMessage time.Time
|
lastMessage time.Time
|
||||||
|
lastMessageMutex sync.Mutex
|
||||||
|
|
||||||
VerboseCallbackHandler bool
|
VerboseCallbackHandler bool
|
||||||
Log *log.Logger
|
Log *log.Logger
|
||||||
|
Loading…
Reference in New Issue
Block a user