fix udpHole
This commit is contained in:
parent
e07c81567a
commit
a728fd5408
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// SDLUDPHoleHandler.swift
|
// SDLUDPHoleHandler.swift
|
||||||
// punchnet
|
// punchnet
|
||||||
//
|
// 上游的SDLUDPHole是基于actor实现的,串行实现的逻辑已经保证了SDLUDPHoleHandler的内部的一致性
|
||||||
// Created by 安礼成 on 2026/5/22.
|
// Created by 安礼成 on 2026/5/22.
|
||||||
//
|
//
|
||||||
import Foundation
|
import Foundation
|
||||||
@ -23,9 +23,6 @@ final class SDLUDPHoleHandler: ChannelInboundHandler {
|
|||||||
public let messageStream: AsyncThrowingStream<SDLHoleDatagram, Error>
|
public let messageStream: AsyncThrowingStream<SDLHoleDatagram, Error>
|
||||||
private let messageContinuation: AsyncThrowingStream<SDLHoleDatagram, Error>.Continuation
|
private let messageContinuation: AsyncThrowingStream<SDLHoleDatagram, Error>.Continuation
|
||||||
|
|
||||||
private let locker = NSLock()
|
|
||||||
private var isStopped: Bool = false
|
|
||||||
|
|
||||||
// 启动函数
|
// 启动函数
|
||||||
init() throws {
|
init() throws {
|
||||||
let (stream, continuation) = AsyncThrowingStream.makeStream(of: SDLHoleDatagram.self, bufferingPolicy: .bufferingNewest(2048))
|
let (stream, continuation) = AsyncThrowingStream.makeStream(of: SDLHoleDatagram.self, bufferingPolicy: .bufferingNewest(2048))
|
||||||
@ -102,16 +99,6 @@ final class SDLUDPHoleHandler: ChannelInboundHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stop() {
|
func stop() {
|
||||||
locker.lock()
|
|
||||||
defer {
|
|
||||||
locker.unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
guard !self.isStopped else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
self.isStopped = true
|
|
||||||
|
|
||||||
self.messageContinuation.finish()
|
self.messageContinuation.finish()
|
||||||
let channel = self.channel
|
let channel = self.channel
|
||||||
self.channel = nil
|
self.channel = nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user