清理掉不必要的状态管理
This commit is contained in:
parent
5fe503b53c
commit
779947677c
@ -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) {
|
||||
|
||||
@ -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] wake")
|
||||
self.runtimeState = .waking
|
||||
SDLLogger.log("[SDLContext] wakeup")
|
||||
|
||||
// 先尝试停止
|
||||
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.flowSessionManager.clear()
|
||||
|
||||
self.udpHoleWorkers?.forEach { $0.cancel() }
|
||||
self.udpHoleWorkers = nil
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user