Merge pull request #267 from alholm/fix/256

mDNS discovery starts announcing right away
This commit is contained in:
Steven Allen 2018-01-28 05:10:55 +00:00 committed by GitHub
commit f5e43430a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 21 deletions

View File

@ -118,29 +118,32 @@ func (m *mdnsService) pollForEntries(ctx context.Context) {
ticker := time.NewTicker(m.interval)
for {
//execute mdns query right away at method call and then with every tick
entriesCh := make(chan *mdns.ServiceEntry, 16)
go func() {
for entry := range entriesCh {
m.handleEntry(entry)
}
}()
log.Debug("starting mdns query")
qp := &mdns.QueryParam{
Domain: "local",
Entries: entriesCh,
Service: m.tag,
Timeout: time.Second * 5,
}
err := mdns.Query(qp)
if err != nil {
log.Error("mdns lookup error: ", err)
}
close(entriesCh)
log.Debug("mdns query complete")
select {
case <-ticker.C:
entriesCh := make(chan *mdns.ServiceEntry, 16)
go func() {
for entry := range entriesCh {
m.handleEntry(entry)
}
}()
log.Debug("starting mdns query")
qp := &mdns.QueryParam{
Domain: "local",
Entries: entriesCh,
Service: m.tag,
Timeout: time.Second * 5,
}
err := mdns.Query(qp)
if err != nil {
log.Error("mdns lookup error: ", err)
}
close(entriesCh)
log.Debug("mdns query complete")
continue
case <-ctx.Done():
log.Debug("mdns service halting")
return