mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-10-29 06:26:56 +00:00
Refactor lifecycle to scoped cleanup
This commit is contained in:
@@ -95,15 +95,16 @@ func newInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
|
||||
return inbound, err
|
||||
}
|
||||
|
||||
func (h *Inbound) Start(stage adapter.StartStage) error {
|
||||
func (h *Inbound) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
if stage != adapter.StartStateStart {
|
||||
return nil
|
||||
}
|
||||
return h.listener.Start()
|
||||
}
|
||||
|
||||
func (h *Inbound) Close() error {
|
||||
return h.listener.Close()
|
||||
err := h.listener.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
scope.Add(h.listener.Close)
|
||||
return nil
|
||||
}
|
||||
|
||||
//nolint:staticcheck
|
||||
|
||||
@@ -109,15 +109,16 @@ func newMultiInbound(ctx context.Context, router adapter.Router, logger log.Cont
|
||||
return inbound, err
|
||||
}
|
||||
|
||||
func (h *MultiInbound) Start(stage adapter.StartStage) error {
|
||||
func (h *MultiInbound) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
if stage != adapter.StartStateStart {
|
||||
return nil
|
||||
}
|
||||
return h.listener.Start()
|
||||
}
|
||||
|
||||
func (h *MultiInbound) Close() error {
|
||||
return h.listener.Close()
|
||||
err := h.listener.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
scope.Add(h.listener.Close)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MultiInbound) SetTracker(tracker adapter.SSMTracker) {
|
||||
|
||||
@@ -86,15 +86,16 @@ func newRelayInbound(ctx context.Context, router adapter.Router, logger log.Cont
|
||||
return inbound, err
|
||||
}
|
||||
|
||||
func (h *RelayInbound) Start(stage adapter.StartStage) error {
|
||||
func (h *RelayInbound) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
if stage != adapter.StartStateStart {
|
||||
return nil
|
||||
}
|
||||
return h.listener.Start()
|
||||
}
|
||||
|
||||
func (h *RelayInbound) Close() error {
|
||||
return h.listener.Close()
|
||||
err := h.listener.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
scope.Add(h.listener.Close)
|
||||
return nil
|
||||
}
|
||||
|
||||
//nolint:staticcheck
|
||||
|
||||
@@ -152,8 +152,14 @@ func (h *Outbound) CloseIdleConnections() {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Outbound) Close() error {
|
||||
return common.Close(common.PtrOrNil(h.multiplexDialer))
|
||||
func (h *Outbound) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
if stage != adapter.StartStateInitialize {
|
||||
return nil
|
||||
}
|
||||
if h.multiplexDialer != nil {
|
||||
scope.Add(h.multiplexDialer.Close)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ N.Dialer = (*shadowsocksDialer)(nil)
|
||||
|
||||
Reference in New Issue
Block a user