Developing lightweight computation at the DSG edge

Commit 3a0b5a7d authored by Ben Kochie's avatar Ben Kochie Committed by Cameron Sparr
Browse files

Fix CPU use (#40)

* Move default case out of select block.
* Add defers to close resources.
* `go fmt` cleanup.
parent 9db3df4b
...@@ -286,6 +286,7 @@ func (p *Pinger) run() { ...@@ -286,6 +286,7 @@ func (p *Pinger) run() {
var wg sync.WaitGroup var wg sync.WaitGroup
recv := make(chan *packet, 5) recv := make(chan *packet, 5)
defer close(recv)
wg.Add(1) wg.Add(1)
go p.recvICMP(conn, recv, &wg) go p.recvICMP(conn, recv, &wg)
...@@ -295,7 +296,9 @@ func (p *Pinger) run() { ...@@ -295,7 +296,9 @@ func (p *Pinger) run() {
} }
timeout := time.NewTicker(p.Timeout) timeout := time.NewTicker(p.Timeout)
defer timeout.Stop()
interval := time.NewTicker(p.Interval) interval := time.NewTicker(p.Interval)
defer interval.Stop()
for { for {
select { select {
...@@ -316,12 +319,11 @@ func (p *Pinger) run() { ...@@ -316,12 +319,11 @@ func (p *Pinger) run() {
if err != nil { if err != nil {
fmt.Println("FATAL: ", err.Error()) fmt.Println("FATAL: ", err.Error())
} }
default: }
if p.Count > 0 && p.PacketsRecv >= p.Count { if p.Count > 0 && p.PacketsRecv >= p.Count {
close(p.done) close(p.done)
wg.Wait() wg.Wait()
return return
}
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment