diff options
| author | Caleb Maclennan <caleb@alerque.com> | 2022-03-24 18:11:07 +0300 |
|---|---|---|
| committer | Caleb Maclennan <caleb@alerque.com> | 2022-03-24 18:11:07 +0300 |
| commit | 2de8ddfbb837a75b1cb5f09a656379c1e7cc589c (patch) | |
| tree | 20b5f7b8a48d1c126763daca3860fcfb7c3b59a7 /docs/tcp.html | |
| parent | f9e1d03f3c6c9fc59dd3b91716debc23aebf947f (diff) | |
| parent | 5ed8b66e6d0c295f95fade159ada0f97f482b2ac (diff) | |
| download | luasocket-2de8ddfbb837a75b1cb5f09a656379c1e7cc589c.tar.gz luasocket-2de8ddfbb837a75b1cb5f09a656379c1e7cc589c.tar.bz2 luasocket-2de8ddfbb837a75b1cb5f09a656379c1e7cc589c.zip | |
Merge remote-tracking branch 'upstream/master' into test-builds
Diffstat (limited to 'docs/tcp.html')
| -rw-r--r-- | docs/tcp.html | 732 |
1 files changed, 732 insertions, 0 deletions
diff --git a/docs/tcp.html b/docs/tcp.html new file mode 100644 index 0000000..9cc173e --- /dev/null +++ b/docs/tcp.html | |||
| @@ -0,0 +1,732 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <meta name="description" content="LuaSocket: The TCP/IP support"> | ||
| 7 | <meta name="keywords" content="Lua, LuaSocket, Socket, TCP, Library, Network, Support"> | ||
| 8 | <title>LuaSocket: TCP/IP support</title> | ||
| 9 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 10 | </head> | ||
| 11 | |||
| 12 | <body> | ||
| 13 | |||
| 14 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 15 | |||
| 16 | <div class="header"> | ||
| 17 | <hr> | ||
| 18 | <center> | ||
| 19 | <table summary="LuaSocket logo"> | ||
| 20 | <tr><td align="center"><a href="http://www.lua.org"> | ||
| 21 | <img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png"> | ||
| 22 | </a></td></tr> | ||
| 23 | <tr><td align="center" valign="top">Network support for the Lua language | ||
| 24 | </td></tr> | ||
| 25 | </table> | ||
| 26 | <p class="bar"> | ||
| 27 | <a href="index.html">home</a> · | ||
| 28 | <a href="index.html#download">download</a> · | ||
| 29 | <a href="installation.html">installation</a> · | ||
| 30 | <a href="introduction.html">introduction</a> · | ||
| 31 | <a href="reference.html">reference</a> | ||
| 32 | </p> | ||
| 33 | </center> | ||
| 34 | <hr> | ||
| 35 | </div> | ||
| 36 | |||
| 37 | <!-- tcp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 38 | |||
| 39 | <h2 id="tcp">TCP</h2> | ||
| 40 | |||
| 41 | <!-- accept +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 42 | |||
| 43 | <p class="name" id="accept"> | ||
| 44 | server:<b>accept()</b> | ||
| 45 | </p> | ||
| 46 | |||
| 47 | <p class="description"> | ||
| 48 | Waits for a remote connection on the server | ||
| 49 | object and returns a client object representing that connection. | ||
| 50 | </p> | ||
| 51 | |||
| 52 | <p class="return"> | ||
| 53 | If a connection is successfully initiated, a client object is returned. | ||
| 54 | If a timeout condition is met, the method returns <b><tt>nil</tt></b> | ||
| 55 | followed by the error string '<tt>timeout</tt>'. Other errors are | ||
| 56 | reported by <b><tt>nil</tt></b> followed by a message describing the error. | ||
| 57 | </p> | ||
| 58 | |||
| 59 | <p class="note"> | ||
| 60 | Note: calling <a href="socket.html#select"><tt>socket.select</tt></a> | ||
| 61 | with a server object in | ||
| 62 | the <tt>recvt</tt> parameter before a call to <tt>accept</tt> does | ||
| 63 | <em>not</em> guarantee <tt>accept</tt> will return immediately. Use the <a | ||
| 64 | href="#settimeout"><tt>settimeout</tt></a> method or <tt>accept</tt> | ||
| 65 | might block until <em>another</em> client shows up. | ||
| 66 | </p> | ||
| 67 | |||
| 68 | <!-- bind +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 69 | |||
| 70 | <p class="name" id="bind"> | ||
| 71 | master:<b>bind(</b>address, port<b>)</b> | ||
| 72 | </p> | ||
| 73 | |||
| 74 | <p class="description"> | ||
| 75 | Binds a master object to <tt>address</tt> and <tt>port</tt> on the | ||
| 76 | local host. | ||
| 77 | </p> | ||
| 78 | |||
| 79 | <p class="parameters"> | ||
| 80 | <tt>Address</tt> can be an IP address or a host name. | ||
| 81 | <tt>Port</tt> must be an integer number in the range [0..64K). | ||
| 82 | If <tt>address</tt> | ||
| 83 | is '<tt>*</tt>', the system binds to all local interfaces | ||
| 84 | using the <tt>INADDR_ANY</tt> constant or | ||
| 85 | <tt>IN6ADDR_ANY_INIT</tt>, according to the family. | ||
| 86 | If <tt>port</tt> is 0, the system automatically | ||
| 87 | chooses an ephemeral port. | ||
| 88 | </p> | ||
| 89 | |||
| 90 | <p class="return"> | ||
| 91 | In case of success, the method returns 1. In case of error, the | ||
| 92 | method returns <b><tt>nil</tt></b> followed by an error message. | ||
| 93 | </p> | ||
| 94 | |||
| 95 | <p class="note"> | ||
| 96 | Note: The function <a href="socket.html#bind"><tt>socket.bind</tt></a> | ||
| 97 | is available and is a shortcut for the creation of server sockets. | ||
| 98 | </p> | ||
| 99 | |||
| 100 | <!-- close ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 101 | |||
| 102 | <p class="name" id="close"> | ||
| 103 | master:<b>close()</b><br> | ||
| 104 | client:<b>close()</b><br> | ||
| 105 | server:<b>close()</b> | ||
| 106 | </p> | ||
| 107 | |||
| 108 | <p class="description"> | ||
| 109 | Closes a TCP object. The internal socket used by the object is closed | ||
| 110 | and the local address to which the object was | ||
| 111 | bound is made available to other applications. No further operations | ||
| 112 | (except for further calls to the <tt>close</tt> method) are allowed on | ||
| 113 | a closed socket. | ||
| 114 | </p> | ||
| 115 | |||
| 116 | <p class="note"> | ||
| 117 | Note: It is important to close all used sockets once they are not | ||
| 118 | needed, since, in many systems, each socket uses a file descriptor, | ||
| 119 | which are limited system resources. Garbage-collected objects are | ||
| 120 | automatically closed before destruction, though. | ||
| 121 | </p> | ||
| 122 | |||
| 123 | <!-- connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 124 | |||
| 125 | <p class="name" id="connect"> | ||
| 126 | master:<b>connect(</b>address, port<b>)</b> | ||
| 127 | </p> | ||
| 128 | |||
| 129 | <p class="description"> | ||
| 130 | Attempts to connect a master object to a remote host, transforming it into a | ||
| 131 | client object. | ||
| 132 | Client objects support methods | ||
| 133 | <a href="#send"><tt>send</tt></a>, | ||
| 134 | <a href="#receive"><tt>receive</tt></a>, | ||
| 135 | <a href="#getsockname"><tt>getsockname</tt></a>, | ||
| 136 | <a href="#getpeername"><tt>getpeername</tt></a>, | ||
| 137 | <a href="#settimeout"><tt>settimeout</tt></a>, | ||
| 138 | and <a href="#close"><tt>close</tt></a>. | ||
| 139 | </p> | ||
| 140 | |||
| 141 | <p class="parameters"> | ||
| 142 | <tt>Address</tt> can be an IP address or a host name. | ||
| 143 | <tt>Port</tt> must be an integer number in the range [1..64K). | ||
| 144 | </p> | ||
| 145 | |||
| 146 | <p class="return"> | ||
| 147 | In case of error, the method returns <b><tt>nil</tt></b> followed by a string | ||
| 148 | describing the error. In case of success, the method returns 1. | ||
| 149 | </p> | ||
| 150 | |||
| 151 | <p class="note"> | ||
| 152 | Note: The function <a href="socket.html#connect"><tt>socket.connect</tt></a> | ||
| 153 | is available and is a shortcut for the creation of client sockets. | ||
| 154 | </p> | ||
| 155 | |||
| 156 | <p class="note"> | ||
| 157 | Note: Starting with LuaSocket 2.0, | ||
| 158 | the <a href="#settimeout"><tt>settimeout</tt></a> | ||
| 159 | method affects the behavior of <tt>connect</tt>, causing it to return | ||
| 160 | with an error in case of a timeout. If that happens, you can still call <a | ||
| 161 | href="socket.html#select"><tt>socket.select</tt></a> with the socket in the | ||
| 162 | <tt>sendt</tt> table. The socket will be writable when the connection is | ||
| 163 | established. | ||
| 164 | </p> | ||
| 165 | |||
| 166 | <p class="note"> | ||
| 167 | Note: Starting with LuaSocket 3.0, the host name resolution | ||
| 168 | depends on whether the socket was created by | ||
| 169 | <a href="#socket.tcp"><tt>socket.tcp</tt></a>, | ||
| 170 | <a href="#socket.tcp4"><tt>socket.tcp4</tt></a> or | ||
| 171 | <a href="#socket.tcp6"><tt>socket.tcp6</tt></a>. Addresses from | ||
| 172 | the appropriate family (or both) are tried in the order | ||
| 173 | returned by the resolver until the | ||
| 174 | first success or until the last failure. If the timeout was | ||
| 175 | set to zero, only the first address is tried. | ||
| 176 | </p> | ||
| 177 | |||
| 178 | <!-- dirty +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 179 | |||
| 180 | <p class="name" id="dirty"> | ||
| 181 | master:<b>dirty()</b><br> | ||
| 182 | client:<b>dirty()</b><br> | ||
| 183 | server:<b>dirty()</b> | ||
| 184 | </p> | ||
| 185 | |||
| 186 | <p class="description"> | ||
| 187 | Check the read buffer status. | ||
| 188 | </p> | ||
| 189 | |||
| 190 | <p class="return"> | ||
| 191 | Returns <tt>true</tt> if there is any data in the read buffer, <tt>false</tt> otherwise. | ||
| 192 | </p> | ||
| 193 | |||
| 194 | <p class="note"> | ||
| 195 | Note: <b>This is an internal method, use at your own risk.</b> | ||
| 196 | </p> | ||
| 197 | |||
| 198 | |||
| 199 | <!-- getfd +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 200 | |||
| 201 | <p class="name" id="getfd"> | ||
| 202 | master:<b>getfd()</b><br> | ||
| 203 | client:<b>getfd()</b><br> | ||
| 204 | server:<b>getfd()</b> | ||
| 205 | </p> | ||
| 206 | |||
| 207 | <p class="description"> | ||
| 208 | Returns the underling socket descriptor or handle associated to the object. | ||
| 209 | </p> | ||
| 210 | |||
| 211 | <p class="return"> | ||
| 212 | The descriptor or handle. In case the object has been closed, the return value | ||
| 213 | will be -1. For an invalid socket it will be <a href="socket.html#socketinvalid"> | ||
| 214 | <tt>_SOCKETINVALID</tt></a>. | ||
| 215 | </p> | ||
| 216 | |||
| 217 | <p class="note"> | ||
| 218 | Note: <b>This is an internal method. Unlikely to be | ||
| 219 | portable. Use at your own risk. </b> | ||
| 220 | </p> | ||
| 221 | |||
| 222 | |||
| 223 | <!-- getoption ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 224 | |||
| 225 | <p class="name" id="getoption"> | ||
| 226 | client:<b>getoption(option)</b><br> | ||
| 227 | server:<b>getoption(option)</b> | ||
| 228 | </p> | ||
| 229 | |||
| 230 | <p class="description"> | ||
| 231 | Gets options for the TCP object. | ||
| 232 | See <a href="#setoption"><tt>setoption</tt></a> for description of the | ||
| 233 | option names and values. | ||
| 234 | </p> | ||
| 235 | |||
| 236 | <p class="parameters"> | ||
| 237 | <tt>Option</tt> is a string with the option name.</p> | ||
| 238 | <ul> | ||
| 239 | <li> '<tt>keepalive</tt>'</li> | ||
| 240 | <li> '<tt>linger</tt>'</li> | ||
| 241 | <li> '<tt>reuseaddr</tt>'</li> | ||
| 242 | <li> '<tt>tcp-nodelay</tt>'</li> | ||
| 243 | </ul> | ||
| 244 | |||
| 245 | <p class="return"> | ||
| 246 | The method returns the option <tt>value</tt> in case of success, or | ||
| 247 | <b><tt>nil</tt></b> followed by an error message otherwise. | ||
| 248 | </p> | ||
| 249 | |||
| 250 | |||
| 251 | <!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 252 | |||
| 253 | <p class="name" id="getpeername"> | ||
| 254 | client:<b>getpeername()</b> | ||
| 255 | </p> | ||
| 256 | |||
| 257 | <p class="description"> | ||
| 258 | Returns information about the remote side of a connected client object. | ||
| 259 | </p> | ||
| 260 | |||
| 261 | <p class="return"> | ||
| 262 | Returns a string with the IP address of the peer, the | ||
| 263 | port number that peer is using for the connection, | ||
| 264 | and a string with the family ("<tt>inet</tt>" or "<tt>inet6</tt>"). | ||
| 265 | In case of error, the method returns <b><tt>nil</tt></b>. | ||
| 266 | </p> | ||
| 267 | |||
| 268 | <p class="note"> | ||
| 269 | Note: It makes no sense to call this method on server objects. | ||
| 270 | </p> | ||
| 271 | |||
| 272 | <!-- getsockname ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 273 | |||
| 274 | <p class="name" id="getsockname"> | ||
| 275 | master:<b>getsockname()</b><br> | ||
| 276 | client:<b>getsockname()</b><br> | ||
| 277 | server:<b>getsockname()</b> | ||
| 278 | </p> | ||
| 279 | |||
| 280 | <p class="description"> | ||
| 281 | Returns the local address information associated to the object. | ||
| 282 | </p> | ||
| 283 | |||
| 284 | <p class="return"> | ||
| 285 | The method returns a string with local IP address, a number with | ||
| 286 | the local port, | ||
| 287 | and a string with the family ("<tt>inet</tt>" or "<tt>inet6</tt>"). | ||
| 288 | In case of error, the method returns <b><tt>nil</tt></b>. | ||
| 289 | </p> | ||
| 290 | |||
| 291 | <!-- getstats +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 292 | |||
| 293 | <p class="name" id="getstats"> | ||
| 294 | master:<b>getstats()</b><br> | ||
| 295 | client:<b>getstats()</b><br> | ||
| 296 | server:<b>getstats()</b><br> | ||
| 297 | </p> | ||
| 298 | |||
| 299 | <p class="description"> | ||
| 300 | Returns accounting information on the socket, useful for throttling | ||
| 301 | of bandwidth. | ||
| 302 | </p> | ||
| 303 | |||
| 304 | <p class="return"> | ||
| 305 | The method returns the number of bytes received, the number of bytes sent, | ||
| 306 | and the age of the socket object in seconds. | ||
| 307 | </p> | ||
| 308 | |||
| 309 | <!-- gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 310 | |||
| 311 | <p class="name" id="gettimeout"> | ||
| 312 | master:<b>gettimeout()</b><br> | ||
| 313 | client:<b>gettimeout()</b><br> | ||
| 314 | server:<b>gettimeout()</b> | ||
| 315 | </p> | ||
| 316 | |||
| 317 | <p class="description"> | ||
| 318 | Returns the current block timeout followed by the curent | ||
| 319 | total timeout. | ||
| 320 | </p> | ||
| 321 | |||
| 322 | |||
| 323 | <!-- listen ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 324 | |||
| 325 | <p class="name" id="listen"> | ||
| 326 | master:<b>listen(</b>backlog<b>)</b> | ||
| 327 | </p> | ||
| 328 | |||
| 329 | <p class="description"> | ||
| 330 | Specifies the socket is willing to receive connections, transforming the | ||
| 331 | object into a server object. Server objects support the | ||
| 332 | <a href="#accept"><tt>accept</tt></a>, | ||
| 333 | <a href="#getsockname"><tt>getsockname</tt></a>, | ||
| 334 | <a href="#setoption"><tt>setoption</tt></a>, | ||
| 335 | <a href="#settimeout"><tt>settimeout</tt></a>, | ||
| 336 | and <a href="#close"><tt>close</tt></a> methods. | ||
| 337 | </p> | ||
| 338 | |||
| 339 | <p class="parameters"> | ||
| 340 | The parameter <tt>backlog</tt> specifies the number of client | ||
| 341 | connections that can | ||
| 342 | be queued waiting for service. If the queue is full and another client | ||
| 343 | attempts connection, the connection is refused. | ||
| 344 | </p> | ||
| 345 | |||
| 346 | <p class="return"> | ||
| 347 | In case of success, the method returns 1. In case of error, the | ||
| 348 | method returns <b><tt>nil</tt></b> followed by an error message. | ||
| 349 | </p> | ||
| 350 | |||
| 351 | <!-- receive ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 352 | |||
| 353 | <p class="name" id="receive"> | ||
| 354 | client:<b>receive(</b>[pattern [, prefix]]<b>)</b> | ||
| 355 | </p> | ||
| 356 | |||
| 357 | <p class="description"> | ||
| 358 | Reads data from a client object, according to the specified <em>read | ||
| 359 | pattern</em>. Patterns follow the Lua file I/O format, and the difference in performance between all patterns is negligible. | ||
| 360 | </p> | ||
| 361 | |||
| 362 | <p class="parameters"> | ||
| 363 | <tt>Pattern</tt> can be any of the following: | ||
| 364 | </p> | ||
| 365 | |||
| 366 | <ul> | ||
| 367 | <li> '<tt>*a</tt>': reads from the socket until the connection is | ||
| 368 | closed. No end-of-line translation is performed;</li> | ||
| 369 | <li> '<tt>*l</tt>': reads a line of text from the socket. The line is | ||
| 370 | terminated by a LF character (ASCII 10), optionally preceded by a | ||
| 371 | CR character (ASCII 13). The CR and LF characters are not included in | ||
| 372 | the returned line. In fact, <em>all</em> CR characters are | ||
| 373 | ignored by the pattern. This is the default pattern;</li> | ||
| 374 | <li> <tt>number</tt>: causes the method to read a specified <tt>number</tt> | ||
| 375 | of bytes from the socket.</li> | ||
| 376 | </ul> | ||
| 377 | |||
| 378 | <p class="parameters"> | ||
| 379 | <tt>Prefix</tt> is an optional string to be concatenated to the beginning | ||
| 380 | of any received data before return. | ||
| 381 | </p> | ||
| 382 | |||
| 383 | <p class="return"> | ||
| 384 | If successful, the method returns the received pattern. In case of error, | ||
| 385 | the method returns <tt><b>nil</b></tt> followed by an error | ||
| 386 | message, followed by a (possibly empty) string containing | ||
| 387 | the partial that was received. The error message can be | ||
| 388 | the string '<tt>closed</tt>' in case the connection was | ||
| 389 | closed before the transmission was completed or the string | ||
| 390 | '<tt>timeout</tt>' in case there was a timeout during the operation. | ||
| 391 | </p> | ||
| 392 | |||
| 393 | <p class="note"> | ||
| 394 | <b>Important note</b>: This function was changed <em>severely</em>. It used | ||
| 395 | to support multiple patterns (but I have never seen this feature used) and | ||
| 396 | now it doesn't anymore. Partial results used to be returned in the same | ||
| 397 | way as successful results. This last feature violated the idea that all | ||
| 398 | functions should return <tt><b>nil</b></tt> on error. Thus it was changed | ||
| 399 | too. | ||
| 400 | </p> | ||
| 401 | |||
| 402 | <!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 403 | |||
| 404 | <p class="name" id="send"> | ||
| 405 | client:<b>send(</b>data [, i [, j]]<b>)</b> | ||
| 406 | </p> | ||
| 407 | |||
| 408 | <p class="description"> | ||
| 409 | Sends <tt>data</tt> through client object. | ||
| 410 | </p> | ||
| 411 | |||
| 412 | <p class="parameters"> | ||
| 413 | <tt>Data</tt> is the string to be sent. The optional arguments | ||
| 414 | <tt>i</tt> and <tt>j</tt> work exactly like the standard | ||
| 415 | <tt>string.sub</tt> Lua function to allow the selection of a | ||
| 416 | substring to be sent. | ||
| 417 | </p> | ||
| 418 | |||
| 419 | <p class="return"> | ||
| 420 | If successful, the method returns the index of the last byte | ||
| 421 | within <tt>[i, j]</tt> that has been sent. Notice that, if | ||
| 422 | <tt>i</tt> is 1 or absent, this is effectively the total | ||
| 423 | number of bytes sent. In case of error, the method returns | ||
| 424 | <b><tt>nil</tt></b>, followed by an error message, followed | ||
| 425 | by the index of the last byte within <tt>[i, j]</tt> that | ||
| 426 | has been sent. You might want to try again from the byte | ||
| 427 | following that. The error message can be '<tt>closed</tt>' | ||
| 428 | in case the connection was closed before the transmission | ||
| 429 | was completed or the string '<tt>timeout</tt>' in case | ||
| 430 | there was a timeout during the operation. | ||
| 431 | </p> | ||
| 432 | |||
| 433 | <p class="note"> | ||
| 434 | Note: Output is <em>not</em> buffered. For small strings, | ||
| 435 | it is always better to concatenate them in Lua | ||
| 436 | (with the '<tt>..</tt>' operator) and send the result in one call | ||
| 437 | instead of calling the method several times. | ||
| 438 | </p> | ||
| 439 | |||
| 440 | <!-- setoption ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 441 | |||
| 442 | <p class="name" id="setoption"> | ||
| 443 | client:<b>setoption(</b>option [, value]<b>)</b><br> | ||
| 444 | server:<b>setoption(</b>option [, value]<b>)</b> | ||
| 445 | </p> | ||
| 446 | |||
| 447 | <p class="description"> | ||
| 448 | Sets options for the TCP object. Options are only needed by low-level or | ||
| 449 | time-critical applications. You should only modify an option if you | ||
| 450 | are sure you need it. | ||
| 451 | </p> | ||
| 452 | |||
| 453 | <p class="parameters"> | ||
| 454 | <tt>Option</tt> is a string with the option name, and <tt>value</tt> | ||
| 455 | depends on the option being set:</p> | ||
| 456 | |||
| 457 | <ul> | ||
| 458 | |||
| 459 | <li> '<tt>keepalive</tt>': Setting this option to <tt>true</tt> enables | ||
| 460 | the periodic transmission of messages on a connected socket. Should the | ||
| 461 | connected party fail to respond to these messages, the connection is | ||
| 462 | considered broken and processes using the socket are notified;</li> | ||
| 463 | |||
| 464 | <li> '<tt>linger</tt>': Controls the action taken when unsent data are | ||
| 465 | queued on a socket and a close is performed. The value is a table with a | ||
| 466 | boolean entry '<tt>on</tt>' and a numeric entry for the time interval | ||
| 467 | '<tt>timeout</tt>' in seconds. If the '<tt>on</tt>' field is set to | ||
| 468 | <tt>true</tt>, the system will block the process on the close attempt until | ||
| 469 | it is able to transmit the data or until '<tt>timeout</tt>' has passed. If | ||
| 470 | '<tt>on</tt>' is <tt>false</tt> and a close is issued, the system will | ||
| 471 | process the close in a manner that allows the process to continue as | ||
| 472 | quickly as possible. I do not advise you to set this to anything other than | ||
| 473 | zero;</li> | ||
| 474 | |||
| 475 | <li> '<tt>reuseaddr</tt>': Setting this option indicates that the rules | ||
| 476 | used in validating addresses supplied in a call to | ||
| 477 | <a href="#bind"><tt>bind</tt></a> should allow reuse of local addresses;</li> | ||
| 478 | |||
| 479 | <li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt> | ||
| 480 | disables the Nagle's algorithm for the connection;</li> | ||
| 481 | |||
| 482 | <li> '<tt>tcp-keepidle</tt>': value in seconds for <tt>TCP_KEEPIDLE</tt> Linux only!!</li> | ||
| 483 | |||
| 484 | <li> '<tt>tcp-keepcnt</tt>': value for <tt>TCP_KEEPCNT</tt> Linux only!!</li> | ||
| 485 | |||
| 486 | <li> '<tt>tcp-keepintvl</tt>': value for <tt>TCP_KEEPINTVL</tt> Linux only!!</li> | ||
| 487 | |||
| 488 | <li> '<tt>ipv6-v6only</tt>': | ||
| 489 | Setting this option to <tt>true</tt> restricts an <tt>inet6</tt> socket to | ||
| 490 | sending and receiving only IPv6 packets.</li> | ||
| 491 | </ul> | ||
| 492 | |||
| 493 | <p class="return"> | ||
| 494 | The method returns 1 in case of success, or <b><tt>nil</tt></b> | ||
| 495 | followed by an error message otherwise. | ||
| 496 | </p> | ||
| 497 | |||
| 498 | <p class="note"> | ||
| 499 | Note: The descriptions above come from the man pages. | ||
| 500 | </p> | ||
| 501 | |||
| 502 | <!-- setstats +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 503 | |||
| 504 | <p class="name" id="setstats"> | ||
| 505 | master:<b>setstats(</b>received, sent, age<b>)</b><br> | ||
| 506 | client:<b>setstats(</b>received, sent, age<b>)</b><br> | ||
| 507 | server:<b>setstats(</b>received, sent, age<b>)</b><br> | ||
| 508 | </p> | ||
| 509 | |||
| 510 | <p class="description"> | ||
| 511 | Resets accounting information on the socket, useful for throttling | ||
| 512 | of bandwidth. | ||
| 513 | </p> | ||
| 514 | |||
| 515 | <p class="parameters"> | ||
| 516 | <tt>Received</tt> is a number with the new number of bytes received. | ||
| 517 | <tt>Sent</tt> is a number with the new number of bytes sent. | ||
| 518 | <tt>Age</tt> is the new age in seconds. | ||
| 519 | </p> | ||
| 520 | |||
| 521 | <p class="return"> | ||
| 522 | The method returns 1 in case of success and <tt><b>nil</b></tt> otherwise. | ||
| 523 | </p> | ||
| 524 | |||
| 525 | <!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 526 | |||
| 527 | <p class="name" id="settimeout"> | ||
| 528 | master:<b>settimeout(</b>value [, mode]<b>)</b><br> | ||
| 529 | client:<b>settimeout(</b>value [, mode]<b>)</b><br> | ||
| 530 | server:<b>settimeout(</b>value [, mode]<b>)</b> | ||
| 531 | </p> | ||
| 532 | |||
| 533 | <p class="description"> | ||
| 534 | Changes the timeout values for the object. By default, | ||
| 535 | all I/O operations are blocking. That is, any call to the methods | ||
| 536 | <a href="#send"><tt>send</tt></a>, | ||
| 537 | <a href="#receive"><tt>receive</tt></a>, and | ||
| 538 | <a href="#accept"><tt>accept</tt></a> | ||
| 539 | will block indefinitely, until the operation completes. The | ||
| 540 | <tt>settimeout</tt> method defines a limit on the amount of time the | ||
| 541 | I/O methods can block. When a timeout is set and the specified amount of | ||
| 542 | time has elapsed, the affected methods give up and fail with an error code. | ||
| 543 | </p> | ||
| 544 | |||
| 545 | <p class="parameters"> | ||
| 546 | The amount of time to wait is specified as the | ||
| 547 | <tt>value</tt> parameter, in seconds. There are two timeout modes and | ||
| 548 | both can be used together for fine tuning: | ||
| 549 | </p> | ||
| 550 | |||
| 551 | <ul> | ||
| 552 | <li> '<tt>b</tt>': <em>block</em> timeout. Specifies the upper limit on | ||
| 553 | the amount of time LuaSocket can be blocked by the operating system | ||
| 554 | while waiting for completion of any single I/O operation. This is the | ||
| 555 | default mode;</li> | ||
| 556 | |||
| 557 | <li> '<tt>t</tt>': <em>total</em> timeout. Specifies the upper limit on | ||
| 558 | the amount of time LuaSocket can block a Lua script before returning from | ||
| 559 | a call.</li> | ||
| 560 | </ul> | ||
| 561 | |||
| 562 | <p class="parameters"> | ||
| 563 | The <b><tt>nil</tt></b> timeout <tt>value</tt> allows operations to block | ||
| 564 | indefinitely. Negative timeout values have the same effect. | ||
| 565 | </p> | ||
| 566 | |||
| 567 | <p class="note"> | ||
| 568 | Note: although timeout values have millisecond precision in LuaSocket, | ||
| 569 | large blocks can cause I/O functions not to respect timeout values due | ||
| 570 | to the time the library takes to transfer blocks to and from the OS | ||
| 571 | and to and from the Lua interpreter. Also, function that accept host names | ||
| 572 | and perform automatic name resolution might be blocked by the resolver for | ||
| 573 | longer than the specified timeout value. | ||
| 574 | </p> | ||
| 575 | |||
| 576 | <p class="note"> | ||
| 577 | Note: The old <tt>timeout</tt> method is deprecated. The name has been | ||
| 578 | changed for sake of uniformity, since all other method names already | ||
| 579 | contained verbs making their imperative nature obvious. | ||
| 580 | </p> | ||
| 581 | |||
| 582 | <!-- shutdown +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 583 | |||
| 584 | <p class="name" id="shutdown"> | ||
| 585 | client:<b>shutdown(</b>mode<b>)</b><br> | ||
| 586 | </p> | ||
| 587 | |||
| 588 | <p class="description"> | ||
| 589 | Shuts down part of a full-duplex connection. | ||
| 590 | </p> | ||
| 591 | |||
| 592 | <p class="parameters"> | ||
| 593 | Mode tells which way of the connection should be shut down and can | ||
| 594 | take the value: | ||
| 595 | <ul> | ||
| 596 | <li>"<tt>both</tt>": disallow further sends and receives on the object. | ||
| 597 | This is the default mode;</li> | ||
| 598 | <li>"<tt>send</tt>": disallow further sends on the object;</li> | ||
| 599 | <li>"<tt>receive</tt>": disallow further receives on the object.</li> | ||
| 600 | </ul> | ||
| 601 | </p> | ||
| 602 | |||
| 603 | <p class="return"> | ||
| 604 | This function returns 1. | ||
| 605 | </p> | ||
| 606 | |||
| 607 | <!-- setfd +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 608 | |||
| 609 | <p class="name" id="setfd"> | ||
| 610 | master:<b>setfd(</b>fd<b>)</b><br> | ||
| 611 | client:<b>setfd(</b>fd<b>)</b><br> | ||
| 612 | server:<b>setfd(</b>fd<b>)</b> | ||
| 613 | </p> | ||
| 614 | |||
| 615 | <p class="description"> | ||
| 616 | Sets the underling socket descriptor or handle associated to the object. The current one | ||
| 617 | is simply replaced, not closed, and no other change to the object state is made. | ||
| 618 | To set it as invalid use <a href="socket.html#socketinvalid"><tt>_SOCKETINVALID</tt></a>. | ||
| 619 | </p> | ||
| 620 | |||
| 621 | <p class="return"> | ||
| 622 | No return value. | ||
| 623 | </p> | ||
| 624 | |||
| 625 | <p class="note"> | ||
| 626 | Note: <b>This is an internal method. Unlikely to be | ||
| 627 | portable. Use at your own risk. </b> | ||
| 628 | </p> | ||
| 629 | |||
| 630 | <!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 631 | |||
| 632 | <p class="name" id="socket.tcp"> | ||
| 633 | socket.<b>tcp()</b> | ||
| 634 | </p> | ||
| 635 | |||
| 636 | <p class="description"> | ||
| 637 | Creates and returns an TCP master object. A master object can | ||
| 638 | be transformed into a server object with the method | ||
| 639 | <a href="#listen"><tt>listen</tt></a> (after a call to <a | ||
| 640 | href="#bind"><tt>bind</tt></a>) or into a client object with | ||
| 641 | the method <a href="#connect"><tt>connect</tt></a>. The only other | ||
| 642 | method supported by a master object is the | ||
| 643 | <a href="#close"><tt>close</tt></a> method.</p> | ||
| 644 | |||
| 645 | <p class="return"> | ||
| 646 | In case of success, a new master object is returned. In case of error, | ||
| 647 | <b><tt>nil</tt></b> is returned, followed by an error message. | ||
| 648 | </p> | ||
| 649 | |||
| 650 | <p class="note"> | ||
| 651 | Note: The choice between IPv4 and IPv6 happens during a call to | ||
| 652 | <a href="#bind"><tt>bind</tt></a> or <a | ||
| 653 | href="#bind"><tt>connect</tt></a>, depending on the address | ||
| 654 | family obtained from the resolver. | ||
| 655 | </p> | ||
| 656 | |||
| 657 | <p class="note"> | ||
| 658 | Note: Before the choice between IPv4 and IPv6 happens, | ||
| 659 | the internal socket object is invalid and therefore <a | ||
| 660 | href="#setoption"><tt>setoption</tt></a> will fail. | ||
| 661 | </p> | ||
| 662 | |||
| 663 | <!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 664 | |||
| 665 | <p class="name" id="socket.tcp4"> | ||
| 666 | socket.<b>tcp4()</b> | ||
| 667 | </p> | ||
| 668 | |||
| 669 | <p class="description"> | ||
| 670 | Creates and returns an IPv4 TCP master object. A master object can | ||
| 671 | be transformed into a server object with the method | ||
| 672 | <a href="#listen"><tt>listen</tt></a> (after a call to <a | ||
| 673 | href="#bind"><tt>bind</tt></a>) or into a client object with | ||
| 674 | the method <a href="#connect"><tt>connect</tt></a>. The only other | ||
| 675 | method supported by a master object is the | ||
| 676 | <a href="#close"><tt>close</tt></a> method.</p> | ||
| 677 | |||
| 678 | <p class="return"> | ||
| 679 | In case of success, a new master object is returned. In case of error, | ||
| 680 | <b><tt>nil</tt></b> is returned, followed by an error message. | ||
| 681 | </p> | ||
| 682 | |||
| 683 | <!-- socket.tcp6 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 684 | |||
| 685 | <p class="name" id="socket.tcp6"> | ||
| 686 | socket.<b>tcp6()</b> | ||
| 687 | </p> | ||
| 688 | |||
| 689 | <p class="description"> | ||
| 690 | Creates and returns an IPv6 TCP master object. A master object can | ||
| 691 | be transformed into a server object with the method | ||
| 692 | <a href="#listen"><tt>listen</tt></a> (after a call to <a | ||
| 693 | href="#bind"><tt>bind</tt></a>) or into a client object with | ||
| 694 | the method <a href="#connect"><tt>connect</tt></a>. The only other | ||
| 695 | method supported by a master object is the | ||
| 696 | <a href="#close"><tt>close</tt></a> method.</p> | ||
| 697 | |||
| 698 | <p class="return"> | ||
| 699 | In case of success, a new master object is returned. In case of error, | ||
| 700 | <b><tt>nil</tt></b> is returned, followed by an error message. | ||
| 701 | </p> | ||
| 702 | |||
| 703 | <p class="note"> | ||
| 704 | Note: The TCP object returned will have the option | ||
| 705 | "<tt>ipv6-v6only</tt>" set to <tt><b>true</b></tt>. | ||
| 706 | </p> | ||
| 707 | |||
| 708 | |||
| 709 | |||
| 710 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 711 | |||
| 712 | <div class="footer"> | ||
| 713 | <hr> | ||
| 714 | <center> | ||
| 715 | <p class="bar"> | ||
| 716 | <a href="index.html">home</a> · | ||
| 717 | <a href="index.html#down">download</a> · | ||
| 718 | <a href="installation.html">installation</a> · | ||
| 719 | <a href="introduction.html">introduction</a> · | ||
| 720 | <a href="reference.html">reference</a> | ||
| 721 | </p> | ||
| 722 | <p> | ||
| 723 | <small> | ||
| 724 | Last modified by Diego Nehab on <br> | ||
| 725 | Thu Apr 20 00:25:57 EDT 2006 | ||
| 726 | </small> | ||
| 727 | </p> | ||
| 728 | </center> | ||
| 729 | </div> | ||
| 730 | |||
| 731 | </body> | ||
| 732 | </html> | ||
