From 4b005cb75d2c4eda48faf3e5c9965a19688d10c6 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Wed, 27 May 2026 16:37:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=BB=E8=A6=81=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tun/Super/SDLSuperClient.swift | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/Tun/Super/SDLSuperClient.swift b/Tun/Super/SDLSuperClient.swift index 1dcbb7c..f4cbe1e 100644 --- a/Tun/Super/SDLSuperClient.swift +++ b/Tun/Super/SDLSuperClient.swift @@ -22,7 +22,6 @@ actor SDLSuperClient { // 数据流 public let messageStream: AsyncThrowingStream private let messageCont: AsyncThrowingStream.Continuation - private var isMessageContinuationFinished: Bool = false private var pendingConnectionError: Error? @@ -107,28 +106,15 @@ actor SDLSuperClient { self.state = .running case .failed(let error): self.pendingConnectionError = SDLSuperError.connectionFailed(error) - self.finishMessageContinuationIfNeed(throwing: .connectionFailed(error)) + self.messageCont.finish(throwing: SDLSuperError.connectionFailed(error)) case .cancelled: self.pendingConnectionError = SDLSuperError.connectionCancelled - self.finishMessageContinuationIfNeed(throwing: .connectionCancelled) + self.messageCont.finish(throwing: SDLSuperError.connectionCancelled) default: () } } - private func finishMessageContinuationIfNeed(throwing error: SDLSuperError?) { - guard !self.isMessageContinuationFinished else { - return - } - - self.isMessageContinuationFinished = true - if let error { - self.messageCont.finish(throwing: error) - } else { - self.messageCont.finish() - } - } - private func waitUntilReady() async throws { while true { try Task.checkCancellation() @@ -164,11 +150,12 @@ actor SDLSuperClient { } catch is CancellationError { throw CancellationError() } catch let error as SDLSuperError { - self.finishMessageContinuationIfNeed(throwing: error) + self.messageCont.finish(throwing: error) throw error } catch { let wrappedError = SDLSuperError.internalError(error) - self.finishMessageContinuationIfNeed(throwing: wrappedError) + self.messageCont.finish(throwing: wrappedError) + throw wrappedError } } @@ -187,7 +174,7 @@ actor SDLSuperClient { if let error { Task { SDLLogger.log("[SDLSuperClient] send data get error: \(error)", for: .debug) - await self?.finishMessageContinuationIfNeed(throwing: .writeFailed(error)) + self?.messageCont.finish(throwing: SDLSuperError.writeFailed(error)) } } }) @@ -231,8 +218,7 @@ actor SDLSuperClient { let connection = self.connection connection.stateUpdateHandler = nil connection.cancel() - - self.finishMessageContinuationIfNeed(throwing: nil) + self.messageCont.finish() SDLLogger.log("[SDLSuperClient] stopped") }