diff --git a/goping/ping_test.go b/goping/ping_test.go index 691771e..c38a01c 100644 --- a/goping/ping_test.go +++ b/goping/ping_test.go @@ -5,14 +5,22 @@ import ( "os" "os/signal" "testing" + "time" ) func TestSign(tt *testing.T) { c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt, os.Kill) - - s := <-c - fmt.Println("Got signal:", s) + for { + select { + case s := <-c: + signal.Notify(c, os.Interrupt, os.Kill) + fmt.Println("Got signal:", s) + os.Exit(0) + default: + fmt.Println("okok") + time.Sleep(time.Second * 1) + } + } } func TestPing(tt *testing.T) { //if len(os.Args) < 3 { diff --git a/pong.go b/pong.go index d454d57..5f0d89b 100644 --- a/pong.go +++ b/pong.go @@ -22,11 +22,12 @@ pong www.baidu.com 443 -t 1 -k udp pong -a www.baidu.com -p 443 -k tcp -t 3 ` -func main2() { +func main() { c := make(chan os.Signal, 1) for { select { case s := <-c: + fmt.Println("ctc") signal.Notify(c, os.Interrupt, os.Kill) fmt.Println("Got signal:", s) os.Exit(0) @@ -37,7 +38,7 @@ func main2() { } } -func main() { +func main3() { address := flag.String("a", "", "domain or ip address") port := flag.Int("p", 0, "port") protocol := flag.String("k", "tcp", "protocol kind")