Skip to content

Remove allow_refill flag arguement from _oni_read_buffer#61

Open
jonnew wants to merge 2 commits into
mainfrom
4.6.0
Open

Remove allow_refill flag arguement from _oni_read_buffer#61
jonnew wants to merge 2 commits into
mainfrom
4.6.0

Conversation

@jonnew
Copy link
Copy Markdown
Member

@jonnew jonnew commented May 20, 2026

  • _oni_read_buffer was called twice in oni_read_frame: once for the frame header with allow_refill=1, and once for the payload with allow_refill=0. The flag was necessary because a second refill during the payload read would change ctx->shared_rbuf, breaking the single-buffer invariant that frames depend on.

  • The flag is unnecessary because _oni_read_buffer already refills to block_read_size bytes, and block_read_size >= max_read_frame_size >= max_data_size. After the header read the buffer is always guaranteed to hold the full payload, so a second refill can never occur. The payload read is now inlined in oni_read_frame.

  • The ONI_ENOREADDEV guard for max_read_frame_size == 0 is moved into _oni_read_buffer, which already uses that field as a refill threshold, making the function self-contained and allowing the NULL check on shared_rbuf within _oni_read_buffer to be removed.

- _oni_read_buffer was called twice in oni_read_frame: once for the frame
  header with allow_refill=1, and once for the payload with allow_refill=0.
  The flag was necessary because a second refill during the payload read
  would change ctx->shared_rbuf, breaking the single-buffer invariant that
  frames depend on.

- The flag is unnecessary because _oni_read_buffer already refills to
  block_read_size bytes, and block_read_size >= max_read_frame_size >=
  max_data_size. After the header read the buffer is always guaranteed to
  hold the full payload, so a second refill can never occur. The payload
  read is now inlined in oni_read_frame.

- The ONI_ENOREADDEV guard for max_read_frame_size == 0 is moved into
  _oni_read_buffer, which already uses that field as a refill threshold,
  making the function self-contained and allowing the NULL check on
  shared_rbuf within _oni_read_buffer to be removed.
@jonnew jonnew requested a review from aacuevas May 20, 2026 13:45
@aacuevas
Copy link
Copy Markdown
Collaborator

Since we are moving towards unnecessary parameters, and since now _oni_read_buffer is only called once with a size parameter of always ONI_RFRAMEHEADERSZ, shouldn't we take the opportunity to remove the size parameter altogether?

Maybe just rename it to something like int _oni_ensure_buffer(oni_ctx ctx) that performs the buffer allocation if necessary and adjust the pointers appropriately, and have oni_read_frame read the header through these pointers, as it already does for the payload.

Right now it reads the payload through the _oni_read_buffer returned pointer but then uses the context pointers for the payload, which seems odd.

- _oni_ensure_read_buffer is now a pure helper function that stictly refills the
  data buffer when required and does nothing otherwise
- Referencing data within the buffer to create data frame elements is
  now performed in oni_read_frame
- Other small changes to address compiler warnings and code consistency
@jonnew
Copy link
Copy Markdown
Member Author

jonnew commented May 21, 2026

This should be addressed in the latest commit.

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