diff --git a/Sources/Punchnet/SDLError.swift b/Sources/Punchnet/SDLError.swift new file mode 100644 index 0000000..3c95aac --- /dev/null +++ b/Sources/Punchnet/SDLError.swift @@ -0,0 +1,11 @@ +// +// SDLError.swift +// sdlan +// +// Created by 安礼成 on 2025/8/2. +// + +enum SDLError: Error { + case socketClosed + case socketError +} diff --git a/Sources/Punchnet/SDLNoticeClient.swift b/Sources/Punchnet/SDLNoticeClient.swift index 44cb4b3..7e5e785 100644 --- a/Sources/Punchnet/SDLNoticeClient.swift +++ b/Sources/Punchnet/SDLNoticeClient.swift @@ -47,6 +47,12 @@ actor SDLNoticeClient { func start() async throws { try await self.asyncChannel.executeThenClose { inbound, outbound in try await withThrowingTaskGroup(of: Void.self) { group in + group.addTask { + try await self.asyncChannel.channel.closeFuture.get() + NSLog("[UDPHole] channel closed") + throw SDLError.socketClosed + } + group.addTask { for try await message in self.writeStream { let buf = self.asyncChannel.channel.allocator.buffer(bytes: message) diff --git a/Sources/Punchnet/SDLSuperClient.swift b/Sources/Punchnet/SDLSuperClient.swift index 26546d8..ca86c77 100644 --- a/Sources/Punchnet/SDLSuperClient.swift +++ b/Sources/Punchnet/SDLSuperClient.swift @@ -9,6 +9,8 @@ import Foundation import NIOCore import NIOPosix + + // --MARK: 和SuperNode的客户端 actor SDLSuperClient { private let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) @@ -63,6 +65,7 @@ actor SDLSuperClient { group.addTask { try await self.asyncChannel.channel.closeFuture.get() NSLog("[SDLSuperClient] socket closed") + throw SDLError.socketClosed } group.addTask { diff --git a/Sources/Punchnet/SDLUDPHole.swift b/Sources/Punchnet/SDLUDPHole.swift index d58d250..08a649f 100644 --- a/Sources/Punchnet/SDLUDPHole.swift +++ b/Sources/Punchnet/SDLUDPHole.swift @@ -60,6 +60,7 @@ actor SDLUDPHole { group.addTask { try await self.asyncChannel.channel.closeFuture.get() NSLog("[UDPHole] channel closed") + throw SDLError.socketClosed } group.addTask { @@ -83,6 +84,7 @@ actor SDLUDPHole { } } catch let err { SDLLogger.log("[SDLUDPHole] decode message, get error: \(err)", level: .debug) + throw err } } }