清理掉不必要的状态管理

This commit is contained in:
anlicheng 2026-04-29 15:53:12 +08:00
parent 5fe503b53c
commit 779947677c
2 changed files with 11 additions and 42 deletions

View File

@ -82,7 +82,7 @@ actor ArpServer {
var arpRequest = SDLArpRequest()
arpRequest.targetIp = targetIp
await quicClient.send(type: .arpRequest, data: try arpRequest.serializedData())
quicClient.send(type: .arpRequest, data: try arpRequest.serializedData())
}
func handleArpResponse(arpResponse: SDLArpResponse) {

View File

@ -22,14 +22,6 @@ actor SDLContextActor {
case stopped
}
private enum RuntimeState {
case idle
case running
case sleeping
case waking
case stopped
}
private enum UDPHoleKind: Equatable {
case v4
case v6
@ -45,7 +37,6 @@ actor SDLContextActor {
}
private var readyState: ReadyState = .idle
private var runtimeState: RuntimeState = .idle
private var readyWaiters: [CheckedContinuation<Void, Error>] = []
var config: SDLConfiguration
@ -147,7 +138,6 @@ actor SDLContextActor {
}
self.readyState = .starting
self.runtimeState = .running
await self.startRuntime(resetNotifier: true)
}
@ -183,35 +173,17 @@ actor SDLContextActor {
}
public func sleep() async {
guard self.runtimeState != .stopped else {
return
}
SDLLogger.log("[SDLContext] sleep")
self.runtimeState = .sleeping
await self.stopRuntime(clearCaches: true)
await self.stopRuntime()
}
public func wake() async {
switch self.runtimeState {
case .stopped, .waking:
return
case .running:
await self.stopRuntime(clearCaches: true)
guard case .running = self.runtimeState else {
return
}
case .idle, .sleeping:
break
}
SDLLogger.log("[SDLContext] wakeup")
SDLLogger.log("[SDLContext] wake")
self.runtimeState = .waking
//
await self.stopRuntime()
//
await self.startRuntime(resetNotifier: false)
guard case .waking = self.runtimeState else {
return
}
self.runtimeState = .running
}
public func waitForReady() async throws {
@ -482,11 +454,10 @@ actor SDLContextActor {
public func stop() async {
self.resumeReadyWaiters(.failure(CancellationError()))
self.readyState = .stopped
self.runtimeState = .stopped
await self.stopRuntime(clearCaches: true)
await self.stopRuntime()
}
private func stopRuntime(clearCaches: Bool) async {
private func stopRuntime() async {
self.superRegistrationStateMachine.reset()
await self.supervisor.stop()
@ -494,9 +465,7 @@ actor SDLContextActor {
await self.arpServer.clear()
await self.sessionManager.clear()
if clearCaches {
self.flowSessionManager.clear()
}
self.udpHoleWorkers?.forEach { $0.cancel() }
self.udpHoleWorkers = nil