Some more (inelegant) multiple listener code plus some reconfigure support

This commit is contained in:
Neil Alexander 2019-03-04 18:41:32 +00:00
parent be8db0c120
commit 82bb95b77f
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
5 changed files with 103 additions and 31 deletions

View file

@ -18,12 +18,13 @@ import (
)
type link struct {
core *Core
mutex sync.RWMutex // protects interfaces below
interfaces map[linkInfo]*linkInterface
handlers map[string]linkListener
awdl awdl // AWDL interface support
tcp tcp // TCP interface support
core *Core
reconfigure chan chan error
mutex sync.RWMutex // protects interfaces below
interfaces map[linkInfo]*linkInterface
handlers map[string]linkListener
awdl awdl // AWDL interface support
tcp tcp // TCP interface support
// TODO timeout (to remove from switch), read from config.ReadTimeout
}
@ -63,6 +64,7 @@ func (l *link) init(c *Core) error {
l.core = c
l.mutex.Lock()
l.interfaces = make(map[linkInfo]*linkInterface)
l.reconfigure = make(chan chan error)
l.mutex.Unlock()
if err := l.tcp.init(l); err != nil {
@ -75,6 +77,23 @@ func (l *link) init(c *Core) error {
return err
}
go func() {
for {
e := <-l.reconfigure
tcpresponse := make(chan error)
awdlresponse := make(chan error)
l.tcp.reconfigure <- tcpresponse
l.awdl.reconfigure <- awdlresponse
if err := <-tcpresponse; err != nil {
e <- err
}
if err := <-awdlresponse; err != nil {
e <- err
}
e <- nil
}
}()
return nil
}