Improve idle connection management

This commit is contained in:
世界
2026-10-02 18:00:09 +08:00
parent eb7deeae8a
commit 07130365d1
37 changed files with 766 additions and 181 deletions
+19 -5
View File
@@ -30,7 +30,7 @@ func RegisterOutbound(registry *outbound.Registry) {
var (
_ adapter.OutboundWithMultiplex = (*Outbound)(nil)
_ adapter.InterfaceUpdateListener = (*Outbound)(nil)
_ adapter.IdleConnectionCloser = (*Outbound)(nil)
_ adapter.IdleConnectionKeeper = (*Outbound)(nil)
)
type Outbound struct {
@@ -134,7 +134,11 @@ func (h *Outbound) ListenPacket(ctx context.Context, destination M.Socksaddr) (n
}
func (h *Outbound) MultiplexEnabled() bool {
return h.multiplexDialer != nil
if h.multiplexDialer != nil {
return true
}
multiplexTransport, isMultiplexTransport := h.transport.(adapter.V2RayMultiplexClientTransport)
return isMultiplexTransport && multiplexTransport.MultiplexEnabled()
}
func (h *Outbound) InterfaceUpdated(ctx context.Context) {
@@ -146,10 +150,20 @@ func (h *Outbound) InterfaceUpdated(ctx context.Context) {
}
}
func (h *Outbound) SetKeepIdleConnections(keep bool) {
transportKeeper, isTransportKeeper := h.transport.(adapter.IdleConnectionKeeper)
if isTransportKeeper {
transportKeeper.SetKeepIdleConnections(keep)
}
if h.multiplexDialer != nil {
h.multiplexDialer.SetKeepIdleConnections(keep)
}
}
func (h *Outbound) CloseIdleConnections() {
transportCloser, isTransportCloser := h.transport.(adapter.IdleConnectionCloser)
if isTransportCloser {
transportCloser.CloseIdleConnections()
transportKeeper, isTransportKeeper := h.transport.(adapter.IdleConnectionKeeper)
if isTransportKeeper {
transportKeeper.CloseIdleConnections()
}
if h.multiplexDialer != nil {
h.multiplexDialer.CloseIdleConnections()