aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2026-08-17 07:39:55 +0200
committerGitHub <noreply@github.com>2026-08-17 07:39:55 +0200
commite912d157b242e661dca37d0a8269202dda974ba7 (patch)
tree2bebbb8626abce49a4d3080956a417bacc69ab10 /docs
parent73b0780321acb14bab6707006f5136ea9998951d (diff)
downloadluasocket-e912d157b242e661dca37d0a8269202dda974ba7.tar.gz
luasocket-e912d157b242e661dca37d0a8269202dda974ba7.tar.bz2
luasocket-e912d157b242e661dca37d0a8269202dda974ba7.zip
chore(docs): some cleanup
Diffstat (limited to 'docs')
-rw-r--r--docs/tcp.html52
1 files changed, 6 insertions, 46 deletions
diff --git a/docs/tcp.html b/docs/tcp.html
index 4c6c6bc..05bf1df 100644
--- a/docs/tcp.html
+++ b/docs/tcp.html
@@ -391,58 +391,18 @@ If successful, the method returns the received pattern. In case of error,
391the method returns <tt><b>nil</b></tt> followed by an error 391the method returns <tt><b>nil</b></tt> followed by an error
392message, followed by a (possibly empty) string containing 392message, followed by a (possibly empty) string containing
393the partial that was received. The error message can be 393the partial that was received. The error message can be
394the string '<tt>closed</tt>' in case the connection was 394the string '<tt>closed</tt>' in case the connection was
395closed before the transmission was completed, the string 395closed before the transmission was completed.
396'<tt>timeout</tt>' in case there was a timeout during the operation, or, 396'<tt>timeout</tt>' indicates there was a timeout during the operation. And
397when <tt>maxsize</tt> was given, the string '<tt>oversized</tt>' in case 397when <tt>maxsize</tt> was given, the string '<tt>oversized</tt>' in case
398the pattern did not complete within <tt>maxsize</tt> bytes -- in which case 398the pattern did not complete within <tt>maxsize</tt> bytes (in which case
399the third return value holds exactly <tt>maxsize</tt> bytes. 399the third return value holds exactly <tt>maxsize</tt> bytes).
400</p> 400</p>
401 401
402<p class="note"> 402<p class="note">
403<b>Important note</b>: This function was changed <em>severely</em>. It used
404to support multiple patterns (but I have never seen this feature used) and
405now it doesn't anymore. Partial results used to be returned in the same
406way as successful results. This last feature violated the idea that all
407functions should return <tt><b>nil</b></tt> on error. Thus it was changed
408too.
409</p>
410
411<p class="note">
412<b>Note on <tt>maxsize</tt></b>: passing a <tt>maxsize</tt> that is smaller
413than 1, a <tt>prefix</tt> whose length is greater than or equal to
414<tt>maxsize</tt>, or, for a numeric <tt>pattern</tt>, a byte count greater
415than <tt>maxsize</tt>, all raise a Lua error rather than returning
416<tt><b>nil</b></tt> plus a message -- these are caller logic errors, and
417they are detected before any byte is read from the socket. To drain and
418discard an oversized line while keeping memory bounded and the stream
419aligned:
420</p>
421
422<pre class="example">
423local data, err, part
424repeat
425 data, err, part = client:receive("*l", "", 4096)
426until err ~= "oversized"
427</pre>
428
429<p class="note">
430To instead retry and eventually get the whole thing, carry the partial
431forward as <tt>prefix</tt> and grow <tt>maxsize</tt>:
432</p>
433
434<pre class="example">
435local data, err, part = client:receive("*l", nil, 4096)
436if err == "oversized" then
437 data, err, part = client:receive("*l", part, 65536) -- larger cap, or this raises
438end
439</pre>
440
441<p class="note">
442Retrying with <tt>prefix</tt> set to the previous partial result and an 403Retrying with <tt>prefix</tt> set to the previous partial result and an
443<em>unchanged</em> <tt>maxsize</tt> raises the length-check error above by 404<em>unchanged</em> <tt>maxsize</tt> raises the length-check error above by
444design -- otherwise it would be a zero-progress spin: no I/O, no timeout, 405design. A <tt>timeout</tt> partial is always strictly shorter
445no error, just CPU. A <tt>timeout</tt> partial is always strictly shorter
446than <tt>maxsize</tt>, so it is always safe to feed straight back as 406than <tt>maxsize</tt>, so it is always safe to feed straight back as
447<tt>prefix</tt> with the same <tt>maxsize</tt>. Finally, note that 407<tt>prefix</tt> with the same <tt>maxsize</tt>. Finally, note that
448<tt>maxsize</tt> bounds the payload <em>returned</em>, not necessarily the 408<tt>maxsize</tt> bounds the payload <em>returned</em>, not necessarily the