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