Skip to content

Add retained TCP payload sends - #122

Merged
moratom merged 5 commits into
rvc2ng_developfrom
feat/tcp-retained-send
Nov 12, 2026
Merged

moratom merged 5 commits into
rvc2ng_developfrom
feat/tcp-retained-send

Conversation

@moratom

@moratom moratom commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Purpose

Allow XLink callers to send a shared payload over TCP while keeping its storage alive for the kernel, so a device can send camera frames over Ethernet without copying them.

Specification

Add an opt-in retained write with an owner release callback (XLinkWriteDataRetained) and the connection's totals (XLinkGetRetainedSendStats). Linux uses bounded MSG_ZEROCOPY submissions and reaps error-queue completions. Control bytes, unsupported sockets and older kernels keep the existing copy behavior. The wire format stays compatible with existing peers.

Dependencies & Potential Impact

The caller keeps payload bytes immutable until the release callback. If an aborted socket cannot drain, XLink keeps the outstanding leases and disables further zero-copy submissions for the process. Existing callers are unchanged.

This PR targets rvc2ng_develop, the long-running branch that depthai-core's rvc2ng_develop pins.

Deployment Plan

Callers opt in per write. Existing callers continue to use XLinkWriteData. depthai-core moves its XLink pin in a separate PR.

Testing & Validation

  • fix(tests): enable CTest at the top level: CI ran ctest in the build directory, which found no tests ("No tests were found" in every job), so no XLink test had run in CI. The tests now run in every job.
  • fix(tests): judge rtt_test by its median round trip: with the tests running, rtt_test failed on the shared macOS and Windows runners whenever one of its 10000 local round trips took over 5 ms (5 samples of 5-43 ms in a failing job). It now judges the median, which Nagle's algorithm or a delayed ACK still breaks: with TCP_NODELAY and TCP_QUICKACK removed it does not finish in 300 s. CI passes on every job of the matrix.
  • Linux, static, USB disabled: 14/14 tests pass, including tcp_retained_send_test, retained_stream_test and retained_stream_reset_test.
  • The reset regression test fails on the original implementation. It checks that reset returns an error and releases the owner if a queued write was never sent.
  • The copy fallback compiles with MSG_ZEROCOPY unavailable; the zero-copy test skips in that configuration.
  • The close-time totals moved from stdout to the debug log, so applications no longer print a line per closed connection.

AI Usage

Assisted by OpenAI Codex and Claude Code.

🤖 Generated with Claude Code

Matevz Morato and others added 4 commits November 6, 2026 19:11
Let the TCP connection retain each payload until the kernel releases its pages. Keep wire framing and the existing copy path available, and expose submitted, completed, and copied-send totals.

Test partial writes, completion ranges, abort, and a public retained stream round trip.
Every closed TCP connection printed its retained-send totals to stdout,
in every application that links XLink. XLinkGetRetainedSendStats gives a
caller the same numbers, so the close-time line moves to the debug log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI runs ctest in the build directory, which had no CTestTestfile because
only tests/ enabled testing, so every job printed "No tests were found"
and passed without running a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@moratom
moratom changed the base branch from feat/rvc2ng-receive-memory to rvc2ng_develop November 12, 2026 00:54
rtt_test failed when any one of its 10000 local round trips took over 5 ms.
Now that CI runs the tests, the shared macOS and Windows runners preempt a
few of them: the failing jobs saw 5 samples between 5 and 43 ms, the rest
far below. Nagle's algorithm or a delayed ACK, which the test guards
against, slows every round trip, so the median catches them: with
TCP_NODELAY and TCP_QUICKACK removed, the test does not finish within 300 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
moratom pushed a commit to luxonis/depthai-core that referenced this pull request Nov 12, 2026
XLink#122 gained a test fix: rtt_test judges its median round trip, so
XLink's CI, which now runs the tests, passes on macOS and Windows. The
library is unchanged from the previous pin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@moratom
moratom merged commit ff00e17 into rvc2ng_develop Nov 12, 2026
28 checks passed
@moratom
moratom deleted the feat/tcp-retained-send branch November 12, 2026 12:22
@themarpe

Copy link
Copy Markdown
Collaborator

@moratom - just a question, given XLinkWriteData is already blocking, do we need new/explicit API for this behavior?

@moratom

moratom commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

@moratom - just a question, given XLinkWriteData is already blocking, do we need new/explicit API for this behavior?

Good point, not in the happy path at least. The agent opted for a separate API for less risk & for the case of failure in case XLinkWriteData returns due to an error, where linux might still be reading the frame.

Safer to have a new flag / new function for now to avoid silently changing this on RVC4 / Core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants