Refactor lifecycle to scoped cleanup

This commit is contained in:
世界
2026-10-09 12:36:03 +08:00
parent a364ff4794
commit a691a44023
115 changed files with 1595 additions and 2030 deletions
+7 -6
View File
@@ -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
+7 -6
View File
@@ -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) {
+7 -6
View File
@@ -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
+8 -2
View File
@@ -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)