Compare commits

..

No commits in common. "6cb8641869eabbb73564a6a8dc3d2ddaabd60eb5" and "3e961696907fbd1f254d7743f47600aaa659b759" have entirely different histories.

3 changed files with 9 additions and 30 deletions

View File

@ -120,7 +120,7 @@ public class SDLContext: @unchecked Sendable {
do { do {
try await self.startSuperClient() try await self.startSuperClient()
} catch let err { } catch let err {
NSLog("[SDLContext] SuperClient get error: \(err), will restart") NSLog("SuperClient get error: \(err)")
await self.arpServer.clear() await self.arpServer.clear()
try? await Task.sleep(for: .seconds(2)) try? await Task.sleep(for: .seconds(2))
} }

View File

@ -9,6 +9,8 @@ import Foundation
import NIOCore import NIOCore
import NIOPosix import NIOPosix
// --MARK: SuperNode // --MARK: SuperNode
actor SDLSuperClient { actor SDLSuperClient {
private let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) private let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
@ -67,10 +69,6 @@ actor SDLSuperClient {
} }
group.addTask { group.addTask {
defer {
self.inboundContinuation.finish()
}
for try await var packet in inbound { for try await var packet in inbound {
if let message = SDLSuperClientDecoder.decode(buffer: &packet) { if let message = SDLSuperClientDecoder.decode(buffer: &packet) {
SDLLogger.log("[SDLSuperTransport] read message: \(message)", level: .warning) SDLLogger.log("[SDLSuperTransport] read message: \(message)", level: .warning)
@ -84,14 +82,9 @@ actor SDLSuperClient {
} }
} }
} }
NSLog("[SDLSuperClient] inbound closed")
} }
group.addTask { group.addTask {
defer {
self.writeContinuation.finish()
}
for try await message in self.writeStream { for try await message in self.writeStream {
var buffer = self.asyncChannel.channel.allocator.buffer(capacity: message.data.count + 5) var buffer = self.asyncChannel.channel.allocator.buffer(capacity: message.data.count + 5)
buffer.writeInteger(message.packetId, as: UInt32.self) buffer.writeInteger(message.packetId, as: UInt32.self)
@ -99,28 +92,17 @@ actor SDLSuperClient {
buffer.writeBytes(message.data) buffer.writeBytes(message.data)
try await outbound.write(buffer) try await outbound.write(buffer)
} }
NSLog("[SDLSuperClient] outbound closed")
} }
// --MARK: // --MARK:
group.addTask { group.addTask {
while true { while !Task.isCancelled {
do {
await self.ping() await self.ping()
try await Task.sleep(nanoseconds: 5 * 1_000_000_000) try? await Task.sleep(nanoseconds: 5 * 1_000_000_000)
} catch let err {
NSLog("[SDLSuperClient] heartbeat cancelled with error: \(err)")
break
}
} }
} }
// 退, try await group.waitForAll()
for try await _ in group {
}
NSLog("[SDLSuperClient] group closed")
} }
} }
} }
@ -200,6 +182,7 @@ actor SDLSuperClient {
deinit { deinit {
try! group.syncShutdownGracefully() try! group.syncShutdownGracefully()
self.inboundContinuation.finish()
} }
} }

View File

@ -100,11 +100,7 @@ actor SDLUDPHole {
} }
} }
for try await _ in group { try await group.waitForAll()
}
SDLLogger.log("[SDLUDPHole] group closed", level: .debug)
} }
} }
} }