Skip to content

Stop socket reads at EOF or the requested byte count - #649

Merged
bsergean merged 1 commit into
masterfrom
fix/socket-read-completion
Nov 17, 2026
Merged

bsergean merged 1 commit into
masterfrom
fix/socket-read-completion

Conversation

@bsergean

Copy link
Copy Markdown
Collaborator

Socket::readBytes() can keep retrying after a clean peer shutdown when the previous socket error is still would-block. It also polls for readability after receiving every requested byte, adding a wait or even turning a completed read into a poll error.

Treat a zero-byte receive as EOF regardless of the previous error, and only poll while bytes remain. The change is in the shared socket helper and applies to plain and TLS sockets without an API change.

Add in-memory tests for completed buffered/streamed reads, EOF with a stale would-block error, empty reads, and immediate cancellation. The fixture deliberately has no native descriptor so unnecessary readiness polling is detected. These tests have no network dependencies, sleeps, or timeout waits; every generated case measures under 1 ms locally.

Validation: three failing assertions on master before the fix; all 25 assertions pass afterward. Full plain-socket suite: 29/29 passed. Targeted ThreadSanitizer run passed. Strict C++11 production build with warnings as errors, formatting and diff checks passed. MinGW production/test syntax checks passed with pre-existing unrelated signedness/unused-parameter warnings suppressed.

@bsergean
bsergean merged commit 8f2f9ea into master Nov 17, 2026
13 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.

1 participant