From 7234553990cf956f13f17cac74bc0dc564eb1850 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 9 May 2015 12:49:58 +0200 Subject: [PATCH] Implement upnpSvc.Stop() (fixes #1782) --- cmd/syncthing/upnpsvc.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/syncthing/upnpsvc.go b/cmd/syncthing/upnpsvc.go index df71a69bd..016042827 100644 --- a/cmd/syncthing/upnpsvc.go +++ b/cmd/syncthing/upnpsvc.go @@ -19,6 +19,7 @@ import ( type upnpSvc struct { cfg *config.Wrapper localPort int + stop chan struct{} } func newUPnPSvc(cfg *config.Wrapper, localPort int) *upnpSvc { @@ -31,6 +32,7 @@ func newUPnPSvc(cfg *config.Wrapper, localPort int) *upnpSvc { func (s *upnpSvc) Serve() { extPort := 0 foundIGD := true + s.stop = make(chan struct{}) for { 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. d = 30 * time.Minute } - time.Sleep(d) + + select { + case <-s.stop: + return + case <-time.After(d): + } } } func (s *upnpSvc) Stop() { - panic("upnpSvc cannot stop") + close(s.stop) } func (s *upnpSvc) tryIGDs(igds []upnp.IGD, prevExtPort int) int {