Proper router stopping. Printable router status.
This commit is contained in:
parent
cb3052ce04
commit
96f9ce1bd3
@ -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}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user