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,12 +431,19 @@ func (r *router) watchErrors() {
if r.status.Code != Stopped {
// notify all goroutines to finish
close(r.exit)
// drain the advertise channel
for range r.advertChan {
}
// drain the event channel
for range r.eventChan {
// 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}
}
if err != nil {
@ -615,11 +622,15 @@ 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
for range r.advertChan {
}
// drain the event channel
for range r.eventChan {
// 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

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