清理掉不必要的状态管理

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() var arpRequest = SDLArpRequest()
arpRequest.targetIp = targetIp arpRequest.targetIp = targetIp
await quicClient.send(type: .arpRequest, data: try arpRequest.serializedData()) quicClient.send(type: .arpRequest, data: try arpRequest.serializedData())
} }
func handleArpResponse(arpResponse: SDLArpResponse) { func handleArpResponse(arpResponse: SDLArpResponse) {

View File

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