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