mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-10-26 13:06:56 +00:00
Close idle connections of unreferenced outbounds and DNS servers
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user