Improve idle connection management

This commit is contained in:
世界
2026-10-02 18:00:09 +08:00
parent eb7deeae8a
commit 07130365d1
37 changed files with 766 additions and 181 deletions
+8 -3
View File
@@ -94,7 +94,7 @@ func NewCommandServer(handler CommandServerHandler, platformInterface PlatformIn
OOMRecorder: oomRecorder,
})
if sPowerReportEnabled {
err := powerManager.Start(PowerReportOptions(server.StartedService))
err := powerManager.Start(PowerReportOptions(server.StartedService, platformInterface))
if err != nil {
log.StdLogger().Error(E.Cause(err, "start power report recorder"))
}
@@ -258,14 +258,19 @@ func (s *CommandServer) NeedFindProcess() bool {
func (s *CommandServer) Pause() {
recorder := s.powerManager.Recorder()
if recorder != nil {
recorder.RecordPlatformEvent("ne-sleep")
recorder.RecordDeviceSleep()
}
instance := s.StartedService.Instance()
if instance == nil || instance.PauseManager() == nil {
return
}
instance.Box().CloseIdleConnections()
instance.PauseManager().DevicePause()
if C.IsIos {
// iOS calls wake within seconds of sleep while the device stays locked, so wake is
// ignored and the pause ends one minute after the last sleep instead. Go timers on
// darwin run on CLOCK_UPTIME_RAW, which does not advance while the device sleeps,
// so the minute counts awake time only and never expires inside a sleep.
if s.endPauseTimer == nil {
s.endPauseTimer = time.AfterFunc(time.Minute, s.endDevicePause)
} else {
@@ -285,7 +290,7 @@ func (s *CommandServer) endDevicePause() {
func (s *CommandServer) Wake() {
recorder := s.powerManager.Recorder()
if recorder != nil {
recorder.RecordPlatformEvent("ne-wake")
recorder.RecordDeviceWake()
}
instance := s.StartedService.Instance()
if instance == nil || instance.PauseManager() == nil {