[client] clipboard: reduce remote file transfer latency

Mark the last non-empty FILE_DATA payload with BEGIN and END when the
producer knows it is terminal. Complete producer bookkeeping in the
following fileDataEnd call without consuming another LGMP grant. Keep
the standalone terminal record for empty and legacy unknown streams.

Drain up to 64 queued clipboard records per worker pass instead of
sleeping after every message. Poll at 1 ms while transfers, blocked
writes, held input, or pending output are active, and retain the 10 ms
interval while idle.

This removes a serialized grant round trip from every non-empty file
response and reduces scheduling delay while a large transfer is active.
Keep the 1 MiB payload size because the bottleneck was stop-and-wait
latency, not the chunk capacity.

Exercise a full 1 MiB response in a single BEGIN|END grant and retain
coverage for empty unknown-size responses.
This commit is contained in:
Geoffrey McRae
2026-08-15 01:13:13 +10:00
parent f9ffce528a
commit 6631fde35f
7 changed files with 123 additions and 56 deletions

View File

@@ -2183,13 +2183,13 @@ LG_ClipboardResult lgClipboard_fileDataBegin(
LG_ClipboardResult lgClipboard_fileDataChunk(
const LG_ClipboardFileRequest * request, uint64_t responseOffset,
const void * data, size_t size)
const void * data, size_t size, bool end)
{
LG_ClipboardResult result = LG_CLIPBOARD_RESULT_FAILED;
LG_LOCK_SHARED(clipboard.activeLock);
if (clipboard.active.ops && clipboard.active.ops->fileDataChunk)
result = clipboard.active.ops->fileDataChunk(
clipboard.active.opaque, request, responseOffset, data, size);
clipboard.active.opaque, request, responseOffset, data, size, end);
LG_UNLOCK_SHARED(clipboard.activeLock);
return result;
}

View File

@@ -2764,7 +2764,7 @@ static struct LocalDataset * acquiredLocalDatasetNL(uint64_t wireDataset)
}
static bool sendJobCall(struct LocalJob * job, int operation,
uint64_t offset, const void * data, size_t size)
uint64_t offset, const void * data, size_t size, bool end)
{
for (;;)
{
@@ -2778,7 +2778,7 @@ static bool sendJobCall(struct LocalJob * job, int operation,
break;
case 1:
result = lgClipboard_fileDataChunk(
&job->request, offset, data, size);
&job->request, offset, data, size, end);
break;
default:
result = lgClipboard_fileDataEnd(&job->request, offset);
@@ -2796,7 +2796,7 @@ static bool sendJobCall(struct LocalJob * job, int operation,
static bool sendBufferJob(struct LocalJob * job,
const uint8_t * data, size_t size)
{
if (!sendJobCall(job, 0, size, NULL, 0))
if (!sendJobCall(job, 0, size, NULL, 0, false))
return false;
size_t offset = 0;
while (offset < size)
@@ -2804,11 +2804,12 @@ static bool sendBufferJob(struct LocalJob * job,
size_t chunk = size - offset;
if (chunk > FILE_STREAM_CHUNK)
chunk = FILE_STREAM_CHUNK;
if (!sendJobCall(job, 1, offset, data + offset, chunk))
const bool end = chunk == size - offset;
if (!sendJobCall(job, 1, offset, data + offset, chunk, end))
return false;
offset += chunk;
}
return sendJobCall(job, 2, size, NULL, 0);
return sendJobCall(job, 2, size, NULL, 0, true);
}
static LG_ClipboardFileError appendLocalEntry(uint8_t ** data, size_t * size,