diff --git a/client/main.go b/client/main.go index f6f06de..683e1eb 100644 --- a/client/main.go +++ b/client/main.go @@ -6,8 +6,6 @@ import ( "math/rand" "net" "os" - "os/signal" - "syscall" "time" "github.com/hashicorp/yamux" @@ -52,7 +50,6 @@ func checkError(err error) { func main() { rand.Seed(int64(time.Now().Nanosecond())) - go sig_handler() myApp := cli.NewApp() myApp.Name = "kcptun" myApp.Usage = "kcptun client" @@ -181,15 +178,3 @@ func main() { } myApp.Run(os.Args) } - -func sig_handler() { - ch := make(chan os.Signal, 1) - signal.Notify(ch, syscall.SIGUSR1) - - for { - switch <-ch { - case syscall.SIGUSR1: - log.Printf("KCP SNMP:%+v", kcp.DefaultSnmp.Copy()) - } - } -} diff --git a/client/signal.go b/client/signal.go new file mode 100644 index 0000000..8f3c74a --- /dev/null +++ b/client/signal.go @@ -0,0 +1,28 @@ +// +build linux darwin freebsd + +package main + +import ( + "log" + "os" + "os/signal" + "syscall" + + "github.com/xtaci/kcp-go" +) + +func init() { + go sig_handler() +} + +func sig_handler() { + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGUSR1) + + for { + switch <-ch { + case syscall.SIGUSR1: + log.Printf("KCP SNMP:%+v", kcp.DefaultSnmp.Copy()) + } + } +} diff --git a/server/main.go b/server/main.go index 235c55b..0c8afdb 100644 --- a/server/main.go +++ b/server/main.go @@ -6,8 +6,6 @@ import ( "math/rand" "net" "os" - "os/signal" - "syscall" "time" "github.com/hashicorp/yamux" @@ -80,7 +78,6 @@ func handleClient(p1, p2 net.Conn) { func main() { rand.Seed(int64(time.Now().Nanosecond())) - go sig_handler() myApp := cli.NewApp() myApp.Name = "kcptun" myApp.Usage = "kcptun server" @@ -178,14 +175,3 @@ func main() { } myApp.Run(os.Args) } -func sig_handler() { - ch := make(chan os.Signal, 1) - signal.Notify(ch, syscall.SIGUSR1) - - for { - switch <-ch { - case syscall.SIGUSR1: - log.Printf("KCP SNMP:%+v", kcp.DefaultSnmp.Copy()) - } - } -} diff --git a/server/signal.go b/server/signal.go new file mode 100644 index 0000000..8f3c74a --- /dev/null +++ b/server/signal.go @@ -0,0 +1,28 @@ +// +build linux darwin freebsd + +package main + +import ( + "log" + "os" + "os/signal" + "syscall" + + "github.com/xtaci/kcp-go" +) + +func init() { + go sig_handler() +} + +func sig_handler() { + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGUSR1) + + for { + switch <-ch { + case syscall.SIGUSR1: + log.Printf("KCP SNMP:%+v", kcp.DefaultSnmp.Copy()) + } + } +}