Implement upnpSvc.Stop() (fixes #1782)

This commit is contained in:
Jakob Borg 2015-05-09 12:49:58 +02:00
parent 5761efdb73
commit 7234553990

View File

@ -19,6 +19,7 @@ import (
type upnpSvc struct { type upnpSvc struct {
cfg *config.Wrapper cfg *config.Wrapper
localPort int localPort int
stop chan struct{}
} }
func newUPnPSvc(cfg *config.Wrapper, localPort int) *upnpSvc { func newUPnPSvc(cfg *config.Wrapper, localPort int) *upnpSvc {
@ -31,6 +32,7 @@ func newUPnPSvc(cfg *config.Wrapper, localPort int) *upnpSvc {
func (s *upnpSvc) Serve() { func (s *upnpSvc) Serve() {
extPort := 0 extPort := 0
foundIGD := true foundIGD := true
s.stop = make(chan struct{})
for { for {
igds := upnp.Discover(time.Duration(s.cfg.Options().UPnPTimeoutS) * time.Second) igds := upnp.Discover(time.Duration(s.cfg.Options().UPnPTimeoutS) * time.Second)
@ -49,12 +51,17 @@ func (s *upnpSvc) Serve() {
// We always want to do renewal so lets just pick a nice sane number. // We always want to do renewal so lets just pick a nice sane number.
d = 30 * time.Minute d = 30 * time.Minute
} }
time.Sleep(d)
select {
case <-s.stop:
return
case <-time.After(d):
}
} }
} }
func (s *upnpSvc) Stop() { func (s *upnpSvc) Stop() {
panic("upnpSvc cannot stop") close(s.stop)
} }
func (s *upnpSvc) tryIGDs(igds []upnp.IGD, prevExtPort int) int { func (s *upnpSvc) tryIGDs(igds []upnp.IGD, prevExtPort int) int {