diff options
| author | Caleb Maclennan <caleb@alerque.com> | 2026-08-31 10:57:58 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-31 10:57:58 +0300 |
| commit | 8f18ce95bb38c7f5c4bef5b3684cf1b0df1fc266 (patch) | |
| tree | c11ae97c461d7f9c3cfe84773b9975de48d5ba9c /docs | |
| parent | 535178a3f0e2cff59f4d59ee3a655bee263a5c90 (diff) | |
| parent | 4863f32b358a8d533f629084a86fb4932ebbd2f3 (diff) | |
| download | luasocket-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.html | 32 |
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"> |
| 364 | client:<b>receive(</b>[pattern [, prefix]]<b>)</b> | 364 | client:<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> | |||
| 390 | of any received data before return. | 390 | of 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 | ||
| 395 | payload bytes the call may accumulate, <em>including</em> <tt>prefix</tt>. | ||
| 396 | Omitted or <tt><b>nil</b></tt> means unlimited. | ||
| 397 | </p> | ||
| 398 | |||
| 393 | <p class="return"> | 399 | <p class="return"> |
| 394 | If successful, the method returns the received pattern. In case of error, | 400 | If successful, the method returns the received pattern. In case of error, |
| 395 | the method returns <tt><b>nil</b></tt> followed by an error | 401 | the method returns <tt><b>nil</b></tt> followed by an error |
| 396 | message, followed by a (possibly empty) string containing | 402 | message, followed by a (possibly empty) string containing |
| 397 | the partial that was received. The error message can be | 403 | the partial that was received. The error message can be |
| 398 | the string '<tt>closed</tt>' in case the connection was | 404 | the string '<tt>closed</tt>' in case the connection was |
| 399 | closed before the transmission was completed or the string | 405 | closed 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 |
| 407 | when <tt>maxsize</tt> was given, the string '<tt>oversized</tt>' in case | ||
| 408 | the pattern did not complete within <tt>maxsize</tt> bytes (in which case | ||
| 409 | the 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 | 413 | Retrying with <tt>prefix</tt> set to the previous partial result and an |
| 405 | to 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 |
| 406 | now it doesn't anymore. Partial results used to be returned in the same | 415 | design. A <tt>timeout</tt> partial is always strictly shorter |
| 407 | way as successful results. This last feature violated the idea that all | 416 | than <tt>maxsize</tt>, so it is always safe to feed straight back as |
| 408 | functions 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 |
| 409 | too. | 418 | <tt>maxsize</tt> bounds the payload <em>returned</em>, not necessarily the |
| 419 | bytes taken off the wire: for the <tt>*l</tt> pattern the discarded CR | ||
| 420 | characters and the line terminator mean more bytes may have been consumed | ||
| 421 | than the returned length suggests. | ||
| 410 | </p> | 422 | </p> |
| 411 | 423 | ||
| 412 | <!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 424 | <!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
