Add TLS receive read-ahead support#31
Closed
Frauschi wants to merge 1 commit into
Closed
Conversation
Frauschi
commented
Jul 17, 2026
Frauschi
commented
Jul 17, 2026
Add WOLFSSL_TLS_READ_AHEAD (--enable-readahead), toggled at runtime via wolfSSL_set_read_ahead(). When enabled, the record-header read pulls a full record in one recv() so the body arrives without a second syscall. The receive window is configurable with wolfSSL_CTX/SSL_set_default_read_buffer_len() (OpenSSL-compatible): 0 keeps the one-record default, a larger value coalesces several records per recv(), a smaller value caps the per-connection buffer footprint. Records exceeding the window are still received correctly, the buffer grows on demand and is reallocated back down to the window afterwards so the retained footprint stays bounded. Includes docs, API tests, and a benchmark toggle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds TLS receive read-ahead support, gated behind
WOLFSSL_TLS_READ_AHEAD(
--enable-readahead) and toggled at runtime viawolfSSL_set_read_ahead().When enabled, the record-header read pulls a full record in one
recv()so thebody arrives without a second syscall.
The receive window is configurable with
wolfSSL_CTX/SSL_set_default_read_buffer_len()(OpenSSL-compatible):0keeps the one-record default,recv(),Records exceeding the window are still received correctly; the input buffer
grows on demand.
Includes docs, API tests, a benchmark toggle, and a bench script.
Branch state
Rebased onto current
master; single commit.Review fixes folded in
This branch already incorporates fixes for issues found in review:
clamped to
WOLFSSL_MAX_READ_AHEAD_SZ(16 MB) at the setters, so a largecaller-supplied size can no longer overflow the signed arithmetic in
GetInputData_ex()to a negative value (which would skipGrowInputBuffer()and drive an oversized
recv()), nor silently wrap thesize_t→word32store.
wolfSSL_has_pending()semantics: corrected the code comment and thedoc note — a non-zero return may reflect a partial (incomplete) record, so
the documented drain loop now advises calling
wolfSSL_read()untilWANT_READrather than looping onhas_pending()alone (which could spin).test_wolfSSL_read_ahead_ctx_inheritcovering theCTX-level setter/getter, CTX→SSL inheritance, NULL-argument paths, and the
clamp.
ssl.hwith the definitions inssl.cand the underlying struct members(excludes
OPENSSL_EXTRA_X509_SMALL, which never provided the fields).Testing
--enable-readahead --enable-debug: builds clean; the four read-ahead APItests pass (
test_wolfSSL_read_ahead,_coalesced,_buffer_len,_ctx_inherit).--enable-opensslextra(read-ahead off): builds clean; the read-ahead testscorrectly report skipped, exercising the setter clamp under the
OPENSSL_EXTRAguard path.