Skip to content

u_send / u_recv - #998

Merged
gijzelaerr merged 19 commits into
gijzelaerr:masterfrom
hs2bws:u_send-/-u_recv
Nov 20, 2026
Merged

gijzelaerr merged 19 commits into
gijzelaerr:masterfrom
hs2bws:u_send-/-u_recv

Conversation

@hs2bws

@hs2bws hs2bws commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Support for u_send and u_recv:

  • u_send(number of blocks) for sending
  • b_recv() and as_b_recv() process both b_send and u_send data
  • 4 transmit and receive buffers instead of just 1 of each
  • Helper: set_u_send_data(data_1, data_2, data_3, data_4) and get_u_recv_data()

U-SEND and U-RECV communication with up to 4 data blocks. Sending: u_send(number of blocks). 
b_recv() and as_b_recv() process both b_send and u_send data.

Since the payload of `u_send` transmissions can be splitted into up to 4 parts, new helpers are required for the data buffers: 
- set_u_send_data(data_1, data_2, data_3, data_4)
- get_u_recv_data()
pre-commit fix
pre-commit fixes
pre-commit fixes
pre-commit fix
pre-commit fix
pre-commit fix
pre-commit fix
remove test_u_send_nodata

@gijzelaerr gijzelaerr left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @hs2bws. This is a solid second step. A plain BSend works exactly as before, set_recv_callback still takes one argument, and the parser tests use frames from your captures, so it's close.

What I checked:

  • The full suite, mypy, ruff and pre-commit pass on the branch.
  • _build_partner_data_pdu_u(b"\x3b\x00", b"\x00", b"\x3b", b"\x01\x00", 4, r_id=2) reproduces the captured 4-block frame from test_parse_partner_usend4_pdu byte for byte.
  • A plain b_send()/b_recv() round trip still returns the same data, and get_u_recv_data() reports block count 0 for it.

Two things need fixing:

  1. The size check in u_send() measures the wrong blocks. For blocks 2, 3 and 4 it uses len(self._send_data), the first block, instead of self._send_data2, _send_data3 and _send_data4. So a large second block passes the check: with a 1-byte first block, u_send(2) accepted a 2,000-byte second block and sent it, although the limit for a 480-byte PDU is 452 bytes. And a short block can be refused when the first one is long. A test that sends a block 2 over the limit and expects ValueError would pin this.
  2. The CHANGES.md entry is under 3.6.0, which was released this morning. Please move it to a new Unreleased section at the top. Two small things there: the list mixes a tab with spaces, and "splitted" should be "split".

Smaller points:

  • In _async_recv_loop, self._datablock_count = datablock_count should be self._recv_datablock_count. The queue carries the right value, so check_as_b_recv_completion() is fine, but the attribute name is a typo.
  • Could you add a test that builds the 1-block and 4-block frames and compares them with the captured bytes? Today only parsing is pinned to the captures.
  • If a USend frame arrives in the middle of a fragmented BSend, _b_recv_loop returns the USend data and drops the fragments it has collected so far. Is that what the CPUs do? If you don't know, raising an error there would be safer than silently losing data.

Once 1 and 2 are fixed, this can go in.

@hs2bws

hs2bws commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

I hope that everything is correct now. All points should be corrected.

@gijzelaerr gijzelaerr left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @hs2bws — everything from the last round is fixed. I re-checked on the branch: the size check in u_send() is now exact (452 bytes fit a 480-byte PDU, 453 are refused, also when split across two blocks), the build tests match your captures byte for byte, and a USend arriving mid-BSend now raises instead of dropping the fragments. Tests, mypy and ruff pass.

Two optional follow-ups, fine to leave for later: a test that an oversized block raises ValueError, and adding data 2–4 to the Returns line of _parse_partner_data_pdu's docstring. I'll squash-merge this.

@gijzelaerr
gijzelaerr merged commit 32fbafc into gijzelaerr:master Nov 20, 2026
17 checks passed
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