5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-10 06:20:26 +00:00

replace the send-to-self with a timer and an arbitrary timeout; i don't really like this but it seems to work better (1 ms is fast by human standards but an eternity for a syscall or the scheduler, so i think that's reasonable)

This commit is contained in:
Arceliar 2019-09-24 18:28:13 -05:00
parent 8c64e6fa09
commit b9e74f34ec

View File

@ -64,8 +64,6 @@ type linkInterface struct {
closeTimer *time.Timer // Fires when the link has been idle so long we need to close it closeTimer *time.Timer // Fires when the link has been idle so long we need to close it
inSwitch bool // True if the switch is tracking this link inSwitch bool // True if the switch is tracking this link
stalled bool // True if we haven't been receiving any response traffic stalled bool // True if we haven't been receiving any response traffic
sendSeqSent uint // Incremented each time we start sending
sendSeqRecv uint // Incremented each time we finish sending
} }
func (l *link) init(c *Core) error { func (l *link) init(c *Core) error {
@ -275,21 +273,14 @@ func (intf *linkInterface) notifySending(size int, isLinkTraffic bool) {
} }
intf.sendTimer = time.AfterFunc(sendTime, intf.notifyBlockedSend) intf.sendTimer = time.AfterFunc(sendTime, intf.notifyBlockedSend)
intf._cancelStallTimer() intf._cancelStallTimer()
intf.sendSeqSent++
seq := intf.sendSeqSent
intf.Act(nil, func() {
intf._checkSending(seq)
})
}) })
} }
// If check if we're still sending // called by an AfterFunc if we seem to be blocked in a send syscall for a long time
func (intf *linkInterface) _checkSending(seq uint) { func (intf *linkInterface) _notifySyscall() {
if intf.sendSeqRecv != seq {
intf.link.core.switchTable.Act(intf, func() { intf.link.core.switchTable.Act(intf, func() {
intf.link.core.switchTable._sendingIn(intf.peer.port) intf.link.core.switchTable._sendingIn(intf.peer.port)
}) })
}
} }
// we just sent something, so cancel any pending timer to send keep-alive traffic // we just sent something, so cancel any pending timer to send keep-alive traffic
@ -321,7 +312,6 @@ func (intf *linkInterface) notifySent(size int, isLinkTraffic bool) {
if size > 0 && intf.stallTimer == nil { if size > 0 && intf.stallTimer == nil {
intf.stallTimer = time.AfterFunc(stallTime, intf.notifyStalled) intf.stallTimer = time.AfterFunc(stallTime, intf.notifyStalled)
} }
intf.sendSeqRecv++
}) })
} }
@ -397,7 +387,15 @@ func (w *linkWriter) sendFrom(from phony.Actor, bss [][]byte, isLinkTraffic bool
size += len(bs) size += len(bs)
} }
w.intf.notifySending(size, isLinkTraffic) w.intf.notifySending(size, isLinkTraffic)
var once sync.Once
timer := time.AfterFunc(time.Millisecond, func() {
once.Do(func() {
w.intf.Act(nil, w.intf._notifySyscall)
})
})
w.intf.msgIO.writeMsgs(bss) w.intf.msgIO.writeMsgs(bss)
// Make sure we either stop the timer from doing anything or wait until it's done
once.Do(func() { timer.Stop() })
w.intf.notifySent(size, isLinkTraffic) w.intf.notifySent(size, isLinkTraffic)
// Cleanup // Cleanup
for _, bs := range bss { for _, bs := range bss {