Skip to content

Return EOF once after the buffer is consumed#112

Merged
werwurm merged 3 commits into
mainfrom
werwurm/nat20device_eof
Jun 17, 2026
Merged

Return EOF once after the buffer is consumed#112
werwurm merged 3 commits into
mainfrom
werwurm/nat20device_eof

Conversation

@werwurm

@werwurm werwurm commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

The nat20 device now returns 0 on the first read after the entire response has been consumed to indicate EOF. Subsequent reads still return EAGAIN to indicate that a new request need to be issued before a new request can be read. The EOF state is cleared by a subsequent write even if the response was not or only partially read.

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

LCOV of commit 558f292 during lcov-test-coverage-report #257

Summary coverage rate:
  lines......: 95.6% (3048 of 3188 lines)
  functions..: 99.1% (232 of 234 functions)
  branches...: 87.1% (1658 of 1904 branches)

Files changed coverage rate: n/a

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adjusts the Linux nat20 character device read semantics to return a single EOF (0) once after the response buffer has been fully consumed, then revert to -EAGAIN until a new request is written.

Changes:

  • Add per-file-descriptor eof state to track “EOF already returned once” behavior.
  • Clear eof on write, and set eof when the response buffer becomes fully consumed.
  • Update read path to return 0 once after consumption before returning -EAGAIN on subsequent reads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/linux/nat20device/nat20device.c
Comment thread examples/linux/nat20device/nat20device.c Outdated
@werwurm werwurm requested review from Copilot and mjain02 June 16, 2026 18:08
@werwurm werwurm marked this pull request as ready for review June 16, 2026 18:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment on lines 226 to 229
/* Update offset */
*f_pos += bytes_to_read;

/* Response fully consumed — free it so subsequent reads
* return -EAGAIN until the next write/dispatch cycle. */
if (*f_pos >= file_priv->response.size) {
kfree(file_priv->response.data);
file_priv->response.data = NULL;
file_priv->response.size = 0;
}

ret = bytes_to_read;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So would a user space process, that doesn't or partially reads the response. Closing the file descriptor will also free the buffer.

Comment thread examples/linux/nat20device/nat20device.c Outdated
@werwurm werwurm requested a review from smacdude June 16, 2026 21:31
@werwurm werwurm merged commit eb78fde into main Jun 17, 2026
10 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.

3 participants