diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2026-07-30 19:22:17 +0200 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2026-07-30 22:06:04 +0200 |
| commit | 73b0780321acb14bab6707006f5136ea9998951d (patch) | |
| tree | 30c5d0cff89913185df7f5fb7ebe1636827cfd58 /src/wsocket.c | |
| parent | e13de2013749961edaa126697f3290d3dca91823 (diff) | |
| download | luasocket-73b0780321acb14bab6707006f5136ea9998951d.tar.gz luasocket-73b0780321acb14bab6707006f5136ea9998951d.tar.bz2 luasocket-73b0780321acb14bab6707006f5136ea9998951d.zip | |
feat(receive): add maxsize argument to bound memory usage
client:receive("*l") and receive("*a") are unbounded: a peer that never
sends a newline, or never closes, makes LuaSocket buffer until the
process runs out of memory (e.g. src/http.lua reading response headers
in a loop). Add an optional maxsize argument that caps the payload a
single call may accumulate, including prefix.
- Hoist all argument validation ahead of timeout_markstart() so bad
calls (maxsize < 1, #prefix >= maxsize, numeric pattern > maxsize)
raise before any I/O and leave the socket untouched.
- recvline/recvall take a budget and return a new internal
BUF_OVERSIZED code, surfaced to Lua as the "oversized" error
alongside "timeout"/"closed", with the partial held in the 3rd
return value.
- recvraw is left untouched: argument checks make the cap unreachable
for numeric patterns.
- Preserve three invariants: a timeout partial is always shorter than
maxsize (safe to retry as prefix), completion beats the cap for *a,
and no bytes are lost or skipped on overflow.
- tcp.c, unixstream.c and serial.c all share this code path unchanged.
Adds test coverage (argument errors, *l/*a boundaries, timeout/close
at the cap, the drain idiom, numeric patterns, unix-stream mirror) and
documents the new argument, error, and recovery idioms in docs/tcp.html.
Diffstat (limited to 'src/wsocket.c')
0 files changed, 0 insertions, 0 deletions
