From 9b5a05ce4e5051e8770e98d89fb810e247ce5001 Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 16 Sep 2026 04:59:50 -0700 Subject: [PATCH] clipboard: acceptHandshake returns Void; the handshake always ends the parse loop Co-Authored-By: Claude Opus 5 (1M context) --- Sources/MWBNet/BulkConnection.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/MWBNet/BulkConnection.swift b/Sources/MWBNet/BulkConnection.swift index b7c343c..0bee5f8 100644 --- a/Sources/MWBNet/BulkConnection.swift +++ b/Sources/MWBNet/BulkConnection.swift @@ -193,8 +193,10 @@ final class BulkConnection: @unchecked Sendable { switch phase { case .handshake: guard inbox.count >= packageSizeEx else { return } - let bytes = take(packageSizeEx) - guard acceptHandshake(bytes) else { return } + // Either way this ends the loop: the handshake is followed by a + // wait for the Engine's answer, or by failure. + acceptHandshake(take(packageSizeEx)) + return case .header: guard inbox.count >= ClipboardCodec.bulkHeaderSize else { return } @@ -225,7 +227,7 @@ final class BulkConnection: @unchecked Sendable { // MARK: - The handshake (`Clipboard.cs:996-1037`) - private func acceptHandshake(_ bytes: Data) -> Bool { + private func acceptHandshake(_ bytes: Data) { // The package is raw here, not framed: Windows assigns the four type // bytes straight into the struct (`DATA.cs:115-121`), so bytes 1..3 // must be zero or `Type` is not the value it looks like. @@ -235,7 +237,7 @@ final class BulkConnection: @unchecked Sendable { let name = packet.machineName, !name.isEmpty else { fail("clipboard handshake rejected") - return false + return } peerName = name peerID = packet.src @@ -251,7 +253,6 @@ final class BulkConnection: @unchecked Sendable { guard let self else { return } self.queue.async { self.authorised(allowed, peerPushes: peerPushes) } }) - return false } private func authorised(_ allowed: Bool, peerPushes: Bool) {