Files
sing-box-extended-mirror/daemon/attached_service.go
T

29 lines
775 B
Go
Raw Normal View History

2026-06-11 21:11:10 +08:00
package daemon
import (
"context"
"time"
"github.com/sagernet/sing-box/log"
)
const defaultAttachedLogMaxLines = 3000
// StartOrReloadService and CloseService must not be called on an attached service.
func NewAttachedService(ctx context.Context) *StartedService {
instance := attachInstance(ctx)
s := NewStartedService(ServiceOptions{
Context: ctx,
LogMaxLines: defaultAttachedLogMaxLines,
})
s.instance = instance
s.serviceStatus = &ServiceStatus{Status: ServiceStatus_STARTED}
s.startedAt = time.Now()
instance.urlTestHistoryStorage.AddUpdateHook(s.urlTestSubscriber)
2026-06-11 21:11:10 +08:00
if instance.clashServer != nil {
instance.clashServer.AddModeUpdateHook(s.clashModeSubscriber)
2026-06-11 21:11:10 +08:00
}
instance.logFactory.(log.ObservableFactory).AttachPlatformWriter(s)
return s
}