Close idle connections of unreferenced outbounds and DNS servers

This commit is contained in:
世界
2026-10-02 18:00:09 +08:00
parent d2cf9747d7
commit fd9a076d25
40 changed files with 851 additions and 81 deletions
+15 -1
View File
@@ -27,7 +27,11 @@ func RegisterOutbound(registry *outbound.Registry) {
outbound.Register[option.VMessOutboundOptions](registry, C.TypeVMess, NewOutbound)
}
var _ adapter.OutboundWithMultiplex = (*Outbound)(nil)
var (
_ adapter.OutboundWithMultiplex = (*Outbound)(nil)
_ adapter.InterfaceUpdateListener = (*Outbound)(nil)
_ adapter.IdleConnectionCloser = (*Outbound)(nil)
)
type Outbound struct {
outbound.Adapter
@@ -120,6 +124,16 @@ func (h *Outbound) InterfaceUpdated(ctx context.Context) {
}
}
func (h *Outbound) CloseIdleConnections() {
transportCloser, isTransportCloser := h.transport.(adapter.IdleConnectionCloser)
if isTransportCloser {
transportCloser.CloseIdleConnections()
}
if h.multiplexDialer != nil {
h.multiplexDialer.CloseIdleConnections()
}
}
func (h *Outbound) Close() error {
return common.Close(common.PtrOrNil(h.multiplexDialer), h.transport)
}