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