From bf59ead3b2490592854f95225aa525e263ffc5b4 Mon Sep 17 00:00:00 2001 From: kr328 Date: Wed, 20 Apr 2022 00:39:46 +0800 Subject: [PATCH] Feature: close all connections on reset --- core/src/main/golang/native/main.go | 1 + core/src/main/golang/native/tunnel/conn.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/core/src/main/golang/native/main.go b/core/src/main/golang/native/main.go index 92933398..01c68b20 100644 --- a/core/src/main/golang/native/main.go +++ b/core/src/main/golang/native/main.go @@ -36,6 +36,7 @@ func coreInit(home, versionName C.c_string, sdkVersion C.int) { func reset() { config.LoadDefault() tunnel.ResetStatistic() + tunnel.CloseAllConnections() runtime.GC() } diff --git a/core/src/main/golang/native/tunnel/conn.go b/core/src/main/golang/native/tunnel/conn.go index c0b05bb3..beb7c3c9 100644 --- a/core/src/main/golang/native/tunnel/conn.go +++ b/core/src/main/golang/native/tunnel/conn.go @@ -5,6 +5,12 @@ import ( "github.com/Dreamacro/clash/tunnel/statistic" ) +func CloseAllConnections() { + for _, c := range statistic.DefaultManager.Snapshot().Connections { + _ = c.Close() + } +} + func closeMatch(filter func(conn C.Conn) bool) { for _, c := range statistic.DefaultManager.Snapshot().Connections { if cc, ok := c.(C.Conn); ok {