From a6bebd85ed4361b1cda72db524124724dbf1f2eb Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 16 Jun 2015 15:19:57 +0100 Subject: [PATCH] Remove 'running' member that triggers a race warning and isn't necessary. --- nameserver/mdns_client.go | 16 ++++------------ nameserver/mdns_server.go | 8 -------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/nameserver/mdns_client.go b/nameserver/mdns_client.go index 2ab57c99..5cc33ba2 100644 --- a/nameserver/mdns_client.go +++ b/nameserver/mdns_client.go @@ -97,7 +97,6 @@ type MDNSClient struct { addr *net.UDPAddr inflight map[string]*inflightQuery actionChan chan<- MDNSAction - running bool } type mDNSQueryInfo struct { @@ -109,15 +108,10 @@ type mDNSQueryInfo struct { func NewMDNSClient() (*MDNSClient, error) { return &MDNSClient{ addr: ipv4Addr, - running: false, inflight: make(map[string]*inflightQuery)}, nil } func (c *MDNSClient) Start(ifi *net.Interface) (err error) { - if c.running { - return nil - } - if c.conn, err = net.ListenUDP("udp4", &net.UDPAddr{IP: net.IPv4zero, Port: 0}); err != nil { return err } @@ -144,9 +138,7 @@ func (c *MDNSClient) Start(ifi *net.Interface) (err error) { } func (c *MDNSClient) Stop() error { - if c.running { - c.actionChan <- nil - } + c.actionChan <- nil return nil } @@ -272,13 +264,13 @@ func (c *MDNSClient) checkInFlightQueries() time.Duration { func (c *MDNSClient) actorLoop(actionChan <-chan MDNSAction) { timer := time.NewTimer(MaxDuration) run := func() { timer.Reset(c.checkInFlightQueries()) } - c.running = true - for c.running { +loop: + for { select { case action := <-actionChan: if action == nil { c.listener.Shutdown() - c.running = false + break loop } else { action() run() diff --git a/nameserver/mdns_server.go b/nameserver/mdns_server.go index d95a6c1b..4a013a4f 100644 --- a/nameserver/mdns_server.go +++ b/nameserver/mdns_server.go @@ -14,7 +14,6 @@ type MDNSServer struct { zone Zone allowLocal bool ttl int - running bool } // Create a new mDNS server @@ -43,11 +42,6 @@ func (s *MDNSServer) addrIsLocal(testaddr net.Addr) bool { // Start the mDNS server func (s *MDNSServer) Start(ifi *net.Interface) (err error) { - // skip double initialization - if s.running { - return nil - } - // This is a bit of a kludge - per the RFC we should send responses from 5353, but that doesn't seem to work s.sendconn, err = net.ListenUDP("udp4", &net.UDPAddr{IP: net.IPv4zero, Port: 0}) if err != nil { @@ -94,13 +88,11 @@ func (s *MDNSServer) Start(ifi *net.Interface) (err error) { Handler: mux, } go s.srv.ActivateAndServe() - s.running = true return err } // Stop the mDNS server func (s *MDNSServer) Stop() error { - s.running = false return s.srv.Shutdown() }