diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2026-08-17 07:39:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-17 07:39:55 +0200 |
| commit | e912d157b242e661dca37d0a8269202dda974ba7 (patch) | |
| tree | 2bebbb8626abce49a4d3080956a417bacc69ab10 /docs | |
| parent | 73b0780321acb14bab6707006f5136ea9998951d (diff) | |
| download | luasocket-e912d157b242e661dca37d0a8269202dda974ba7.tar.gz luasocket-e912d157b242e661dca37d0a8269202dda974ba7.tar.bz2 luasocket-e912d157b242e661dca37d0a8269202dda974ba7.zip | |
chore(docs): some cleanup
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/tcp.html | 52 |
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, | |||
| 391 | the method returns <tt><b>nil</b></tt> followed by an error | 391 | the method returns <tt><b>nil</b></tt> followed by an error |
| 392 | message, followed by a (possibly empty) string containing | 392 | message, followed by a (possibly empty) string containing |
| 393 | the partial that was received. The error message can be | 393 | the partial that was received. The error message can be |
| 394 | the string '<tt>closed</tt>' in case the connection was | 394 | the string '<tt>closed</tt>' in case the connection was |
| 395 | closed before the transmission was completed, the string | 395 | closed 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 |
| 397 | when <tt>maxsize</tt> was given, the string '<tt>oversized</tt>' in case | 397 | when <tt>maxsize</tt> was given, the string '<tt>oversized</tt>' in case |
| 398 | the pattern did not complete within <tt>maxsize</tt> bytes -- in which case | 398 | the pattern did not complete within <tt>maxsize</tt> bytes (in which case |
| 399 | the third return value holds exactly <tt>maxsize</tt> bytes. | 399 | the 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 | ||
| 404 | to support multiple patterns (but I have never seen this feature used) and | ||
| 405 | now it doesn't anymore. Partial results used to be returned in the same | ||
| 406 | way as successful results. This last feature violated the idea that all | ||
| 407 | functions should return <tt><b>nil</b></tt> on error. Thus it was changed | ||
| 408 | too. | ||
| 409 | </p> | ||
| 410 | |||
| 411 | <p class="note"> | ||
| 412 | <b>Note on <tt>maxsize</tt></b>: passing a <tt>maxsize</tt> that is smaller | ||
| 413 | than 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 | ||
| 415 | than <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 | ||
| 417 | they are detected before any byte is read from the socket. To drain and | ||
| 418 | discard an oversized line while keeping memory bounded and the stream | ||
| 419 | aligned: | ||
| 420 | </p> | ||
| 421 | |||
| 422 | <pre class="example"> | ||
| 423 | local data, err, part | ||
| 424 | repeat | ||
| 425 | data, err, part = client:receive("*l", "", 4096) | ||
| 426 | until err ~= "oversized" | ||
| 427 | </pre> | ||
| 428 | |||
| 429 | <p class="note"> | ||
| 430 | To instead retry and eventually get the whole thing, carry the partial | ||
| 431 | forward as <tt>prefix</tt> and grow <tt>maxsize</tt>: | ||
| 432 | </p> | ||
| 433 | |||
| 434 | <pre class="example"> | ||
| 435 | local data, err, part = client:receive("*l", nil, 4096) | ||
| 436 | if err == "oversized" then | ||
| 437 | data, err, part = client:receive("*l", part, 65536) -- larger cap, or this raises | ||
| 438 | end | ||
| 439 | </pre> | ||
| 440 | |||
| 441 | <p class="note"> | ||
| 442 | Retrying with <tt>prefix</tt> set to the previous partial result and an | 403 | Retrying 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 |
| 444 | design -- otherwise it would be a zero-progress spin: no I/O, no timeout, | 405 | design. A <tt>timeout</tt> partial is always strictly shorter |
| 445 | no error, just CPU. A <tt>timeout</tt> partial is always strictly shorter | ||
| 446 | than <tt>maxsize</tt>, so it is always safe to feed straight back as | 406 | than <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 |
