aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego.nehab@gmail.com>2016-03-04 15:36:32 -0300
committerDiego Nehab <diego.nehab@gmail.com>2016-03-04 15:36:32 -0300
commit944305dc21350fd2ec32a9552d893da86894fd62 (patch)
tree82948c24dade5e0da6924ab5e706f146bce4692a
parentcdce73b226cc4da6a073b79bec02a6780d32ff1a (diff)
downloadluasocket-944305dc21350fd2ec32a9552d893da86894fd62.tar.gz
luasocket-944305dc21350fd2ec32a9552d893da86894fd62.tar.bz2
luasocket-944305dc21350fd2ec32a9552d893da86894fd62.zip
Added gettimeout for completeness.
Also documented. Rordered manuals so order is alphabetical.
-rw-r--r--doc/mime.html59
-rw-r--r--doc/reference.html2
-rw-r--r--doc/smtp.html235
-rw-r--r--doc/socket.html70
-rw-r--r--doc/tcp.html283
-rw-r--r--doc/udp.html431
-rw-r--r--src/tcp.c8
-rw-r--r--src/timeout.c10
-rw-r--r--src/timeout.h1
-rw-r--r--src/udp.c7
10 files changed, 587 insertions, 519 deletions
diff --git a/doc/mime.html b/doc/mime.html
index ae136fd..8cb3507 100644
--- a/doc/mime.html
+++ b/doc/mime.html
@@ -72,34 +72,6 @@ local mime = require("mime")
72 72
73<h3 id=high>High-level filters</h3> 73<h3 id=high>High-level filters</h3>
74 74
75<!-- normalize ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
76
77<p class=name id="normalize">
78mime.<b>normalize(</b>[marker]<b>)</b>
79</p>
80
81<p class=description>
82Converts most common end-of-line markers to a specific given marker.
83</p>
84
85<p class=parameters>
86<tt>Marker</tt> is the new marker. It defaults to CRLF, the canonic
87end-of-line marker defined by the MIME standard.
88</p>
89
90<p class=return>
91The function returns a filter that performs the conversion.
92</p>
93
94<p class=note>
95Note: There is no perfect solution to this problem. Different end-of-line
96markers are an evil that will probably plague developers forever.
97This function, however, will work perfectly for text created with any of
98the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF),
99or the DOS (CRLF) conventions. Even if the data has mixed end-of-line
100markers, the function will still work well, although it doesn't
101guarantee that the number of empty lines will be correct.
102</p>
103 75
104<!-- decode +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 76<!-- decode +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
105 77
@@ -159,6 +131,35 @@ base64 = ltn12.filter.chain(
159) 131)
160</pre> 132</pre>
161 133
134<!-- normalize ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
135
136<p class=name id="normalize">
137mime.<b>normalize(</b>[marker]<b>)</b>
138</p>
139
140<p class=description>
141Converts most common end-of-line markers to a specific given marker.
142</p>
143
144<p class=parameters>
145<tt>Marker</tt> is the new marker. It defaults to CRLF, the canonic
146end-of-line marker defined by the MIME standard.
147</p>
148
149<p class=return>
150The function returns a filter that performs the conversion.
151</p>
152
153<p class=note>
154Note: There is no perfect solution to this problem. Different end-of-line
155markers are an evil that will probably plague developers forever.
156This function, however, will work perfectly for text created with any of
157the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF),
158or the DOS (CRLF) conventions. Even if the data has mixed end-of-line
159markers, the function will still work well, although it doesn't
160guarantee that the number of empty lines will be correct.
161</p>
162
162<!-- stuff +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 163<!-- stuff +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
163 164
164<p class=name id="stuff"> 165<p class=name id="stuff">
@@ -466,7 +467,7 @@ marker.
466<p> 467<p>
467<small> 468<small>
468Last modified by Diego Nehab on <br> 469Last modified by Diego Nehab on <br>
469Thu Apr 20 00:25:44 EDT 2006 470Fri Mar 4 15:19:17 BRT 2016
470</small> 471</small>
471</p> 472</p>
472</center> 473</center>
diff --git a/doc/reference.html b/doc/reference.html
index 878e7d2..287dc19 100644
--- a/doc/reference.html
+++ b/doc/reference.html
@@ -187,6 +187,7 @@ Support, Manual">
187<a href="tcp.html#getpeername">getpeername</a>, 187<a href="tcp.html#getpeername">getpeername</a>,
188<a href="tcp.html#getsockname">getsockname</a>, 188<a href="tcp.html#getsockname">getsockname</a>,
189<a href="tcp.html#getstats">getstats</a>, 189<a href="tcp.html#getstats">getstats</a>,
190<a href="tcp.html#gettimeout">gettimeout</a>,
190<a href="tcp.html#listen">listen</a>, 191<a href="tcp.html#listen">listen</a>,
191<a href="tcp.html#receive">receive</a>, 192<a href="tcp.html#receive">receive</a>,
192<a href="tcp.html#send">send</a>, 193<a href="tcp.html#send">send</a>,
@@ -207,6 +208,7 @@ Support, Manual">
207<a href="udp.html#getoption">getoption</a>, 208<a href="udp.html#getoption">getoption</a>,
208<a href="udp.html#getpeername">getpeername</a>, 209<a href="udp.html#getpeername">getpeername</a>,
209<a href="udp.html#getsockname">getsockname</a>, 210<a href="udp.html#getsockname">getsockname</a>,
211<a href="udp.html#gettimeout">gettimeout</a>,
210<a href="udp.html#receive">receive</a>, 212<a href="udp.html#receive">receive</a>,
211<a href="udp.html#receivefrom">receivefrom</a>, 213<a href="udp.html#receivefrom">receivefrom</a>,
212<a href="udp.html#send">send</a>, 214<a href="udp.html#send">send</a>,
diff --git a/doc/smtp.html b/doc/smtp.html
index bbbff80..600ec37 100644
--- a/doc/smtp.html
+++ b/doc/smtp.html
@@ -114,6 +114,124 @@ the SMTP module:
114<li> <tt>ZONE</tt>: default time zone. 114<li> <tt>ZONE</tt>: default time zone.
115</ul> 115</ul>
116 116
117<!-- message ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
118
119<p class=name id=message>
120smtp.<b>message(</b>mesgt<b>)</b>
121</p>
122
123<p class=description>
124Returns a <em>simple</em>
125<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep).
126</p>
127
128<p class=parameters>
129The only parameter of the function is a table describing the message.
130<tt>Mesgt</tt> has the following form (notice the recursive structure):
131</p>
132
133<blockquote>
134<table summary="Mesgt table structure">
135<tr><td><tt>
136mesgt = {<br>
137&nbsp;&nbsp;headers = <i>header-table</i>,<br>
138&nbsp;&nbsp;body = <i>LTN12 source</i> or <i>string</i> or
139<i>multipart-mesgt</i><br>
140}<br>
141&nbsp;<br>
142multipart-mesgt = {<br>
143&nbsp;&nbsp;[preamble = <i>string</i>,]<br>
144&nbsp;&nbsp;[1] = <i>mesgt</i>,<br>
145&nbsp;&nbsp;[2] = <i>mesgt</i>,<br>
146&nbsp;&nbsp;...<br>
147&nbsp;&nbsp;[<i>n</i>] = <i>mesgt</i>,<br>
148&nbsp;&nbsp;[epilogue = <i>string</i>,]<br>
149}<br>
150</tt></td></tr>
151</table>
152</blockquote>
153
154<p class=parameters>
155For a simple message, all that is needed is a set of <tt>headers</tt>
156and the <tt>body</tt>. The message <tt>body</tt> can be given as a string
157or as a <em>simple</em>
158<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
159source. For multipart messages, the body is a table that
160recursively defines each part as an independent message, plus an optional
161<tt>preamble</tt> and <tt>epilogue</tt>.
162</p>
163
164<p class=return>
165The function returns a <em>simple</em>
166<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
167source that produces the
168message contents as defined by <tt>mesgt</tt>, chunk by chunk.
169Hopefully, the following
170example will make things clear. When in doubt, refer to the appropriate RFC
171as listed in the introduction. </p>
172
173<pre class=example>
174-- load the smtp support and its friends
175local smtp = require("socket.smtp")
176local mime = require("mime")
177local ltn12 = require("ltn12")
178
179-- creates a source to send a message with two parts. The first part is
180-- plain text, the second part is a PNG image, encoded as base64.
181source = smtp.message{
182 headers = {
183 -- Remember that headers are *ignored* by smtp.send.
184 from = "Sicrano de Oliveira &lt;sicrano@example.com&gt;",
185 to = "Fulano da Silva &lt;fulano@example.com&gt;",
186 subject = "Here is a message with attachments"
187 },
188 body = {
189 preamble = "If your client doesn't understand attachments, \r\n" ..
190 "it will still display the preamble and the epilogue.\r\n" ..
191 "Preamble will probably appear even in a MIME enabled client.",
192 -- first part: no headers means plain text, us-ascii.
193 -- The mime.eol low-level filter normalizes end-of-line markers.
194 [1] = {
195 body = mime.eol(0, [[
196 Lines in a message body should always end with CRLF.
197 The smtp module will *NOT* perform translation. However, the
198 send function *DOES* perform SMTP stuffing, whereas the message
199 function does *NOT*.
200 ]])
201 },
202 -- second part: headers describe content to be a png image,
203 -- sent under the base64 transfer content encoding.
204 -- notice that nothing happens until the message is actually sent.
205 -- small chunks are loaded into memory right before transmission and
206 -- translation happens on the fly.
207 [2] = {
208 headers = {
209 ["content-type"] = 'image/png; name="image.png"',
210 ["content-disposition"] = 'attachment; filename="image.png"',
211 ["content-description"] = 'a beautiful image',
212 ["content-transfer-encoding"] = "BASE64"
213 },
214 body = ltn12.source.chain(
215 ltn12.source.file(io.open("image.png", "rb")),
216 ltn12.filter.chain(
217 mime.encode("base64"),
218 mime.wrap()
219 )
220 )
221 },
222 epilogue = "This might also show up, but after the attachments"
223 }
224}
225
226-- finally send it
227r, e = smtp.send{
228 from = "&lt;sicrano@example.com&gt;",
229 rcpt = "&lt;fulano@example.com&gt;",
230 source = source,
231}
232</pre>
233
234
117<!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 235<!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
118 236
119<p class=name id=send> 237<p class=name id=send>
@@ -275,123 +393,6 @@ r, e = smtp.send{
275} 393}
276</pre> 394</pre>
277 395
278<!-- message ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
279
280<p class=name id=message>
281smtp.<b>message(</b>mesgt<b>)</b>
282</p>
283
284<p class=description>
285Returns a <em>simple</em>
286<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep).
287</p>
288
289<p class=parameters>
290The only parameter of the function is a table describing the message.
291<tt>Mesgt</tt> has the following form (notice the recursive structure):
292</p>
293
294<blockquote>
295<table summary="Mesgt table structure">
296<tr><td><tt>
297mesgt = {<br>
298&nbsp;&nbsp;headers = <i>header-table</i>,<br>
299&nbsp;&nbsp;body = <i>LTN12 source</i> or <i>string</i> or
300<i>multipart-mesgt</i><br>
301}<br>
302&nbsp;<br>
303multipart-mesgt = {<br>
304&nbsp;&nbsp;[preamble = <i>string</i>,]<br>
305&nbsp;&nbsp;[1] = <i>mesgt</i>,<br>
306&nbsp;&nbsp;[2] = <i>mesgt</i>,<br>
307&nbsp;&nbsp;...<br>
308&nbsp;&nbsp;[<i>n</i>] = <i>mesgt</i>,<br>
309&nbsp;&nbsp;[epilogue = <i>string</i>,]<br>
310}<br>
311</tt></td></tr>
312</table>
313</blockquote>
314
315<p class=parameters>
316For a simple message, all that is needed is a set of <tt>headers</tt>
317and the <tt>body</tt>. The message <tt>body</tt> can be given as a string
318or as a <em>simple</em>
319<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
320source. For multipart messages, the body is a table that
321recursively defines each part as an independent message, plus an optional
322<tt>preamble</tt> and <tt>epilogue</tt>.
323</p>
324
325<p class=return>
326The function returns a <em>simple</em>
327<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
328source that produces the
329message contents as defined by <tt>mesgt</tt>, chunk by chunk.
330Hopefully, the following
331example will make things clear. When in doubt, refer to the appropriate RFC
332as listed in the introduction. </p>
333
334<pre class=example>
335-- load the smtp support and its friends
336local smtp = require("socket.smtp")
337local mime = require("mime")
338local ltn12 = require("ltn12")
339
340-- creates a source to send a message with two parts. The first part is
341-- plain text, the second part is a PNG image, encoded as base64.
342source = smtp.message{
343 headers = {
344 -- Remember that headers are *ignored* by smtp.send.
345 from = "Sicrano de Oliveira &lt;sicrano@example.com&gt;",
346 to = "Fulano da Silva &lt;fulano@example.com&gt;",
347 subject = "Here is a message with attachments"
348 },
349 body = {
350 preamble = "If your client doesn't understand attachments, \r\n" ..
351 "it will still display the preamble and the epilogue.\r\n" ..
352 "Preamble will probably appear even in a MIME enabled client.",
353 -- first part: no headers means plain text, us-ascii.
354 -- The mime.eol low-level filter normalizes end-of-line markers.
355 [1] = {
356 body = mime.eol(0, [[
357 Lines in a message body should always end with CRLF.
358 The smtp module will *NOT* perform translation. However, the
359 send function *DOES* perform SMTP stuffing, whereas the message
360 function does *NOT*.
361 ]])
362 },
363 -- second part: headers describe content to be a png image,
364 -- sent under the base64 transfer content encoding.
365 -- notice that nothing happens until the message is actually sent.
366 -- small chunks are loaded into memory right before transmission and
367 -- translation happens on the fly.
368 [2] = {
369 headers = {
370 ["content-type"] = 'image/png; name="image.png"',
371 ["content-disposition"] = 'attachment; filename="image.png"',
372 ["content-description"] = 'a beautiful image',
373 ["content-transfer-encoding"] = "BASE64"
374 },
375 body = ltn12.source.chain(
376 ltn12.source.file(io.open("image.png", "rb")),
377 ltn12.filter.chain(
378 mime.encode("base64"),
379 mime.wrap()
380 )
381 )
382 },
383 epilogue = "This might also show up, but after the attachments"
384 }
385}
386
387-- finally send it
388r, e = smtp.send{
389 from = "&lt;sicrano@example.com&gt;",
390 rcpt = "&lt;fulano@example.com&gt;",
391 source = source,
392}
393</pre>
394
395<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 396<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
396 397
397<div class=footer> 398<div class=footer>
diff --git a/doc/socket.html b/doc/socket.html
index a99d71b..35f8391 100644
--- a/doc/socket.html
+++ b/doc/socket.html
@@ -51,6 +51,30 @@ To obtain the <tt>socket</tt> namespace, run:
51local socket = require("socket") 51local socket = require("socket")
52</pre> 52</pre>
53 53
54<!-- headers.canonic ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
55
56<p class=name id="headers.canonic">
57socket.headers.<b>canonic</b></p>
58
59<p> The <tt>socket.headers.canonic</tt> table
60is used by the HTTP and SMTP modules to translate from
61lowercase field names back into their canonic
62capitalization. When a lowercase field name exists as a key
63in this table, the associated value is substituted in
64whenever the field name is sent out.
65</p>
66
67<p>
68You can obtain the <tt>headers</tt> namespace if case run-time
69modifications are required by running:
70</p>
71
72<pre class=example>
73-- loads the headers module
74local headers = require("headers")
75</pre>
76
77
54<!-- bind ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 78<!-- bind ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
55 79
56<p class=name id=bind> 80<p class=name id=bind>
@@ -129,29 +153,6 @@ t = socket.gettime()
129print(socket.gettime() - t .. " seconds elapsed") 153print(socket.gettime() - t .. " seconds elapsed")
130</pre> 154</pre>
131 155
132<!-- socket.headers ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
133
134<p class=name id="headers.canonic">
135socket.headers.<b>canonic</b></p>
136
137<p> The <tt>socket.headers.canonic</tt> table
138is used by the HTTP and SMTP modules to translate from
139lowercase field names back into their canonic
140capitalization. When a lowercase field name exists as a key
141in this table, the associated value is substituted in
142whenever the field name is sent out.
143</p>
144
145<p>
146You can obtain the <tt>headers</tt> namespace if case run-time
147modifications are required by running:
148</p>
149
150<pre class=example>
151-- loads the headers module
152local headers = require("headers")
153</pre>
154
155<!-- newtry +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 156<!-- newtry +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
156 157
157<p class=name id=newtry> 158<p class=name id=newtry>
@@ -283,6 +284,18 @@ it to <tt>select</tt>, it will be ignored.
283<b>Using select with non-socket objects</b>: Any object that implements <tt>getfd</tt> and <tt>dirty</tt> can be used with <tt>select</tt>, allowing objects from other libraries to be used within a <tt>socket.select</tt> driven loop. 284<b>Using select with non-socket objects</b>: Any object that implements <tt>getfd</tt> and <tt>dirty</tt> can be used with <tt>select</tt>, allowing objects from other libraries to be used within a <tt>socket.select</tt> driven loop.
284</p> 285</p>
285 286
287<!-- setsize ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
288
289<p class=name id=setsize>
290socket.<b>_SETSIZE</b>
291</p>
292
293<p class=description>
294The maximum number of sockets that the <a
295href=#select><tt>select</tt></a> function can handle.
296</p>
297
298
286<!-- sink ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 299<!-- sink ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
287 300
288<p class=name id=sink> 301<p class=name id=sink>
@@ -390,17 +403,6 @@ side closes the connection.
390The function returns a source with the appropriate behavior. 403The function returns a source with the appropriate behavior.
391</p> 404</p>
392 405
393<!-- setsize ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
394
395<p class=name id=setsize>
396socket.<b>_SETSIZE</b>
397</p>
398
399<p class=description>
400The maximum number of sockets that the <a
401href=#select><tt>select</tt></a> function can handle.
402</p>
403
404<!-- socketinvalid ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 406<!-- socketinvalid ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
405 407
406<p class=name id=socketinvalid> 408<p class=name id=socketinvalid>
diff --git a/doc/tcp.html b/doc/tcp.html
index c86853d..c6c6eb2 100644
--- a/doc/tcp.html
+++ b/doc/tcp.html
@@ -38,84 +38,6 @@
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">
44socket.<b>tcp()</b>
45</p>
46
47<p class=description>
48Creates and returns an TCP master object. A master object can
49be transformed into a server object with the method
50<a href=#listen><tt>listen</tt></a> (after a call to <a
51href=#bind><tt>bind</tt></a>) or into a client object with
52the method <a href=#connect><tt>connect</tt></a>. The only other
53method supported by a master object is the
54<a href=#close><tt>close</tt></a> method.</p>
55
56<p class=return>
57In 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>
62Note: The choice between IPv4 and IPv6 happens during a call to
63<a href=#bind><tt>bind</tt></a> or <a
64href=#bind><tt>connect</tt></a>, depending on the address
65family obtained from the resolver.
66</p>
67
68<p class=note>
69Note: Before the choice between IPv4 and IPv6 happens,
70the internal socket object is invalid and therefore <a
71href=#setoption><tt>setoption</tt></a> will fail.
72</p>
73
74<!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
75
76<p class=name id="socket.tcp4">
77socket.<b>tcp4()</b>
78</p>
79
80<p class=description>
81Creates and returns an IPv4 TCP master object. A master object can
82be transformed into a server object with the method
83<a href=#listen><tt>listen</tt></a> (after a call to <a
84href=#bind><tt>bind</tt></a>) or into a client object with
85the method <a href=#connect><tt>connect</tt></a>. The only other
86method supported by a master object is the
87<a href=#close><tt>close</tt></a> method.</p>
88
89<p class=return>
90In 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">
97socket.<b>tcp6()</b>
98</p>
99
100<p class=description>
101Creates and returns an IPv6 TCP master object. A master object can
102be transformed into a server object with the method
103<a href=#listen><tt>listen</tt></a> (after a call to <a
104href=#bind><tt>bind</tt></a>) or into a client object with
105the method <a href=#connect><tt>connect</tt></a>. The only other
106method supported by a master object is the
107<a href=#close><tt>close</tt></a> method.</p>
108
109<p class=return>
110In 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>
115Note: 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">
@@ -252,6 +174,78 @@ first success or until the last failure. If the timeout was
252set to zero, only the first address is tried. 174set to zero, only the first address is tried.
253</p> 175</p>
254 176
177<!-- dirty +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
178
179<p class=name id="dirty">
180master:<b>dirty()</b><br>
181client:<b>dirty()</b><br>
182server:<b>dirty()</b>
183</p>
184
185<p class=description>
186Check the read buffer status.
187</p>
188
189<p class=return>
190Returns <tt>true</tt> if there is any data in the read buffer, <tt>false</tt> otherwise.
191</p>
192
193<p class=note>
194Note: <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">
201master:<b>getfd()</b><br>
202client:<b>getfd()</b><br>
203server:<b>getfd()</b>
204</p>
205
206<p class=description>
207Returns the underling socket descriptor or handle associated to the object.
208</p>
209
210<p class=return>
211The descriptor or handle. In case the object has been closed, the return will be -1.
212</p>
213
214<p class=note>
215Note: <b>This is an internal method. Unlikely to be
216portable. Use at your own risk. </b>
217</p>
218
219
220<!-- getoption ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
221
222<p class=name id="getoption">
223client:<b>getoption(</b>option)</b><br>
224server:<b>getoption(</b>option)</b>
225</p>
226
227<p class=description>
228Gets options for the TCP object.
229See <a href=#setoption><tt>setoption</tt></a> for description of the
230option 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>
244The 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
255<!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 249<!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
256 250
257<p class=name id="getpeername"> 251<p class=name id="getpeername">
@@ -310,6 +304,20 @@ The method returns the number of bytes received, the number of bytes sent,
310and the age of the socket object in seconds. 304and the age of the socket object in seconds.
311</p> 305</p>
312 306
307<!-- gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
308
309<p class=name id="gettimeout">
310master:<b>gettimeout()</b><br>
311client:<b>gettimeout()</b><br>
312server:<b>gettimeout()</b>
313</p>
314
315<p class=description>
316Returns the current block timeout followed by the curent
317total timeout.
318</p>
319
320
313<!-- listen ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 321<!-- listen ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
314 322
315<p class=name id="listen"> 323<p class=name id="listen">
@@ -483,34 +491,6 @@ followed by an error message otherwise.
483Note: The descriptions above come from the man pages. 491Note: The descriptions above come from the man pages.
484</p> 492</p>
485 493
486<!-- getoption ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
487
488<p class=name id="getoption">
489client:<b>getoption(</b>option)</b><br>
490server:<b>getoption(</b>option)</b>
491</p>
492
493<p class=description>
494Gets options for the TCP object.
495See <a href=#setoption><tt>setoption</tt></a> for description of the
496option names and values.
497</p>
498
499<p class=parameters>
500<tt>Option</tt> is a string with the option name.
501<ul>
502
503<li> '<tt>keepalive</tt>'
504<li> '<tt>linger</tt>'
505<li> '<tt>reuseaddr</tt>'
506<li> '<tt>tcp-nodelay</tt>'
507</ul>
508
509<p class=return>
510The method returns the option <tt>value</tt> in case of success, or
511<b><tt>nil</tt></b> followed by an error message otherwise.
512</p>
513
514<!-- setstats +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 494<!-- setstats +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
515 495
516<p class=name id="setstats"> 496<p class=name id="setstats">
@@ -615,66 +595,107 @@ This is the default mode;
615This function returns 1. 595This function returns 1.
616</p> 596</p>
617 597
618<!-- dirty +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 598<!-- setfd +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
619 599
620<p class=name id="dirty"> 600<p class=name id="setfd">
621master:<b>dirty()</b><br> 601master:<b>setfd(</b>fd<b>)</b><br>
622client:<b>dirty()</b><br> 602client:<b>setfd(</b>fd<b>)</b><br>
623server:<b>dirty()</b> 603server:<b>setfd(</b>fd<b>)</b>
624</p> 604</p>
625 605
626<p class=description> 606<p class=description>
627Check the read buffer status. 607Sets 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.
628</p> 608</p>
629 609
630<p class=return> 610<p class=return>
631Returns <tt>true</tt> if there is any data in the read buffer, <tt>false</tt> otherwise. 611No return value.
632</p> 612</p>
633 613
634<p class=note> 614<p class=note>
635Note: <b>This is an internal method, any use is unlikely to be portable.</b> 615Note: <b>This is an internal method. Unlikely to be
616portable. Use at your own risk. </b>
636</p> 617</p>
637 618
638<!-- getfd +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 619<!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
639 620
640<p class=name id="getfd"> 621<p class=name id="socket.tcp">
641master:<b>getfd()</b><br> 622socket.<b>tcp()</b>
642client:<b>getfd()</b><br>
643server:<b>getfd()</b>
644</p> 623</p>
645 624
646<p class=description> 625<p class=description>
647Returns the underling socket descriptor or handle associated to the object. 626Creates and returns an TCP master object. A master object can
648</p> 627be transformed into a server object with the method
628<a href=#listen><tt>listen</tt></a> (after a call to <a
629href=#bind><tt>bind</tt></a>) or into a client object with
630the method <a href=#connect><tt>connect</tt></a>. The only other
631method supported by a master object is the
632<a href=#close><tt>close</tt></a> method.</p>
649 633
650<p class=return> 634<p class=return>
651The descriptor or handle. In case the object has been closed, the return will be -1. 635In case of success, a new master object is returned. In case of error,
636<b><tt>nil</tt></b> is returned, followed by an error message.
637</p>
638
639<p class=note>
640Note: The choice between IPv4 and IPv6 happens during a call to
641<a href=#bind><tt>bind</tt></a> or <a
642href=#bind><tt>connect</tt></a>, depending on the address
643family obtained from the resolver.
652</p> 644</p>
653 645
654<p class=note> 646<p class=note>
655Note: <b>This is an internal method, any use is unlikely to be portable.</b> 647Note: Before the choice between IPv4 and IPv6 happens,
648the internal socket object is invalid and therefore <a
649href=#setoption><tt>setoption</tt></a> will fail.
656</p> 650</p>
657 651
658<!-- setfd +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 652<!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
659 653
660<p class=name id="setfd"> 654<p class=name id="socket.tcp4">
661master:<b>setfd(</b>fd<b>)</b><br> 655socket.<b>tcp4()</b>
662client:<b>setfd(</b>fd<b>)</b><br>
663server:<b>setfd(</b>fd<b>)</b>
664</p> 656</p>
665 657
666<p class=description> 658<p class=description>
667Sets 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. 659Creates and returns an IPv4 TCP master object. A master object can
660be transformed into a server object with the method
661<a href=#listen><tt>listen</tt></a> (after a call to <a
662href=#bind><tt>bind</tt></a>) or into a client object with
663the method <a href=#connect><tt>connect</tt></a>. The only other
664method supported by a master object is the
665<a href=#close><tt>close</tt></a> method.</p>
666
667<p class=return>
668In case of success, a new master object is returned. In case of error,
669<b><tt>nil</tt></b> is returned, followed by an error message.
670</p>
671
672<!-- socket.tcp6 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
673
674<p class=name id="socket.tcp6">
675socket.<b>tcp6()</b>
668</p> 676</p>
669 677
678<p class=description>
679Creates and returns an IPv6 TCP master object. A master object can
680be transformed into a server object with the method
681<a href=#listen><tt>listen</tt></a> (after a call to <a
682href=#bind><tt>bind</tt></a>) or into a client object with
683the method <a href=#connect><tt>connect</tt></a>. The only other
684method supported by a master object is the
685<a href=#close><tt>close</tt></a> method.</p>
686
670<p class=return> 687<p class=return>
671No return value. 688In case of success, a new master object is returned. In case of error,
689<b><tt>nil</tt></b> is returned, followed by an error message.
672</p> 690</p>
673 691
674<p class=note> 692<p class=note>
675Note: <b>This is an internal method, any use is unlikely to be portable.</b> 693Note: The TCP object returned will have the option
694"<tt>ipv6-v6only</tt>" set to <tt><b>true</b></tt>.
676</p> 695</p>
677 696
697
698
678<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 699<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
679 700
680<div class=footer> 701<div class=footer>
diff --git a/doc/udp.html b/doc/udp.html
index 9437c51..4618aad 100644
--- a/doc/udp.html
+++ b/doc/udp.html
@@ -39,112 +39,6 @@
39 39
40<h2 id="udp">UDP</h2> 40<h2 id="udp">UDP</h2>
41 41
42<!-- socket.udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
43
44<p class="name" id="socket.udp">
45socket.<b>udp()</b>
46</p>
47
48<p class="description">
49Creates and returns an unconnected UDP object.
50Unconnected objects support the
51<a href="#sendto"><tt>sendto</tt></a>,
52<a href="#receive"><tt>receive</tt></a>,
53<a href="#receivefrom"><tt>receivefrom</tt></a>,
54<a href="#getoption"><tt>getoption</tt></a>,
55<a href="#getsockname"><tt>getsockname</tt></a>,
56<a href="#setoption"><tt>setoption</tt></a>,
57<a href="#settimeout"><tt>settimeout</tt></a>,
58<a href="#setpeername"><tt>setpeername</tt></a>,
59<a href="#setsockname"><tt>setsockname</tt></a>, and
60<a href="#close"><tt>close</tt></a>.
61The <a href="#setpeername"><tt>setpeername</tt></a>
62is used to connect the object.
63</p>
64
65<p class="return">
66In case of success, a new unconnected UDP object
67returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
68an error message.
69</p>
70
71<p class=note>
72Note: The choice between IPv4 and IPv6 happens during a call to
73<a href=#sendto><tt>sendto</tt></a>, <a
74href=#setpeername><tt>setpeername</tt></a>, or <a
75href=#setsockname><tt>sockname</tt></a>, depending on the address
76family obtained from the resolver.
77</p>
78
79<p class=note>
80Note: Before the choice between IPv4 and IPv6 happens,
81the internal socket object is invalid and therefore <a
82href=#setoption><tt>setoption</tt></a> will fail.
83</p>
84
85<!-- socket.udp4 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
86
87<p class="name" id="socket.udp">
88socket.<b>udp4()</b>
89</p>
90
91<p class="description">
92Creates and returns an unconnected IPv4 UDP object.
93Unconnected objects support the
94<a href="#sendto"><tt>sendto</tt></a>,
95<a href="#receive"><tt>receive</tt></a>,
96<a href="#receivefrom"><tt>receivefrom</tt></a>,
97<a href="#getoption"><tt>getoption</tt></a>,
98<a href="#getsockname"><tt>getsockname</tt></a>,
99<a href="#setoption"><tt>setoption</tt></a>,
100<a href="#settimeout"><tt>settimeout</tt></a>,
101<a href="#setpeername"><tt>setpeername</tt></a>,
102<a href="#setsockname"><tt>setsockname</tt></a>, and
103<a href="#close"><tt>close</tt></a>.
104The <a href="#setpeername"><tt>setpeername</tt></a>
105is used to connect the object.
106</p>
107
108<p class="return">
109In case of success, a new unconnected UDP object
110returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
111an error message.
112</p>
113
114<!-- socket.udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
115
116<p class="name" id="socket.udp6">
117socket.<b>udp6()</b>
118</p>
119
120<p class="description">
121Creates and returns an unconnected IPv6 UDP object.
122Unconnected objects support the
123<a href="#sendto"><tt>sendto</tt></a>,
124<a href="#receive"><tt>receive</tt></a>,
125<a href="#receivefrom"><tt>receivefrom</tt></a>,
126<a href="#getoption"><tt>getoption</tt></a>,
127<a href="#getsockname"><tt>getsockname</tt></a>,
128<a href="#setoption"><tt>setoption</tt></a>,
129<a href="#settimeout"><tt>settimeout</tt></a>,
130<a href="#setpeername"><tt>setpeername</tt></a>,
131<a href="#setsockname"><tt>setsockname</tt></a>, and
132<a href="#close"><tt>close</tt></a>.
133The <a href="#setpeername"><tt>setpeername</tt></a>
134is used to connect the object.
135</p>
136
137<p class="return">
138In case of success, a new unconnected UDP object
139returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
140an error message.
141</p>
142
143<p class=note>
144Note: The TCP object returned will have the option
145"<tt>ipv6-v6only</tt>" set to <tt><b>true</b></tt>.
146</p>
147
148<!-- close +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 42<!-- close +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
149 43
150<p class="name" id="close"> 44<p class="name" id="close">
@@ -168,6 +62,40 @@ Garbage-collected objects are automatically closed before
168destruction, though. 62destruction, though.
169</p> 63</p>
170 64
65<!-- getoption +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
66
67<p class="name" id="getoption">
68connected:<b>getoption()</b><br>
69unconnected:<b>getoption()</b>
70</p>
71
72<p class="description">
73Gets an option value from the UDP object.
74See <a href=#setoption><tt>setoption</tt></a> for
75description of the option names and values.
76</p>
77
78<p class="parameters"><tt>Option</tt> is a string with the option name.
79<ul>
80<li> '<tt>dontroute</tt>'
81<li> '<tt>broadcast</tt>'
82<li> '<tt>reuseaddr</tt>'
83<li> '<tt>reuseport</tt>'
84<li> '<tt>ip-multicast-loop</tt>'
85<li> '<tt>ipv6-v6only</tt>'
86<li> '<tt>ip-multicast-if</tt>'
87<li> '<tt>ip-multicast-ttl</tt>'
88<li> '<tt>ip-add-membership</tt>'
89<li> '<tt>ip-drop-membership</tt>'
90</ul>
91</p>
92
93<p class=return>
94The method returns the option <tt>value</tt> in case of
95success, or
96<b><tt>nil</tt></b> followed by an error message otherwise.
97</p>
98
171<!-- getpeername +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 99<!-- getpeername +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
172 100
173<p class="name" id="getpeername"> 101<p class="name" id="getpeername">
@@ -218,6 +146,18 @@ first time (in which case it is bound to an ephemeral port and the
218wild-card address). 146wild-card address).
219</p> 147</p>
220 148
149<!-- gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
150
151<p class=name id="gettimeout">
152connected:<b>settimeout(</b>value<b>)</b><br>
153unconnected:<b>settimeout(</b>value<b>)</b>
154</p>
155
156<p class=description>
157Returns the current timeout value.
158</p>
159
160
221<!-- receive +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 161<!-- receive +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
222 162
223<p class="name" id="receive"> 163<p class="name" id="receive">
@@ -265,40 +205,6 @@ address and port as extra return values (and is therefore slightly less
265efficient). 205efficient).
266</p> 206</p>
267 207
268<!-- getoption +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
269
270<p class="name" id="getoption">
271connected:<b>getoption()</b><br>
272unconnected:<b>getoption()</b>
273</p>
274
275<p class="description">
276Gets an option value from the UDP object.
277See <a href=#setoption><tt>setoption</tt></a> for
278description of the option names and values.
279</p>
280
281<p class="parameters"><tt>Option</tt> is a string with the option name.
282<ul>
283<li> '<tt>dontroute</tt>'
284<li> '<tt>broadcast</tt>'
285<li> '<tt>reuseaddr</tt>'
286<li> '<tt>reuseport</tt>'
287<li> '<tt>ip-multicast-loop</tt>'
288<li> '<tt>ipv6-v6only</tt>'
289<li> '<tt>ip-multicast-if</tt>'
290<li> '<tt>ip-multicast-ttl</tt>'
291<li> '<tt>ip-add-membership</tt>'
292<li> '<tt>ip-drop-membership</tt>'
293</ul>
294</p>
295
296<p class=return>
297The method returns the option <tt>value</tt> in case of
298success, or
299<b><tt>nil</tt></b> followed by an error message otherwise.
300</p>
301
302<!-- send ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 208<!-- send ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
303 209
304<p class="name" id="send"> 210<p class="name" id="send">
@@ -362,6 +268,75 @@ refuses to send a message to the specified address (i.e. no
362interface accepts the address). 268interface accepts the address).
363</p> 269</p>
364 270
271<!-- setoption +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
272
273<p class="name" id="setoption">
274connected:<b>setoption(</b>option [, value]<b>)</b><br>
275unconnected:<b>setoption(</b>option [, value]<b>)</b>
276</p>
277
278<p class="description">
279Sets options for the UDP object. Options are
280only needed by low-level or time-critical applications. You should
281only modify an option if you are sure you need it.</p>
282<p class="parameters"><tt>Option</tt> is a string with the option
283name, and <tt>value</tt> depends on the option being set:
284</p>
285
286<ul>
287<li> '<tt>dontroute</tt>': Indicates that outgoing
288messages should bypass the standard routing facilities.
289Receives a boolean value;
290<li> '<tt>broadcast</tt>': Requests permission to send
291broadcast datagrams on the socket.
292Receives a boolean value;
293<li> '<tt>reuseaddr</tt>': Indicates that the rules used in
294validating addresses supplied in a <tt>bind()</tt> call
295should allow reuse of local addresses.
296Receives a boolean value;
297<li> '<tt>reuseport</tt>': Allows completely duplicate
298bindings by multiple processes if they all set
299'<tt>reuseport</tt>' before binding the port.
300Receives a boolean value;
301<li> '<tt>ip-multicast-loop</tt>':
302Specifies whether or not a copy of an outgoing multicast
303datagram is delivered to the sending host as long as it is a
304member of the multicast group.
305Receives a boolean value;
306<li> '<tt>ipv6-v6only</tt>':
307Specifies whether to restrict <tt>inet6</tt> sockets to
308sending and receiving only IPv6 packets.
309Receive a boolean value;
310<li> '<tt>ip-multicast-if</tt>':
311Sets the interface over which outgoing multicast datagrams
312are sent.
313Receives an IP address;
314<li> '<tt>ip-multicast-ttl</tt>':
315Sets the Time To Live in the IP header for outgoing
316multicast datagrams.
317Receives a number;
318<li> '<tt>ip-add-membership</tt>':
319Joins the multicast group specified.
320Receives a table with fields
321<tt>multiaddr</tt> and <tt>interface</tt>, each containing an
322IP address;
323<li> '<tt>ip-drop-membership</tt>': Leaves the multicast
324group specified.
325Receives a table with fields
326<tt>multiaddr</tt> and <tt>interface</tt>, each containing an
327IP address.
328</ul>
329
330<p class="return">
331The method returns 1 in case of success, or
332<b><tt>nil</tt></b> followed by an error message otherwise.
333</p>
334
335<p class=note>
336Note: The descriptions above come from the man pages.
337</p>
338
339
365<!-- setpeername +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 340<!-- setpeername +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
366 341
367<p class="name" id="setpeername"> 342<p class="name" id="setpeername">
@@ -448,74 +423,6 @@ system or explicitly by <tt>setsockname</tt>, it cannot be
448changed. 423changed.
449</p> 424</p>
450 425
451<!-- setoption +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
452
453<p class="name" id="setoption">
454connected:<b>setoption(</b>option [, value]<b>)</b><br>
455unconnected:<b>setoption(</b>option [, value]<b>)</b>
456</p>
457
458<p class="description">
459Sets options for the UDP object. Options are
460only needed by low-level or time-critical applications. You should
461only modify an option if you are sure you need it.</p>
462<p class="parameters"><tt>Option</tt> is a string with the option
463name, and <tt>value</tt> depends on the option being set:
464</p>
465
466<ul>
467<li> '<tt>dontroute</tt>': Indicates that outgoing
468messages should bypass the standard routing facilities.
469Receives a boolean value;
470<li> '<tt>broadcast</tt>': Requests permission to send
471broadcast datagrams on the socket.
472Receives a boolean value;
473<li> '<tt>reuseaddr</tt>': Indicates that the rules used in
474validating addresses supplied in a <tt>bind()</tt> call
475should allow reuse of local addresses.
476Receives a boolean value;
477<li> '<tt>reuseport</tt>': Allows completely duplicate
478bindings by multiple processes if they all set
479'<tt>reuseport</tt>' before binding the port.
480Receives a boolean value;
481<li> '<tt>ip-multicast-loop</tt>':
482Specifies whether or not a copy of an outgoing multicast
483datagram is delivered to the sending host as long as it is a
484member of the multicast group.
485Receives a boolean value;
486<li> '<tt>ipv6-v6only</tt>':
487Specifies whether to restrict <tt>inet6</tt> sockets to
488sending and receiving only IPv6 packets.
489Receive a boolean value;
490<li> '<tt>ip-multicast-if</tt>':
491Sets the interface over which outgoing multicast datagrams
492are sent.
493Receives an IP address;
494<li> '<tt>ip-multicast-ttl</tt>':
495Sets the Time To Live in the IP header for outgoing
496multicast datagrams.
497Receives a number;
498<li> '<tt>ip-add-membership</tt>':
499Joins the multicast group specified.
500Receives a table with fields
501<tt>multiaddr</tt> and <tt>interface</tt>, each containing an
502IP address;
503<li> '<tt>ip-drop-membership</tt>': Leaves the multicast
504group specified.
505Receives a table with fields
506<tt>multiaddr</tt> and <tt>interface</tt>, each containing an
507IP address.
508</ul>
509
510<p class="return">
511The method returns 1 in case of success, or
512<b><tt>nil</tt></b> followed by an error message otherwise.
513</p>
514
515<p class=note>
516Note: The descriptions above come from the man pages.
517</p>
518
519<!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 426<!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
520 427
521<p class="name" id="settimeout"> 428<p class="name" id="settimeout">
@@ -556,6 +463,114 @@ all other method names already contained verbs making their
556imperative nature obvious. 463imperative nature obvious.
557</p> 464</p>
558 465
466<!-- socket.udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
467
468<p class="name" id="socket.udp">
469socket.<b>udp()</b>
470</p>
471
472<p class="description">
473Creates and returns an unconnected UDP object.
474Unconnected objects support the
475<a href="#sendto"><tt>sendto</tt></a>,
476<a href="#receive"><tt>receive</tt></a>,
477<a href="#receivefrom"><tt>receivefrom</tt></a>,
478<a href="#getoption"><tt>getoption</tt></a>,
479<a href="#getsockname"><tt>getsockname</tt></a>,
480<a href="#setoption"><tt>setoption</tt></a>,
481<a href="#settimeout"><tt>settimeout</tt></a>,
482<a href="#setpeername"><tt>setpeername</tt></a>,
483<a href="#setsockname"><tt>setsockname</tt></a>, and
484<a href="#close"><tt>close</tt></a>.
485The <a href="#setpeername"><tt>setpeername</tt></a>
486is used to connect the object.
487</p>
488
489<p class="return">
490In case of success, a new unconnected UDP object
491returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
492an error message.
493</p>
494
495<p class=note>
496Note: The choice between IPv4 and IPv6 happens during a call to
497<a href=#sendto><tt>sendto</tt></a>, <a
498href=#setpeername><tt>setpeername</tt></a>, or <a
499href=#setsockname><tt>sockname</tt></a>, depending on the address
500family obtained from the resolver.
501</p>
502
503<p class=note>
504Note: Before the choice between IPv4 and IPv6 happens,
505the internal socket object is invalid and therefore <a
506href=#setoption><tt>setoption</tt></a> will fail.
507</p>
508
509<!-- socket.udp4 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
510
511<p class="name" id="socket.udp">
512socket.<b>udp4()</b>
513</p>
514
515<p class="description">
516Creates and returns an unconnected IPv4 UDP object.
517Unconnected objects support the
518<a href="#sendto"><tt>sendto</tt></a>,
519<a href="#receive"><tt>receive</tt></a>,
520<a href="#receivefrom"><tt>receivefrom</tt></a>,
521<a href="#getoption"><tt>getoption</tt></a>,
522<a href="#getsockname"><tt>getsockname</tt></a>,
523<a href="#setoption"><tt>setoption</tt></a>,
524<a href="#settimeout"><tt>settimeout</tt></a>,
525<a href="#setpeername"><tt>setpeername</tt></a>,
526<a href="#setsockname"><tt>setsockname</tt></a>, and
527<a href="#close"><tt>close</tt></a>.
528The <a href="#setpeername"><tt>setpeername</tt></a>
529is used to connect the object.
530</p>
531
532<p class="return">
533In case of success, a new unconnected UDP object
534returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
535an error message.
536</p>
537
538<!-- socket.udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
539
540<p class="name" id="socket.udp6">
541socket.<b>udp6()</b>
542</p>
543
544<p class="description">
545Creates and returns an unconnected IPv6 UDP object.
546Unconnected objects support the
547<a href="#sendto"><tt>sendto</tt></a>,
548<a href="#receive"><tt>receive</tt></a>,
549<a href="#receivefrom"><tt>receivefrom</tt></a>,
550<a href="#getoption"><tt>getoption</tt></a>,
551<a href="#getsockname"><tt>getsockname</tt></a>,
552<a href="#setoption"><tt>setoption</tt></a>,
553<a href="#settimeout"><tt>settimeout</tt></a>,
554<a href="#setpeername"><tt>setpeername</tt></a>,
555<a href="#setsockname"><tt>setsockname</tt></a>, and
556<a href="#close"><tt>close</tt></a>.
557The <a href="#setpeername"><tt>setpeername</tt></a>
558is used to connect the object.
559</p>
560
561<p class="return">
562In case of success, a new unconnected UDP object
563returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
564an error message.
565</p>
566
567<p class=note>
568Note: The TCP object returned will have the option
569"<tt>ipv6-v6only</tt>" set to <tt><b>true</b></tt>.
570</p>
571
572
573
559<!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 574<!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
560 575
561<div class=footer> 576<div class=footer>
diff --git a/src/tcp.c b/src/tcp.c
index e4f1a4b..ef9ee6f 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -36,6 +36,7 @@ static int meth_accept(lua_State *L);
36static int meth_close(lua_State *L); 36static int meth_close(lua_State *L);
37static int meth_getoption(lua_State *L); 37static int meth_getoption(lua_State *L);
38static int meth_setoption(lua_State *L); 38static int meth_setoption(lua_State *L);
39static int meth_gettimeout(lua_State *L);
39static int meth_settimeout(lua_State *L); 40static int meth_settimeout(lua_State *L);
40static int meth_getfd(lua_State *L); 41static int meth_getfd(lua_State *L);
41static int meth_setfd(lua_State *L); 42static int meth_setfd(lua_State *L);
@@ -65,6 +66,7 @@ static luaL_Reg tcp_methods[] = {
65 {"setpeername", meth_connect}, 66 {"setpeername", meth_connect},
66 {"setsockname", meth_bind}, 67 {"setsockname", meth_bind},
67 {"settimeout", meth_settimeout}, 68 {"settimeout", meth_settimeout},
69 {"gettimeout", meth_gettimeout},
68 {"shutdown", meth_shutdown}, 70 {"shutdown", meth_shutdown},
69 {NULL, NULL} 71 {NULL, NULL}
70}; 72};
@@ -350,6 +352,12 @@ static int meth_settimeout(lua_State *L)
350 return timeout_meth_settimeout(L, &tcp->tm); 352 return timeout_meth_settimeout(L, &tcp->tm);
351} 353}
352 354
355static int meth_gettimeout(lua_State *L)
356{
357 p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, "tcp{any}", 1);
358 return timeout_meth_gettimeout(L, &tcp->tm);
359}
360
353/*=========================================================================*\ 361/*=========================================================================*\
354* Library functions 362* Library functions
355\*=========================================================================*/ 363\*=========================================================================*/
diff --git a/src/timeout.c b/src/timeout.c
index 087d033..5a601d5 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -173,6 +173,16 @@ int timeout_meth_settimeout(lua_State *L, p_timeout tm) {
173 return 1; 173 return 1;
174} 174}
175 175
176/*-------------------------------------------------------------------------*\
177* Gets timeout values for IO operations
178* Lua Output: block, total
179\*-------------------------------------------------------------------------*/
180int timeout_meth_gettimeout(lua_State *L, p_timeout tm) {
181 lua_pushnumber(L, tm->block);
182 lua_pushnumber(L, tm->total);
183 return 2;
184}
185
176/*=========================================================================*\ 186/*=========================================================================*\
177* Test support functions 187* Test support functions
178\*=========================================================================*/ 188\*=========================================================================*/
diff --git a/src/timeout.h b/src/timeout.h
index 6715ca7..af90231 100644
--- a/src/timeout.h
+++ b/src/timeout.h
@@ -22,6 +22,7 @@ p_timeout timeout_markstart(p_timeout tm);
22double timeout_getstart(p_timeout tm); 22double timeout_getstart(p_timeout tm);
23double timeout_gettime(void); 23double timeout_gettime(void);
24int timeout_meth_settimeout(lua_State *L, p_timeout tm); 24int timeout_meth_settimeout(lua_State *L, p_timeout tm);
25int timeout_meth_gettimeout(lua_State *L, p_timeout tm);
25 26
26#define timeout_iszero(tm) ((tm)->block == 0.0) 27#define timeout_iszero(tm) ((tm)->block == 0.0)
27 28
diff --git a/src/udp.c b/src/udp.c
index 968dca8..ec97252 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -36,6 +36,7 @@ static int meth_receivefrom(lua_State *L);
36static int meth_getfamily(lua_State *L); 36static int meth_getfamily(lua_State *L);
37static int meth_getsockname(lua_State *L); 37static int meth_getsockname(lua_State *L);
38static int meth_getpeername(lua_State *L); 38static int meth_getpeername(lua_State *L);
39static int meth_gettimeout(lua_State *L);
39static int meth_setsockname(lua_State *L); 40static int meth_setsockname(lua_State *L);
40static int meth_setpeername(lua_State *L); 41static int meth_setpeername(lua_State *L);
41static int meth_close(lua_State *L); 42static int meth_close(lua_State *L);
@@ -66,6 +67,7 @@ static luaL_Reg udp_methods[] = {
66 {"setpeername", meth_setpeername}, 67 {"setpeername", meth_setpeername},
67 {"setsockname", meth_setsockname}, 68 {"setsockname", meth_setsockname},
68 {"settimeout", meth_settimeout}, 69 {"settimeout", meth_settimeout},
70 {"gettimeout", meth_gettimeout},
69 {NULL, NULL} 71 {NULL, NULL}
70}; 72};
71 73
@@ -347,6 +349,11 @@ static int meth_settimeout(lua_State *L) {
347 return timeout_meth_settimeout(L, &udp->tm); 349 return timeout_meth_settimeout(L, &udp->tm);
348} 350}
349 351
352static int meth_gettimeout(lua_State *L) {
353 p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1);
354 return timeout_meth_gettimeout(L, &udp->tm);
355}
356
350/*-------------------------------------------------------------------------*\ 357/*-------------------------------------------------------------------------*\
351* Turns a master udp object into a client object. 358* Turns a master udp object into a client object.
352\*-------------------------------------------------------------------------*/ 359\*-------------------------------------------------------------------------*/