Remove 'running' member that triggers a race warning and isn't necessary.
This commit is contained in:
1 parent
c2778d9fa3
commit
a6bebd85ed
2 files changed
+4
-20
No files matched your search
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user