fix handling of keepAliveTimer and blocked state in link.go

This commit is contained in:
Arceliar 2020-05-30 10:32:15 -05:00
parent 1df305d31c
commit 3dc2242712

View File

@ -387,19 +387,14 @@ func (intf *link) notifySending(size int) {
intf.Act(&intf.writer, func() {
intf.isSending = true
intf.sendTimer = time.AfterFunc(sendTime, intf.notifyBlockedSend)
intf._cancelStallTimer()
if intf.keepAliveTimer != nil {
intf.keepAliveTimer.Stop()
intf.keepAliveTimer = nil
}
intf.peer.notifyBlocked(intf)
})
}
// we just sent something, so cancel any pending timer to send keep-alive traffic
func (intf *link) _cancelStallTimer() {
if intf.stallTimer != nil {
intf.stallTimer.Stop()
intf.stallTimer = nil
}
}
// This gets called from a time.AfterFunc, and notifies the switch that we appear
// to have gotten blocked on a write, so the switch should start routing traffic
// through other links, if alternatives exist
@ -441,11 +436,13 @@ func (intf *link) _notifyIdle() {
// Set the peer as stalled, to prevent them from returning to the switch until a read succeeds
func (intf *link) notifyStalled() {
intf.Act(nil, func() { // Sent from a time.AfterFunc
if intf.stallTimer != nil && !intf.blocked {
if intf.stallTimer != nil {
intf.stallTimer.Stop()
intf.stallTimer = nil
intf.blocked = true
intf.links.core.switchTable.blockPeer(intf, intf.peer.port)
if !intf.blocked {
intf.blocked = true
intf.links.core.switchTable.blockPeer(intf, intf.peer.port)
}
}
})
}
@ -480,9 +477,9 @@ func (intf *link) notifyRead(size int) {
// We need to send keep-alive traffic now
func (intf *link) notifyDoKeepAlive() {
intf.Act(nil, func() { // Sent from a time.AfterFunc
if intf.stallTimer != nil {
intf.stallTimer.Stop()
intf.stallTimer = nil
if intf.keepAliveTimer != nil {
intf.keepAliveTimer.Stop()
intf.keepAliveTimer = nil
intf.writer.sendFrom(nil, [][]byte{nil}) // Empty keep-alive traffic
}
})