diff --git a/bin/main.go b/bin/main.go index 2e02753..6aef4bf 100644 --- a/bin/main.go +++ b/bin/main.go @@ -4,8 +4,6 @@ import ( "fmt" "log" "os" - "os/signal" - "syscall" "github.com/jessevdk/go-flags" "github.com/nknorg/nconnect" @@ -50,8 +48,4 @@ func main() { log.Fatal(err) } } - - sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) - <-sigs } diff --git a/nconnect.go b/nconnect.go index 6e46fdc..e62af07 100644 --- a/nconnect.go +++ b/nconnect.go @@ -7,8 +7,10 @@ import ( "log" "net" "os" + "os/signal" "strconv" "strings" + "syscall" "time" "github.com/eycorsican/go-tun2socks/core" @@ -413,6 +415,7 @@ func (nc *nconnect) StartClient() error { } nc.startSSAndTunnel() + nc.waitForSignal() return nil } @@ -490,6 +493,7 @@ func (nc *nconnect) StartServer() error { } nc.startSSAndTunnel() + nc.waitForSignal() return nil } @@ -512,6 +516,12 @@ func (nc *nconnect) startSSAndTunnel() { }() } +func (nc *nconnect) waitForSignal() { + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + <-sigs +} + func (nc *nconnect) SetTunaNode(node *types.Node) { nc.tunaNode = node }