优化接入网关连接

This commit is contained in:
dushixiang
2022-05-05 17:18:55 +08:00
parent f3a78761c8
commit 90751bacfc
4 changed files with 53 additions and 49 deletions

View File

@ -57,15 +57,14 @@ func (g *Gateway) Run() {
}
func (g *Gateway) Close() {
g.exit <- true
if g.SshClient != nil {
_ = g.SshClient.Close()
}
if len(g.tunnels) > 0 {
for _, tunnel := range g.tunnels {
tunnel.Close()
}
for id := range g.tunnels {
g.CloseSshTunnel(id)
}
g.exit <- true
}
func (g *Gateway) OpenSshTunnel(id, ip string, port int) (exposedIP string, exposedPort int, err error) {
@ -111,7 +110,5 @@ func (g *Gateway) OpenSshTunnel(id, ip string, port int) (exposedIP string, expo
}
func (g Gateway) CloseSshTunnel(id string) {
if g.tunnels[id] != nil {
g.tunnels[id].Close()
}
g.Del <- id
}