clipboard: pace in-band chunks, 128 packets every 5 ms
A 1 MB payload is 21 846 packets. Handing them to ControlChannel.forward in one loop overruns the 512-packet outbox (contracts C3), which closes the connection, and puts a second of clipboard traffic ahead of the next mouse packet. Windows paces naturally because SendClipboardDataUsingTCP writes each packet down a blocking socket from its own thread (Clipboard.cs:260-305). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
dd26befe58
commit
4181bb273f
2 files changed
+71
-1
No files matched your search
@@ -224,6 +224,7 @@ public final class BulkChannel: @unchecked Sendable {
|
||||
// mwb/ClipboardBridge.swift
|
||||
public enum ClipboardAction: Sendable {
|
||||
case send(Packet) // the Engine stamps it (C1)
|
||||
case sendChunks(payload: Data, isImage: Bool) // paced, see beginChunkedSend
|
||||
case getRemoteClipboard(machine: String, postAction: UInt32)
|
||||
case pushClipboard(machine: String, postAction: UInt32)
|
||||
case commitFile(staged: URL, name: String)
|
||||
@@ -239,6 +240,8 @@ public final class ClipboardBridge { // Engine-isolated, not S
|
||||
-> [ClipboardAction]
|
||||
public func wantsRemoteClipboard(now: TimeInterval) -> [ClipboardAction]
|
||||
public func received(_ content: BulkReceived, from peerName: String) -> [ClipboardAction]
|
||||
public func beginChunkedSend(_ packets: [Packet],
|
||||
forward: @escaping @Sendable ([Packet]) async -> Void)
|
||||
public func announce(_ file: URL)
|
||||
}
|
||||
public final class ClipboardRelay: BulkSink, @unchecked Sendable {
|
||||
@@ -272,6 +275,15 @@ all deliberate:
|
||||
a poll can never interleave with a write and mistake a received
|
||||
clipboard for a local copy. AppKit documents the general pasteboard as
|
||||
usable off the main thread; it is a window-server object, not a view.
|
||||
- **In-band chunks are paced, 128 packets every 5 ms.** A 1 MB payload is
|
||||
21 846 packets; handing them to `ControlChannel.forward` in one loop
|
||||
overruns the 512-packet outbox contracts C3 allows and closes the
|
||||
connection, and puts a second of clipboard traffic in front of the next
|
||||
mouse packet. Windows paces naturally — `SendClipboardDataUsingTCP`
|
||||
writes each packet down a blocking socket from its own thread
|
||||
(`Clipboard.cs:260-305`) — and `beginChunkedSend` is that thread. A
|
||||
second copy cancels the first, because two interleaved payloads would
|
||||
arrive as one corrupt stream.
|
||||
- **`ReceivedFile` has `destinationURL()` (pure) beside
|
||||
`destinationDirectory()` (creates).** `BulkConfig` needs the path at
|
||||
startup, and nothing should appear on the user's Desktop until a file
|
||||
@@ -422,6 +434,11 @@ was not needed.
|
||||
twice (§10.7 note 11).
|
||||
- The download folder is created on the first received file, not at
|
||||
startup, so an app that never receives one leaves the Desktop alone.
|
||||
- In-band chunks are paced. Also found re-reading the first pass: the
|
||||
obvious `chunkPackets(...).map { .send($0) }` puts up to 21 846 packets
|
||||
into a 512-packet outbox at once, which contracts C3 answers by closing
|
||||
the connection — so anything over about 24 KB of clipboard would have
|
||||
killed the control connection instead of copying.
|
||||
|
||||
**Deviations from the brief.** Four one-line calls outside the strictly
|
||||
authorised set, all in `Sources/mwb/Engine.swift` and
|
||||
|
||||
Reference in new issue
Block a user