fix quicClient
This commit is contained in:
parent
7b549981af
commit
2b234fb5c3
@ -268,12 +268,13 @@ actor SDLContextActor {
|
|||||||
|
|
||||||
await quicClient.start()
|
await quicClient.start()
|
||||||
|
|
||||||
|
do {
|
||||||
try await quicClient.waitReady(timeout: .seconds(3))
|
try await quicClient.waitReady(timeout: .seconds(3))
|
||||||
// 这里必须等待quic的协商完成
|
// 这里必须等待quic的协商完成
|
||||||
try await Task.sleep(for: .seconds(0.3))
|
try await Task.sleep(for: .seconds(0.3))
|
||||||
SDLLogger.log("[SDLContext] start quic client: \(self.config.serverHost)")
|
SDLLogger.log("[SDLContext] start quic client: \(self.config.serverHost)")
|
||||||
|
|
||||||
try await withTaskCancellationHandler{
|
try await withTaskCancellationHandler {
|
||||||
try await withThrowingTaskGroup { group in
|
try await withThrowingTaskGroup { group in
|
||||||
defer {
|
defer {
|
||||||
group.cancelAll()
|
group.cancelAll()
|
||||||
@ -286,6 +287,9 @@ actor SDLContextActor {
|
|||||||
}
|
}
|
||||||
await self.handleQUICMessage(message: message)
|
await self.handleQUICMessage(message: message)
|
||||||
}
|
}
|
||||||
|
if Task.isCancelled {
|
||||||
|
return
|
||||||
|
}
|
||||||
throw SDLQUICClientExit.transportClosed("messageStream finished")
|
throw SDLQUICClientExit.transportClosed("messageStream finished")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,9 +320,19 @@ actor SDLContextActor {
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if Task.isCancelled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
throw SDLQUICClientExit.transportClosed("eventStream finished")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
let _ = try await group.next()
|
let _ = try await group.next()
|
||||||
|
await quicClient.stop()
|
||||||
|
} catch {
|
||||||
|
await quicClient.stop()
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} onCancel: {
|
} onCancel: {
|
||||||
@ -326,6 +340,10 @@ actor SDLContextActor {
|
|||||||
await quicClient.stop()
|
await quicClient.stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
await quicClient.stop()
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleQUICMessage(message: SDLQUICInboundMessage) async {
|
private func handleQUICMessage(message: SDLQUICInboundMessage) async {
|
||||||
|
|||||||
@ -136,7 +136,6 @@ actor SDLQUICClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() async -> SDLQUICClientExit {
|
func run() async -> SDLQUICClientExit {
|
||||||
await withTaskCancellationHandler {
|
|
||||||
await withTaskGroup(of: SDLQUICClientExit.self) { group in
|
await withTaskGroup(of: SDLQUICClientExit.self) { group in
|
||||||
group.addTask {
|
group.addTask {
|
||||||
await self.readLoop()
|
await self.readLoop()
|
||||||
@ -148,16 +147,10 @@ actor SDLQUICClient {
|
|||||||
|
|
||||||
let exit = await group.next() ?? .normal
|
let exit = await group.next() ?? .normal
|
||||||
group.cancelAll()
|
group.cancelAll()
|
||||||
await self.stop()
|
|
||||||
self.finishStreams()
|
self.finishStreams()
|
||||||
|
|
||||||
return exit
|
return exit
|
||||||
}
|
}
|
||||||
} onCancel: {
|
|
||||||
Task {
|
|
||||||
await self.stop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func send(type: SDLPacketType, data: Data) {
|
func send(type: SDLPacketType, data: Data) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user