调整变量的ARC
This commit is contained in:
parent
f9fa7bf73e
commit
b858be7310
@ -374,7 +374,10 @@ actor SDLContextActor {
|
||||
self.udpHoleLocalAddress = localAddress
|
||||
|
||||
defer {
|
||||
if self.udpHole === udpHole {
|
||||
self.udpHole = nil
|
||||
self.udpHoleLocalAddress = nil
|
||||
}
|
||||
}
|
||||
|
||||
// 开始探测nat的类型
|
||||
@ -430,9 +433,11 @@ actor SDLContextActor {
|
||||
}
|
||||
|
||||
defer {
|
||||
self.udpHoleV6?.stop()
|
||||
if self.udpHoleV6 === udpHoleV6 {
|
||||
udpHoleV6.stop()
|
||||
self.udpHoleV6 = nil
|
||||
}
|
||||
}
|
||||
|
||||
try await withThrowingTaskGroup { group in
|
||||
defer {
|
||||
@ -485,12 +490,18 @@ actor SDLContextActor {
|
||||
|
||||
self.flowSessionManager.clear()
|
||||
|
||||
self.udpHoleMonitorTask?.cancel()
|
||||
let udpHole = self.udpHole
|
||||
self.udpHole = nil
|
||||
self.udpHoleLocalAddress = nil
|
||||
|
||||
self.udpHoleV6?.stop()
|
||||
let udpHoleV6 = self.udpHoleV6
|
||||
self.udpHoleV6 = nil
|
||||
|
||||
self.udpHoleMonitorTask?.cancel()
|
||||
self.udpHoleMonitorTask = nil
|
||||
udpHoleV6?.stop()
|
||||
await udpHole?.stop()
|
||||
|
||||
self.dnsMonitorTask?.cancel()
|
||||
self.dnsLocalMonitorTask?.cancel()
|
||||
|
||||
|
||||
@ -82,6 +82,7 @@ actor DNSLocalClient {
|
||||
|
||||
self.connection = connection
|
||||
self.cleanupTask = cleanupTask
|
||||
|
||||
connection.start(queue: .global())
|
||||
}
|
||||
|
||||
|
||||
@ -76,7 +76,7 @@ private final class SDLUDPHoleHandler: ChannelInboundHandler {
|
||||
private let messageContinuation: AsyncThrowingStream<(SocketAddress, SDLHoleMessage), Error>.Continuation
|
||||
private var isMessageContinuationFinished: Bool = false
|
||||
|
||||
private var counterActor: SDLUDPCounter
|
||||
private let counterActor: SDLUDPCounter
|
||||
|
||||
// 启动函数
|
||||
init() throws {
|
||||
@ -102,8 +102,9 @@ private final class SDLUDPHoleHandler: ChannelInboundHandler {
|
||||
|
||||
self.channel = channel
|
||||
|
||||
let counterActor = self.counterActor
|
||||
Task {
|
||||
await self.counterActor.start()
|
||||
await counterActor.start()
|
||||
}
|
||||
|
||||
return localAddress
|
||||
@ -117,8 +118,9 @@ private final class SDLUDPHoleHandler: ChannelInboundHandler {
|
||||
let remoteAddress = envelope.remoteAddress
|
||||
|
||||
let bytesCount = buffer.readableBytes
|
||||
let counterActor = self.counterActor
|
||||
Task {
|
||||
await self.counterActor.increment(direction: .inbound, from: remoteAddress.description, bytes: bytesCount)
|
||||
await counterActor.increment(direction: .inbound, from: remoteAddress.description, bytes: bytesCount)
|
||||
}
|
||||
|
||||
do {
|
||||
@ -147,8 +149,9 @@ private final class SDLUDPHoleHandler: ChannelInboundHandler {
|
||||
return
|
||||
}
|
||||
|
||||
let counterActor = self.counterActor
|
||||
Task {
|
||||
await self.counterActor.increment(direction: .outbound, from: remoteAddress.description, bytes: data.count)
|
||||
await counterActor.increment(direction: .outbound, from: remoteAddress.description, bytes: data.count)
|
||||
}
|
||||
|
||||
var buffer = channel.allocator.buffer(capacity: data.count + 1)
|
||||
@ -162,8 +165,8 @@ private final class SDLUDPHoleHandler: ChannelInboundHandler {
|
||||
channel.writeAndFlush(envelope, promise: promise)
|
||||
}
|
||||
|
||||
promise.futureResult.whenFailure { err in
|
||||
self.finishMessageContinuationIfNeed(throwing: .sendFaied(err))
|
||||
promise.futureResult.whenFailure { [weak self] err in
|
||||
self?.finishMessageContinuationIfNeed(throwing: .sendFaied(err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,8 +176,9 @@ private final class SDLUDPHoleHandler: ChannelInboundHandler {
|
||||
self.channel = nil
|
||||
try? self.group.syncShutdownGracefully()
|
||||
|
||||
let counterActor = self.counterActor
|
||||
Task {
|
||||
await self.counterActor.stop()
|
||||
await counterActor.stop()
|
||||
}
|
||||
|
||||
SDLLogger.log("[SDLUDPHole] stopped", for: .debug)
|
||||
|
||||
@ -118,9 +118,16 @@ final class SDLUDPHoleV6: ChannelInboundHandler {
|
||||
|
||||
self.messageContinuation.finish()
|
||||
self.eventContinuation.finish()
|
||||
|
||||
let channel = self.channel
|
||||
self.channel = nil
|
||||
try? channel?.close().wait()
|
||||
|
||||
try? self.group.syncShutdownGracefully()
|
||||
}
|
||||
|
||||
deinit {
|
||||
SDLLogger.log("[SDLUDPHoleV6] deinit", for: .debug)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user