调整生命周期的管理
This commit is contained in:
parent
a2901a0f8f
commit
7f56806852
@ -154,9 +154,7 @@ actor SDLContextActor {
|
||||
}
|
||||
|
||||
self.superMonitorTask = self.startMonitorTask(name: "superMonitorTask") {
|
||||
SDLLogger.log("[SDLContext] superClient running!!!!")
|
||||
try await self.startSuperClient()
|
||||
SDLLogger.log("[SDLContext] superClient stop!!!!")
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,8 +374,10 @@ actor SDLContextActor {
|
||||
|
||||
// 开始探测nat的类型
|
||||
Task {
|
||||
SDLLogger.log("[SDLContext] start probeNatType")
|
||||
await self.probeNatType()
|
||||
}
|
||||
|
||||
SDLLogger.log("[SDLContext] udpHole ready")
|
||||
|
||||
do {
|
||||
@ -525,10 +525,14 @@ actor SDLContextActor {
|
||||
self.updatePolicyTask?.cancel()
|
||||
|
||||
self.updatePolicyTask = Task {
|
||||
while !Task.isCancelled {
|
||||
try? await Task.sleep(for: .seconds(300))
|
||||
SDLLogger.log("[SDLContext] updatePolicyTask execute")
|
||||
await self.identifyStore.batUpdatePolicy(using: self.quicClient, dstIdentityID: self.config.identityId)
|
||||
do {
|
||||
while true {
|
||||
try await Task.sleep(for: .seconds(300))
|
||||
SDLLogger.log("[SDLContext] updatePolicyTask execute")
|
||||
await self.identifyStore.batUpdatePolicy(using: self.quicClient, dstIdentityID: self.config.identityId)
|
||||
}
|
||||
} catch let err {
|
||||
SDLLogger.log("[SDLContext] updatePolicyTask stop with err: \(err)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -730,9 +734,10 @@ extension SDLContextActor {
|
||||
try Task.checkCancellation()
|
||||
try await body()
|
||||
} catch is CancellationError {
|
||||
SDLLogger.log("[SDLContext] worker \(name) cancelled", for: .debug)
|
||||
break
|
||||
} catch let err {
|
||||
SDLLogger.log("[SDLContextActor] worker \(name) crashed: \(err.localizedDescription)", for: .debug)
|
||||
SDLLogger.log("[SDLContext] worker \(name) crashed: \(err.localizedDescription), will restart", for: .debug)
|
||||
do {
|
||||
try await Task.sleep(for: retryDelay)
|
||||
} catch is CancellationError {
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
//
|
||||
// SDLSupervisor.swift
|
||||
// punchnet
|
||||
//
|
||||
// Created by 安礼成 on 2026/3/10.
|
||||
//
|
||||
|
||||
actor SDLSupervisor {
|
||||
private var loopChildWorkers: [Task<Void, Never>] = []
|
||||
|
||||
func addWorker(name: String, _ body: @escaping () async throws -> Void, retryDelay: Duration = .seconds(2)) {
|
||||
let worker = Task(name: name) {
|
||||
while !Task.isCancelled {
|
||||
do {
|
||||
try await body()
|
||||
} catch is CancellationError {
|
||||
break
|
||||
} catch let err {
|
||||
SDLLogger.log("[Supervisor] worker \(name) crashed: \(err.localizedDescription)", for: .debug)
|
||||
try? await Task.sleep(for: retryDelay)
|
||||
}
|
||||
}
|
||||
}
|
||||
self.loopChildWorkers.append(worker)
|
||||
}
|
||||
|
||||
func stop() {
|
||||
self.loopChildWorkers.forEach { $0.cancel() }
|
||||
self.loopChildWorkers.removeAll()
|
||||
}
|
||||
|
||||
}
|
||||
@ -105,8 +105,7 @@ private final class SDLUDPHoleHandler: ChannelInboundHandler {
|
||||
var buffer = envelope.data
|
||||
let remoteAddress = envelope.remoteAddress
|
||||
|
||||
let byteCount = buffer.readableBytes - buffer.readerIndex
|
||||
SDLLogger.log("[SDLUDPHole] get raw bytes: \(byteCount), from: \(remoteAddress)", for: .debug)
|
||||
SDLLogger.log("[SDLUDPHole] get raw bytes: \(buffer.readableBytes), from: \(remoteAddress)", for: .debug)
|
||||
|
||||
do {
|
||||
if let message = try SDLHoleMessage.decode(buffer: &buffer) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user