Developing lightweight computation at the DSG edge

Commit 667d0a66 authored by Xie Zhenye's avatar Xie Zhenye Committed by Cameron Sparr
Browse files

remove signal handler, add Stop method (#10)

* remove signal handler, add Stop method

* Added ICMP Packet ID to distinguish ICMP replies
parent ad2f544f
...@@ -48,8 +48,6 @@ import ( ...@@ -48,8 +48,6 @@ import (
"math" "math"
"math/rand" "math/rand"
"net" "net"
"os"
"os/signal"
"sync" "sync"
"syscall" "syscall"
"time" "time"
...@@ -94,7 +92,6 @@ func NewPinger(addr string) (*Pinger, error) { ...@@ -94,7 +92,6 @@ func NewPinger(addr string) (*Pinger, error) {
network: "udp", network: "udp",
ipv4: ipv4, ipv4: ipv4,
Size: timeSliceLength, Size: timeSliceLength,
done: make(chan bool), done: make(chan bool),
}, nil }, nil
} }
...@@ -290,14 +287,9 @@ func (p *Pinger) run() { ...@@ -290,14 +287,9 @@ func (p *Pinger) run() {
timeout := time.NewTicker(p.Timeout) timeout := time.NewTicker(p.Timeout)
interval := time.NewTicker(p.Interval) interval := time.NewTicker(p.Interval)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
for { for {
select { select {
case <-c:
close(p.done)
case <-p.done: case <-p.done:
wg.Wait() wg.Wait()
return return
...@@ -325,6 +317,10 @@ func (p *Pinger) run() { ...@@ -325,6 +317,10 @@ func (p *Pinger) run() {
} }
} }
func (p *Pinger) Stop() {
close(p.done)
}
func (p *Pinger) finish() { func (p *Pinger) finish() {
handler := p.OnFinish handler := p.OnFinish
if handler != nil { if handler != nil {
......
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