mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-13 00:30:28 +00:00
Merge pull request #117 from Arceliar/panicfix
closed channel send bugfix
This commit is contained in:
commit
ad1ba2c8ca
@ -166,17 +166,24 @@ func (ps *peers) sendSwitchMsgs() {
|
|||||||
if p.port == 0 {
|
if p.port == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
select {
|
p.doSendSwitchMsgs()
|
||||||
case p.doSend <- struct{}{}:
|
}
|
||||||
default:
|
}
|
||||||
}
|
|
||||||
|
// If called, sends a notification to the peer's linkLoop to trigger a switchMsg send.
|
||||||
|
// Mainly called by sendSwitchMsgs or during linkLoop startup.
|
||||||
|
func (p *peer) doSendSwitchMsgs() {
|
||||||
|
defer func() { recover() }() // In case there's a race with close(p.doSend)
|
||||||
|
select {
|
||||||
|
case p.doSend <- struct{}{}:
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must be launched in a separate goroutine by whatever sets up the peer struct.
|
// This must be launched in a separate goroutine by whatever sets up the peer struct.
|
||||||
// It handles link protocol traffic.
|
// It handles link protocol traffic.
|
||||||
func (p *peer) linkLoop() {
|
func (p *peer) linkLoop() {
|
||||||
go func() { p.doSend <- struct{}{} }()
|
go p.doSendSwitchMsgs()
|
||||||
tick := time.NewTicker(time.Second)
|
tick := time.NewTicker(time.Second)
|
||||||
defer tick.Stop()
|
defer tick.Stop()
|
||||||
for {
|
for {
|
||||||
|
Loading…
Reference in New Issue
Block a user