Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error checks around mdns.Query #18

Merged
merged 1 commit into from Sep 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions discovery/service.go
Expand Up @@ -32,29 +32,33 @@ func NewService(ctx context.Context) *Service {
}

func (d *Service) Run(ctx context.Context, interval time.Duration) error {
mdns.Query(&mdns.QueryParam{
err := mdns.Query(&mdns.QueryParam{
Service: "_googlecast._tcp",
Domain: "local",
Timeout: interval,
Entries: d.entriesCh,
})
if err != nil {
return err
}

ticker := time.NewTicker(interval)
for {
select {
case <-ticker.C:
mdns.Query(&mdns.QueryParam{
err = mdns.Query(&mdns.QueryParam{
Service: "_googlecast._tcp",
Domain: "local",
Timeout: time.Second * 3,
Entries: d.entriesCh,
})
if err != nil {
return err
}
case <-ctx.Done():
return ctx.Err()
}
}

return nil
}

func (d *Service) Stop() {
Expand Down