diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-02-04 14:29:11 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-02-04 14:29:11 +0000 |
commit | 0b2542d1a61fc5425ff65ab3dbf7ba7de174763f (patch) | |
tree | 8a6188e11db0c9ef6891c31e8a1bebca050b23b2 /doc/tcp.html | |
parent | f67864f86c7d703325e86b14d0ba33992c52891b (diff) | |
download | luasocket-0b2542d1a61fc5425ff65ab3dbf7ba7de174763f.tar.gz luasocket-0b2542d1a61fc5425ff65ab3dbf7ba7de174763f.tar.bz2 luasocket-0b2542d1a61fc5425ff65ab3dbf7ba7de174763f.zip |
Worked on the manual.
Implemented stuffing (needs test)
Added cddb and qp examples.
Diffstat (limited to 'doc/tcp.html')
-rw-r--r-- | doc/tcp.html | 148 |
1 files changed, 101 insertions, 47 deletions
diff --git a/doc/tcp.html b/doc/tcp.html index eb4cdfa..34d6c6e 100644 --- a/doc/tcp.html +++ b/doc/tcp.html | |||
@@ -44,10 +44,11 @@ socket.<b>tcp()</b> | |||
44 | <p class=description> | 44 | <p class=description> |
45 | Creates and returns a TCP master object. A master object can | 45 | Creates and returns a TCP master object. A master object can |
46 | be transformed into a server object with the method | 46 | be transformed into a server object with the method |
47 | <a href=#bind><tt>bind</tt></a> or into a client object with the method | 47 | <a href=#listen><tt>listen</tt></a> (after a call to <a |
48 | <a href=#connect><tt>connect</tt></a>. The only other method | 48 | href=#bind><tt>bind</tt></a>) or into a client object with |
49 | supported by a master object is the <a href=#close><tt>close</tt></a> | 49 | the method <a href=#connect><tt>connect</tt></a>. The only other |
50 | method.</p> | 50 | method supported by a master object is the |
51 | <a href=#close><tt>close</tt></a> method.</p> | ||
51 | 52 | ||
52 | <p class=return> | 53 | <p class=return> |
53 | In case of success, a new master object is returned. In case of error, | 54 | In case of success, a new master object is returned. In case of error, |
@@ -67,8 +68,9 @@ object and returns a client object representing that connection. | |||
67 | 68 | ||
68 | <p class=return> | 69 | <p class=return> |
69 | If a connection is successfully initiated, a client object is returned. | 70 | If a connection is successfully initiated, a client object is returned. |
70 | If a timeout condition is met, the method returns <b><tt>nil</tt></b> followed | 71 | If a timeout condition is met, the method returns <b><tt>nil</tt></b> |
71 | by the error string '<tt>timeout</tt>'. | 72 | followed by the error string '<tt>timeout</tt>'. Other errors are |
73 | reported by <b><tt>nil</tt></b> followed by a message describing the error. | ||
72 | </p> | 74 | </p> |
73 | 75 | ||
74 | <p class=note> | 76 | <p class=note> |
@@ -77,25 +79,18 @@ with a server object in | |||
77 | the <tt>receive</tt> parameter before a call to <tt>accept</tt> does | 79 | the <tt>receive</tt> parameter before a call to <tt>accept</tt> does |
78 | <em>not</em> guarantee <tt>accept</tt> will return immediately. Use the <a | 80 | <em>not</em> guarantee <tt>accept</tt> will return immediately. Use the <a |
79 | href=#settimeout><tt>settimeout</tt></a> method or <tt>accept</tt> | 81 | href=#settimeout><tt>settimeout</tt></a> method or <tt>accept</tt> |
80 | might block until <em>another</em> client shows up. | 82 | might block until <em>another</em> client shows up. |
81 | </p> | 83 | </p> |
82 | 84 | ||
83 | <!-- bind +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 85 | <!-- bind +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
84 | 86 | ||
85 | <p class=name id=bind> | 87 | <p class=name id=bind> |
86 | master:<b>bind(</b>address, port [, backlog]<b>)</b> | 88 | master:<b>bind(</b>address, port<b>)</b> |
87 | </p> | 89 | </p> |
88 | 90 | ||
89 | <p class=description> | 91 | <p class=description> |
90 | Binds a master object to <tt>address</tt> and <tt>port</tt> on the | 92 | Binds a master object to <tt>address</tt> and <tt>port</tt> on the |
91 | local host, transforming it into a server object. Server | 93 | local host. |
92 | objects support the | ||
93 | <a href=#accept><tt>accept</tt></a>, | ||
94 | <a href=#getsockname><tt>getsockname</tt></a>, | ||
95 | <a href=#setoption><tt>setoption</tt></a>, | ||
96 | <a href=#settimeout><tt>settimeout</tt></a>, | ||
97 | and <a href=#close><tt>close</tt></a> methods. | ||
98 | </p> | ||
99 | 94 | ||
100 | <p class=parameters> | 95 | <p class=parameters> |
101 | <tt>Address</tt> can be an IP address or a host name. | 96 | <tt>Address</tt> can be an IP address or a host name. |
@@ -103,10 +98,7 @@ and <a href=#close><tt>close</tt></a> methods. | |||
103 | If <tt>address</tt> | 98 | If <tt>address</tt> |
104 | is '<tt>*</tt>', the system binds to all local interfaces | 99 | is '<tt>*</tt>', the system binds to all local interfaces |
105 | using the <tt>INADDR_ANY</tt> constant. If <tt>port</tt> is 0, the system automatically | 100 | using the <tt>INADDR_ANY</tt> constant. If <tt>port</tt> is 0, the system automatically |
106 | chooses an ephemeral port. The optional parameter <tt>backlog</tt>, which | 101 | chooses an ephemeral port. |
107 | defaults to 1, specifies the number of client connections that can | ||
108 | be queued waiting for service. If the queue is full and another client | ||
109 | attempts connection, the connection is refused. | ||
110 | </p> | 102 | </p> |
111 | 103 | ||
112 | <p class=return> | 104 | <p class=return> |
@@ -115,8 +107,8 @@ method returns <b><tt>nil</tt></b> followed by an error message. | |||
115 | </p> | 107 | </p> |
116 | 108 | ||
117 | <p class=note> | 109 | <p class=note> |
118 | Note: The function <tt>socket.bind</tt> is available and is a short | 110 | Note: The function <a href=#socket.bind><tt>socket.bind</tt></a> |
119 | for <a href=#socket.tcp><tt>socket.tcp</tt></a> followed by the <tt>bind</tt> method. | 111 | is available and is a shortcut for the creation server sockets. |
120 | </p> | 112 | </p> |
121 | 113 | ||
122 | <!-- close ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 114 | <!-- close ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
@@ -150,7 +142,8 @@ master:<b>connect(</b>address, port<b>)</b> | |||
150 | 142 | ||
151 | <p class=description> | 143 | <p class=description> |
152 | Attempts to connect a master object to a remote host, transforming it into a | 144 | Attempts to connect a master object to a remote host, transforming it into a |
153 | client object. Client objects support methods | 145 | client object. |
146 | Client objects support methods | ||
154 | <a href=#send><tt>send</tt></a>, | 147 | <a href=#send><tt>send</tt></a>, |
155 | <a href=#receive><tt>receive</tt></a>, | 148 | <a href=#receive><tt>receive</tt></a>, |
156 | <a href=#getsockname><tt>getsockname</tt></a>, | 149 | <a href=#getsockname><tt>getsockname</tt></a>, |
@@ -170,8 +163,15 @@ describing the error. In case of success, the method returns 1. | |||
170 | </p> | 163 | </p> |
171 | 164 | ||
172 | <p class=note> | 165 | <p class=note> |
173 | Note: The function <tt>socket.connect</tt> is available and is a short | 166 | Note: The function <a href=#socket.connect><tt>socket.connect</tt></a> |
174 | for <a href=#socket.tcp><tt>socket.tcp</tt></a> followed by the <tt>connect</tt> method. | 167 | is available and is a shortcut for the creation of client sockets. |
168 | </p> | ||
169 | |||
170 | <p class=note> | ||
171 | Note: Starting with LuaSocket 2.0, | ||
172 | the <a href=#settimeout><tt>settimeout</tt></a> | ||
173 | function affects the behavior of connect, causing it to return in case of | ||
174 | a timeout error. | ||
175 | </p> | 175 | </p> |
176 | 176 | ||
177 | <!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 177 | <!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
@@ -210,12 +210,32 @@ The method returns a string with local IP address and a number with | |||
210 | the port. In case of error, the method returns <b><tt>nil</tt></b>. | 210 | the port. In case of error, the method returns <b><tt>nil</tt></b>. |
211 | </p> | 211 | </p> |
212 | 212 | ||
213 | <p class=note> | 213 | <!-- listen ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
214 | Note: Naturally, for a server object, the address and port returned are | 214 | |
215 | those passed to the <a href=#bind>bind</a> method. If the port value | 215 | <p class=name id=listen> |
216 | passed to bind was 0, the OS assigned ephemeral port is returned. For | 216 | master:<b>listen(</b>backlog<b>)</b> |
217 | client objects, both the address and port are ephemeral and these are the | 217 | </p> |
218 | values returned. | 218 | |
219 | <p class=description> | ||
220 | Specifies the socket is willing to receive connections, transforming the | ||
221 | object into a server object. Server objects support the | ||
222 | <a href=#accept><tt>accept</tt></a>, | ||
223 | <a href=#getsockname><tt>getsockname</tt></a>, | ||
224 | <a href=#setoption><tt>setoption</tt></a>, | ||
225 | <a href=#settimeout><tt>settimeout</tt></a>, | ||
226 | and <a href=#close><tt>close</tt></a> methods. | ||
227 | </p> | ||
228 | |||
229 | <p class=parameters> | ||
230 | The parameter <tt>backlog</tt> specifies the number of client | ||
231 | connections that can | ||
232 | be queued waiting for service. If the queue is full and another client | ||
233 | attempts connection, the connection is refused. | ||
234 | </p> | ||
235 | |||
236 | <p class=return> | ||
237 | In case of success, the method returns 1. In case of error, the | ||
238 | method returns <b><tt>nil</tt></b> followed by an error message. | ||
219 | </p> | 239 | </p> |
220 | 240 | ||
221 | <!-- receive ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 241 | <!-- receive ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
@@ -242,8 +262,8 @@ closed. No end-of-line translation is performed; | |||
242 | terminated by a LF character (ASCII 10), optionally preceded by a | 262 | terminated by a LF character (ASCII 10), optionally preceded by a |
243 | CR character (ASCII 13). The CR and LF characters are not included in | 263 | CR character (ASCII 13). The CR and LF characters are not included in |
244 | the returned line. This is the default pattern; | 264 | the returned line. This is the default pattern; |
245 | <li> <tt>number</tt>: causes the method to read <tt>number</tt> raw | 265 | <li> <tt>number</tt>: causes the method to read a specified <tt>number</tt> |
246 | bytes from the socket. | 266 | of bytes from the socket. |
247 | </ul> | 267 | </ul> |
248 | 268 | ||
249 | <p class=return> | 269 | <p class=return> |
@@ -311,22 +331,30 @@ are sure you need it. | |||
311 | depends on the option being set: | 331 | depends on the option being set: |
312 | 332 | ||
313 | <ul> | 333 | <ul> |
314 | <li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt> disables the | 334 | |
315 | Nagle's algorithm for the connection; | 335 | <li> '<tt>keepalive</tt>': Setting this option to <tt>true</tt> enables |
336 | the periodic transmission of messages on a connected socket. Should the | ||
337 | connected party fail to respond to these messages, the connection is | ||
338 | considered broken and processes using the socket are notified; | ||
339 | |||
316 | <li> '<tt>linger</tt>': Controls the action taken when unsent data are | 340 | <li> '<tt>linger</tt>': Controls the action taken when unsent data are |
317 | queued on a socket and a close is performed. The value is a table with a | 341 | queued on a socket and a close is performed. The value is a table with a |
318 | boolean entry '<tt>on</tt>' and a numeric entry for the time interval | 342 | boolean entry '<tt>on</tt>' and a numeric entry for the time interval |
319 | '<tt>timeout</tt>' in seconds. | 343 | '<tt>timeout</tt>' in seconds. If the '<tt>on</tt>' field is set to |
320 | If the '<tt>on</tt>' field is set to <tt>true</tt>, | 344 | <tt>true</tt>, the system will block the process on the close attempt until |
321 | the system will block the process on the close attempt until it is able to | 345 | it is able to transmit the data or until '<tt>timeout</tt>' has passed. If |
322 | transmit the data or until '<tt>timeout</tt>' has passed. If '<tt>on</tt>' | 346 | '<tt>on</tt>' is <tt>false</tt> and a close is issued, the system will |
323 | is <tt>false</tt> and a close is issued, the system will process the close | 347 | process the close in a manner that allows the process to continue as |
324 | in a manner that allows the process to continue as quickly as possible. I | 348 | quickly as possible. I do not advise you to set this to anything other than |
325 | do not advise you to set this to anything other than zero. | 349 | zero; |
326 | <li> '<tt>keepalive</tt>': Setting this option to <tt>true</tt> enables | 350 | |
327 | the periodic transmission of messages on a connected socket. Should the | 351 | <li> '<tt>reuseaddr</tt>': Setting this option indicates that the rules |
328 | connected party fail to respond to these messages, the connection is | 352 | used in validating addresses supplied in a call to |
329 | considered broken and processes using the socket are notified. | 353 | <a href=#bind><tt>bind</tt></a> should allow reuse of local addresses; |
354 | |||
355 | <li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt> | ||
356 | disables the Nagle's algorithm for the connection. | ||
357 | |||
330 | </ul> | 358 | </ul> |
331 | 359 | ||
332 | <p class=return> | 360 | <p class=return> |
@@ -382,7 +410,9 @@ indefinitely. Negative timeout values have the same effect. | |||
382 | Note: although timeout values have millisecond precision in LuaSocket, | 410 | Note: although timeout values have millisecond precision in LuaSocket, |
383 | large blocks can cause I/O functions not to respect timeout values due | 411 | large blocks can cause I/O functions not to respect timeout values due |
384 | to the time the library takes to transfer blocks to and from the OS | 412 | to the time the library takes to transfer blocks to and from the OS |
385 | and to and from the Lua interpreter. | 413 | and to and from the Lua interpreter. Also, function that accept host names |
414 | and perform automatic name resolution might be blocked by the resolver for | ||
415 | longer than the specified timeout value. | ||
386 | </p> | 416 | </p> |
387 | 417 | ||
388 | <p class=note> | 418 | <p class=note> |
@@ -391,6 +421,30 @@ changed for sake of uniformity, since all other method names already | |||
391 | contained verbs making their imperative nature obvious. | 421 | contained verbs making their imperative nature obvious. |
392 | </p> | 422 | </p> |
393 | 423 | ||
424 | <!-- shutdown +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
425 | |||
426 | <p class=name id=shutdown> | ||
427 | client:<b>shutdown(</b>mode<b>)</b><br> | ||
428 | </p> | ||
429 | |||
430 | <p class=description> | ||
431 | Shuts down part of a full duplex connection. | ||
432 | </p> | ||
433 | |||
434 | <p class=parameters> | ||
435 | Mode tells which way of the connection should be shut down and can | ||
436 | take the value: | ||
437 | <ul> | ||
438 | <li>"<tt>both</tt>": disallow further sends and receives on the object. | ||
439 | This is the default mode; | ||
440 | <li>"<tt>send</tt>": disallow further sends on the object; | ||
441 | <li>"<tt>receive</tt>": disallow further receives on the object. | ||
442 | </ul> | ||
443 | |||
444 | <p class=return> | ||
445 | This function returns 1. | ||
446 | </p> | ||
447 | |||
394 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 448 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
395 | 449 | ||
396 | <div class=footer> | 450 | <div class=footer> |