From 9d383a5b5b32282338b9ac38e0159e8881d91f4d Mon Sep 17 00:00:00 2001 From: Haidy <595153335@qq.com> Date: Wed, 16 May 2018 01:11:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/control.go | 1 + client/service.go | 3 +++ cmd/frpc/sub/root.go | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/client/control.go b/client/control.go index ba37a2db..1a8b8453 100644 --- a/client/control.go +++ b/client/control.go @@ -172,6 +172,7 @@ func (ctl *Control) Close() error { ctl.mu.Lock() defer ctl.mu.Unlock() ctl.exit = true + ctl.conn.Close() ctl.pm.CloseProxies() return nil } diff --git a/client/service.go b/client/service.go index e2c65e65..866118d0 100644 --- a/client/service.go +++ b/client/service.go @@ -52,9 +52,11 @@ func (svr *Service) Run(cmd bool) error { if cmd { <-svr.closedCh + log.Info("svr closed") } else { go func() { <-svr.closedCh + log.Info("svr closed") }() } return nil @@ -62,4 +64,5 @@ func (svr *Service) Run(cmd bool) error { func (svr *Service) Close() { svr.ctl.Close() + svr.closedCh <- 0 } diff --git a/cmd/frpc/sub/root.go b/cmd/frpc/sub/root.go index 459480cd..0c3e8dc5 100644 --- a/cmd/frpc/sub/root.go +++ b/cmd/frpc/sub/root.go @@ -112,6 +112,16 @@ func RunFrpc(cfgFilePath string) (err error) { return runClient(cfgFilePath) } +func StopFrp() (err error) { + if service == nil { + return fmt.Errorf("frp not start") + } + + service.Close() + log.Info("frpc is stoped") + return +} + func handleSignal(svr *client.Service) { ch := make(chan os.Signal) signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) @@ -225,13 +235,3 @@ func startService(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]co err = svr.Run(cmd) return } - -func StopFrp() (err error) { - if service == nil { - return fmt.Errorf("frp not start") - } - - service.Close() - log.Info("frpc is stoped") - return -}