瀏覽代碼

Feature: close all connections on reset

kr328 3 年之前
父節點
當前提交
bf59ead3b2
共有 2 個文件被更改,包括 7 次插入0 次删除
  1. 1 0
      core/src/main/golang/native/main.go
  2. 6 0
      core/src/main/golang/native/tunnel/conn.go

+ 1 - 0
core/src/main/golang/native/main.go

@@ -36,6 +36,7 @@ func coreInit(home, versionName C.c_string, sdkVersion C.int) {
 func reset() {
 func reset() {
 	config.LoadDefault()
 	config.LoadDefault()
 	tunnel.ResetStatistic()
 	tunnel.ResetStatistic()
+	tunnel.CloseAllConnections()
 
 
 	runtime.GC()
 	runtime.GC()
 }
 }

+ 6 - 0
core/src/main/golang/native/tunnel/conn.go

@@ -5,6 +5,12 @@ import (
 	"github.com/Dreamacro/clash/tunnel/statistic"
 	"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) {
 func closeMatch(filter func(conn C.Conn) bool) {
 	for _, c := range statistic.DefaultManager.Snapshot().Connections {
 	for _, c := range statistic.DefaultManager.Snapshot().Connections {
 		if cc, ok := c.(C.Conn); ok {
 		if cc, ok := c.(C.Conn); ok {