aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorCaleb Maclennan <caleb@alerque.com>2026-08-31 10:57:58 +0300
committerGitHub <noreply@github.com>2026-08-31 10:57:58 +0300
commit8f18ce95bb38c7f5c4bef5b3684cf1b0df1fc266 (patch)
treec11ae97c461d7f9c3cfe84773b9975de48d5ba9c /docs
parent535178a3f0e2cff59f4d59ee3a655bee263a5c90 (diff)
parent4863f32b358a8d533f629084a86fb4932ebbd2f3 (diff)
downloadluasocket-8f18ce95bb38c7f5c4bef5b3684cf1b0df1fc266.tar.gz
luasocket-8f18ce95bb38c7f5c4bef5b3684cf1b0df1fc266.tar.bz2
luasocket-8f18ce95bb38c7f5c4bef5b3684cf1b0df1fc266.zip
Merge pull request #463 from lunarmodules/feat/receive-limit
feat(receive): add maxsize argument to bound memory usage
Diffstat (limited to 'docs')
-rw-r--r--docs/tcp.html32
1 files changed, 22 insertions, 10 deletions
diff --git a/docs/tcp.html b/docs/tcp.html
index d223abf..715d28f 100644
--- a/docs/tcp.html
+++ b/docs/tcp.html
@@ -361,7 +361,7 @@ method returns <b><tt>nil</tt></b> followed by an error message.
361<!-- receive ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 361<!-- receive ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
362 362
363<p class="name" id="receive"> 363<p class="name" id="receive">
364client:<b>receive(</b>[pattern [, prefix]]<b>)</b> 364client:<b>receive(</b>[pattern [, prefix [, maxsize]]]<b>)</b>
365</p> 365</p>
366 366
367<p class="description"> 367<p class="description">
@@ -390,23 +390,35 @@ of bytes from the socket.</li>
390of any received data before return. 390of any received data before return.
391</p> 391</p>
392 392
393<p class="parameters">
394<tt>Maxsize</tt> is an optional positive integer bounding the number of
395payload bytes the call may accumulate, <em>including</em> <tt>prefix</tt>.
396Omitted or <tt><b>nil</b></tt> means unlimited.
397</p>
398
393<p class="return"> 399<p class="return">
394If successful, the method returns the received pattern. In case of error, 400If successful, the method returns the received pattern. In case of error,
395the method returns <tt><b>nil</b></tt> followed by an error 401the method returns <tt><b>nil</b></tt> followed by an error
396message, followed by a (possibly empty) string containing 402message, followed by a (possibly empty) string containing
397the partial that was received. The error message can be 403the partial that was received. The error message can be
398the string '<tt>closed</tt>' in case the connection was 404the string '<tt>closed</tt>' in case the connection was
399closed before the transmission was completed or the string 405closed before the transmission was completed.
400'<tt>timeout</tt>' in case there was a timeout during the operation. 406'<tt>timeout</tt>' indicates there was a timeout during the operation. And
407when <tt>maxsize</tt> was given, the string '<tt>oversized</tt>' in case
408the pattern did not complete within <tt>maxsize</tt> bytes (in which case
409the third return value holds exactly <tt>maxsize</tt> bytes).
401</p> 410</p>
402 411
403<p class="note"> 412<p class="note">
404<b>Important note</b>: This function was changed <em>severely</em>. It used 413Retrying with <tt>prefix</tt> set to the previous partial result and an
405to support multiple patterns (but I have never seen this feature used) and 414<em>unchanged</em> <tt>maxsize</tt> raises the length-check error above by
406now it doesn't anymore. Partial results used to be returned in the same 415design. A <tt>timeout</tt> partial is always strictly shorter
407way as successful results. This last feature violated the idea that all 416than <tt>maxsize</tt>, so it is always safe to feed straight back as
408functions should return <tt><b>nil</b></tt> on error. Thus it was changed 417<tt>prefix</tt> with the same <tt>maxsize</tt>. Finally, note that
409too. 418<tt>maxsize</tt> bounds the payload <em>returned</em>, not necessarily the
419bytes taken off the wire: for the <tt>*l</tt> pattern the discarded CR
420characters and the line terminator mean more bytes may have been consumed
421than the returned length suggests.
410</p> 422</p>
411 423
412<!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 424<!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->