Proper router stopping. Printable router status.

This commit is contained in:
Milos Gajdos 2019-07-27 16:01:30 +01:00
parent cb3052ce04
commit 96f9ce1bd3
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F
2 changed files with 36 additions and 10 deletions

View File

@ -431,6 +431,9 @@ func (r *router) watchErrors() {
if r.status.Code != Stopped {
// notify all goroutines to finish
close(r.exit)
// drain the advertise channel only if advertising
if r.status.Code == Advertising {
// drain the advertise channel
for range r.advertChan {
}
@ -439,6 +442,10 @@ func (r *router) watchErrors() {
}
}
// mark the router as Stopped and set its Error to nil
r.status = Status{Code: Stopped, Error: nil}
}
if err != nil {
r.status = Status{Code: Error, Error: err}
}
@ -615,12 +622,16 @@ func (r *router) Stop() error {
if r.status.Code == Running || r.status.Code == Advertising {
// notify all goroutines to finish
close(r.exit)
// drain the advertise channel only if advertising
if r.status.Code == Advertising {
// drain the advertise channel
for range r.advertChan {
}
// drain the event channel
for range r.eventChan {
}
}
// mark the router as Stopped and set its Error to nil
r.status = Status{Code: Stopped, Error: nil}

View File

@ -59,6 +59,21 @@ const (
Error
)
func (s StatusCode) String() string {
switch s {
case Running:
return "running"
case Advertising:
return "advertising"
case Stopped:
return "stopped"
case Error:
return "error"
default:
return "unknown"
}
}
// Status is router status
type Status struct {
// Error is router error