mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-10-28 14:07:00 +00:00
Improve idle connection management
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user