aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-20 22:19:54 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-20 22:19:54 +0000
commitf7579db9e830ef41f422a280d26c9077f48728e5 (patch)
treed96affac7f5e8203d2e9c4a053213a992cd76650
parent5dc5c3ebe8f111bba01762ca0f5edba912c4f0b9 (diff)
downloadluasocket-f7579db9e830ef41f422a280d26c9077f48728e5.tar.gz
luasocket-f7579db9e830ef41f422a280d26c9077f48728e5.tar.bz2
luasocket-f7579db9e830ef41f422a280d26c9077f48728e5.zip
Fixing bugs...
-rw-r--r--doc/dns.html2
-rw-r--r--doc/ftp.html18
-rw-r--r--doc/http.html18
-rw-r--r--doc/index.html6
-rw-r--r--doc/introduction.html2
-rw-r--r--doc/ltn12.html2
-rw-r--r--doc/mime.html2
-rw-r--r--doc/reference.css2
-rw-r--r--doc/reference.html4
-rw-r--r--doc/smtp.html28
-rw-r--r--doc/socket.html31
-rw-r--r--doc/tcp.html8
-rw-r--r--doc/udp.html2
-rw-r--r--doc/url.html8
-rw-r--r--etc/get.lua14
-rw-r--r--src/except.c2
-rw-r--r--src/ftp.lua2
-rw-r--r--src/tcp.c2
-rw-r--r--src/timeout.c26
-rw-r--r--src/usocket.c11
-rw-r--r--src/wsocket.c5
-rw-r--r--test/httptest.lua4
-rw-r--r--test/mimetest.lua4
-rw-r--r--test/testclnt.lua18
24 files changed, 127 insertions, 94 deletions
diff --git a/doc/dns.html b/doc/dns.html
index 67b24ca..47134d8 100644
--- a/doc/dns.html
+++ b/doc/dns.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
diff --git a/doc/ftp.html b/doc/ftp.html
index 14a3601..fe514e9 100644
--- a/doc/ftp.html
+++ b/doc/ftp.html
@@ -14,7 +14,7 @@
14<center> 14<center>
15<table summary="LuaSocket logo"> 15<table summary="LuaSocket logo">
16<tr><td align=center><a href="http://www.lua.org"> 16<tr><td align=center><a href="http://www.lua.org">
17<img border=0 alt="LuaSocket" src="luasocket.png"> 17<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
18</a></td></tr> 18</a></td></tr>
19<tr><td align=center valign=top>Network support for the Lua language 19<tr><td align=center valign=top>Network support for the Lua language
20</td></tr> 20</td></tr>
@@ -227,10 +227,10 @@ message describing the reason for failure.
227-- load the ftp support 227-- load the ftp support
228local ftp = require("ftp") 228local ftp = require("ftp")
229 229
230-- Log as user "diego" on server "ftp.tecgraf.puc-rio.br", 230-- Log as user "fulano" on server "ftp.example.com",
231-- using password "nehab", and store a file "README" with contents 231-- using password "silva", and store a file "README" with contents
232-- "wrong password, of course" 232-- "wrong password, of course"
233f, e = ftp.put("ftp://diego:nehab@ftp.tecgraf.puc-rio.br/README", 233f, e = ftp.put("ftp://fulano:silva@ftp.example.com/README",
234 "wrong password, of course") 234 "wrong password, of course")
235</pre> 235</pre>
236 236
@@ -239,13 +239,13 @@ f, e = ftp.put("ftp://diego:nehab@ftp.tecgraf.puc-rio.br/README",
239local ftp = require("ftp") 239local ftp = require("ftp")
240local ltn12 = require("ltn12") 240local ltn12 = require("ltn12")
241 241
242-- Log as user "diego" on server "ftp.tecgraf.puc-rio.br", 242-- Log as user "fulano" on server "ftp.example.com",
243-- using password "nehab", and append to the remote file "LOG", sending the 243-- using password "silva", and append to the remote file "LOG", sending the
244-- contents of the local file "LOCAL-LOG" 244-- contents of the local file "LOCAL-LOG"
245f, e = ftp.put{ 245f, e = ftp.put{
246 host = "ftp.tecgraf.puc-rio.br", 246 host = "ftp.example.com",
247 user = "diego", 247 user = "fulano",
248 password = "nehab", 248 password = "silva",
249 command = "appe", 249 command = "appe",
250 argument = "LOG", 250 argument = "LOG",
251 source = ltn12.source.file(io.open("LOCAL-LOG", "r")) 251 source = ltn12.source.file(io.open("LOCAL-LOG", "r"))
diff --git a/doc/http.html b/doc/http.html
index a98915c..4780436 100644
--- a/doc/http.html
+++ b/doc/http.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
@@ -209,9 +209,9 @@ http = require("http")
209-- file from "/luasocket/http.html" 209-- file from "/luasocket/http.html"
210b = http.request("http://www.tecgraf.puc-rio.br/luasocket/http.html") 210b = http.request("http://www.tecgraf.puc-rio.br/luasocket/http.html")
211 211
212-- connect to server "www.tecgraf.puc-rio.br" and tries to retrieve 212-- connect to server "www.example.com" and tries to retrieve
213-- "~diego/auth/index.html". Fails because authentication is needed. 213-- "/private/index.html". Fails because authentication is needed.
214b, c, h = http.request("http://www.tecgraf.puc-rio.br/~diego/auth/index.html") 214b, c, h = http.request("http://www.example.com/private/index.html")
215-- b returns some useless page telling about the denied access, 215-- b returns some useless page telling about the denied access,
216-- h returns authentication information 216-- h returns authentication information
217-- and c returns with value 401 (Authentication Required) 217-- and c returns with value 401 (Authentication Required)
@@ -276,16 +276,16 @@ authentication is required.
276http = require("http") 276http = require("http")
277mime = require("mime") 277mime = require("mime")
278 278
279-- Connect to server "www.tecgraf.puc-rio.br" and tries to retrieve 279-- Connect to server "www.example.com" and tries to retrieve
280-- "~diego/auth/index.html", using the provided name and password to 280-- "/private/index.html", using the provided name and password to
281-- authenticate the request 281-- authenticate the request
282b, c, h = http.request("http://diego:password@www.tecgraf.puc-rio.br/~diego/auth/index.html") 282b, c, h = http.request("http://fulano:silva@www.example.com/private/index.html")
283 283
284-- Alternatively, one could fill the appropriate header and authenticate 284-- Alternatively, one could fill the appropriate header and authenticate
285-- the request directly. 285-- the request directly.
286r, c = http.request { 286r, c = http.request {
287 url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html", 287 url = "http://www.example.com/private/index.html",
288 headers = { authentication = "Basic " .. (mime.b64("diego:password")) } 288 headers = { authentication = "Basic " .. (mime.b64("fulano:silva")) }
289} 289}
290</pre> 290</pre>
291 291
diff --git a/doc/index.html b/doc/index.html
index 7394386..0e9eb1d 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
@@ -216,7 +216,7 @@ the changes that made it into version 2.0:
216 216
217<li> Select checks if sockets have buffered data and returns immediately; 217<li> Select checks if sockets have buffered data and returns immediately;
218 218
219<li> <tt>socket.sleep</tt> and <tt>socket.time</tt> are now part of the 219<li> <tt>socket.sleep</tt> and <tt>socket.gettime</tt> are now part of the
220 library and are supported. They used to be available only when 220 library and are supported. They used to be available only when
221 LUASOCKET_DEBUG was defined, but it turns out they might be useful for 221 LUASOCKET_DEBUG was defined, but it turns out they might be useful for
222 applications; 222 applications;
@@ -276,6 +276,8 @@ return convention WILL break old code;
276 does not call <tt>listen</tt> anymore. It is the new <tt>listen</tt> 276 does not call <tt>listen</tt> anymore. It is the new <tt>listen</tt>
277method that turns a TCP object into a server object; 277method that turns a TCP object into a server object;
278 278
279<li> <tt>socket.time</tt> became <tt>socket.gettime</tt> for uniformity;
280
279<li> Interface to options has changed. 281<li> Interface to options has changed.
280 282
281</ul> 283</ul>
diff --git a/doc/introduction.html b/doc/introduction.html
index 8706c83..2c738d6 100644
--- a/doc/introduction.html
+++ b/doc/introduction.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
diff --git a/doc/ltn12.html b/doc/ltn12.html
index 23b9ff8..bfb9b51 100644
--- a/doc/ltn12.html
+++ b/doc/ltn12.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
diff --git a/doc/mime.html b/doc/mime.html
index 520c8ff..0f4ffa8 100644
--- a/doc/mime.html
+++ b/doc/mime.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
diff --git a/doc/reference.css b/doc/reference.css
index 7c8148d..b1dd25d 100644
--- a/doc/reference.css
+++ b/doc/reference.css
@@ -1,7 +1,7 @@
1body { 1body {
2 margin-left: 1em; 2 margin-left: 1em;
3 margin-right: 1em; 3 margin-right: 1em;
4 font-family: "Verdana"; 4 font-family: "Verdana", sans-serif;
5} 5}
6 6
7tt { 7tt {
diff --git a/doc/reference.html b/doc/reference.html
index ec81d72..5c07c4d 100644
--- a/doc/reference.html
+++ b/doc/reference.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
@@ -140,6 +140,7 @@
140<blockquote> 140<blockquote>
141<a href="socket.html#debug">DEBUG</a>, 141<a href="socket.html#debug">DEBUG</a>,
142<a href="dns.html#dns">dns</a>, 142<a href="dns.html#dns">dns</a>,
143<a href="socket.html#gettime">gettime</a>,
143<a href="socket.html#newtry">newtry</a>, 144<a href="socket.html#newtry">newtry</a>,
144<a href="socket.html#protect">protect</a>, 145<a href="socket.html#protect">protect</a>,
145<a href="socket.html#select">select</a>, 146<a href="socket.html#select">select</a>,
@@ -147,7 +148,6 @@
147<a href="socket.html#skip">skip</a>, 148<a href="socket.html#skip">skip</a>,
148<a href="socket.html#sleep">sleep</a>, 149<a href="socket.html#sleep">sleep</a>,
149<a href="socket.html#source">source</a>, 150<a href="socket.html#source">source</a>,
150<a href="socket.html#time">time</a>,
151<a href="tcp.html#tcp">tcp</a>, 151<a href="tcp.html#tcp">tcp</a>,
152<a href="socket.html#try">try</a>, 152<a href="socket.html#try">try</a>,
153<a href="udp.html#udp">udp</a>, 153<a href="udp.html#udp">udp</a>,
diff --git a/doc/smtp.html b/doc/smtp.html
index 89f4757..224dde3 100644
--- a/doc/smtp.html
+++ b/doc/smtp.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
@@ -165,7 +165,7 @@ If successful, the function returns 1. Otherwise, the function returns
165<p class=note> 165<p class=note>
166Note: SMTP servers are can be very picky with the format of e-mail 166Note: SMTP servers are can be very picky with the format of e-mail
167addresses. To be safe, use only addresses of the form 167addresses. To be safe, use only addresses of the form
168"<tt>&lt;fulano@tecgraf.puc-rio.br&gt;</tt>" in the <tt>from</tt> and 168"<tt>&lt;fulano@example.com&gt;</tt>" in the <tt>from</tt> and
169<tt>rcpt</tt> arguments to the <tt>send</tt> function. In headers, e-mail 169<tt>rcpt</tt> arguments to the <tt>send</tt> function. In headers, e-mail
170addresses can take whatever form you like. </p> 170addresses can take whatever form you like. </p>
171 171
@@ -238,23 +238,23 @@ and
238local smtp = require("smtp") 238local smtp = require("smtp")
239 239
240-- Connects to server "localhost" and sends a message to users 240-- Connects to server "localhost" and sends a message to users
241-- "fulano@tecgraf.puc-rio.br", "beltrano@tecgraf.puc-rio.br", 241-- "fulano@example.com", "beltrano@example.com",
242-- and "sicrano@tecgraf.puc-rio.br". 242-- and "sicrano@example.com".
243-- Note that "fulano" is the primary recipient, "beltrano" receives a 243-- Note that "fulano" is the primary recipient, "beltrano" receives a
244-- carbon copy and neither of them knows that "sicrano" received a blind 244-- carbon copy and neither of them knows that "sicrano" received a blind
245-- carbon copy of the message. 245-- carbon copy of the message.
246from = "&lt;luasocket@tecgraf.puc-rio.br&gt;" 246from = "&lt;luasocket@example.com&gt;"
247 247
248rcpt = { 248rcpt = {
249 "&lt;fulano@tecgraf.puc-rio.br&gt;", 249 "&lt;fulano@example.com&gt;",
250 "&lt;beltrano@tecgraf.puc-rio.br&gt;", 250 "&lt;beltrano@example.com&gt;",
251 "&lt;sicrano@tecgraf.puc-rio.br&gt;" 251 "&lt;sicrano@example.com&gt;"
252} 252}
253 253
254mesgt = { 254mesgt = {
255 headers = { 255 headers = {
256 to = "Fulano da Silva &lt;fulano@tecgraf.puc-rio.br&gt;", 256 to = "Fulano da Silva &lt;fulano@example.com&gt;",
257 cc = '"Beltrano F. Nunes" &lt;beltrano@tecgraf.puc-rio.br&gt;', 257 cc = '"Beltrano F. Nunes" &lt;beltrano@example.com&gt;',
258 subject = "My first message" 258 subject = "My first message"
259 } 259 }
260 body = "I hope this works. If it does, I can send you another 1000 copies." 260 body = "I hope this works. If it does, I can send you another 1000 copies."
@@ -334,8 +334,8 @@ local ltn12 = require("ltn12")
334source = smtp.message{ 334source = smtp.message{
335 headers = { 335 headers = {
336 -- Remember that headers are *ignored* by smtp.send. 336 -- Remember that headers are *ignored* by smtp.send.
337 from = "Sicrano de Oliveira &lt;sicrano@tecgraf.puc-rio.br&gt;", 337 from = "Sicrano de Oliveira &lt;sicrano@example.com&gt;",
338 to = "Fulano da Silva &lt;fulano@tecgraf.puc-rio.br&gt;", 338 to = "Fulano da Silva &lt;fulano@example.com&gt;",
339 subject = "Here is a message with attachments" 339 subject = "Here is a message with attachments"
340 }, 340 },
341 body = { 341 body = {
@@ -378,8 +378,8 @@ source = smtp.message{
378 378
379-- finally send it 379-- finally send it
380r, e = smtp.send{ 380r, e = smtp.send{
381 from = "&lt;sicrano@tecgraf.puc-rio.br&gt;", 381 from = "&lt;sicrano@example.com&gt;",
382 rcpt = "&lt;fulano@tecgraf.puc-rio.br&gt;", 382 rcpt = "&lt;fulano@example.com&gt;",
383 source = source, 383 source = source,
384} 384}
385</pre> 385</pre>
diff --git a/doc/socket.html b/doc/socket.html
index 4d77478..1bbeb7f 100644
--- a/doc/socket.html
+++ b/doc/socket.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
@@ -48,6 +48,27 @@ To obtain the <tt>socket</tt> namespace, run:
48local socket = require("socket") 48local socket = require("socket")
49</pre> 49</pre>
50 50
51<!-- bind ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
52
53<p class=name id=bind>
54socket.<b>bind(</b>address, port [, backlog]<b>)</b>
55</p>
56
57<p class=description>
58</p>
59
60<!-- connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
61
62<p class=name id=connect>
63socket.<b>connect(</b>address, port [, locaddr, locport]<b>)</b>
64</p>
65
66<p class=description>
67This function is a shortcut that creates and returns a TCP socket object
68connected to a remote <tt>host</tt> at a given <tt>port</tt>. Optionally,
69the use can also specify the local address and port to bind
70(<tt>locaddr</tt> and </tt>locport</tt>).
71</p>
51 72
52<!-- debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 73<!-- debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
53 74
@@ -289,8 +310,8 @@ The function returns a source with the appropriate behavior.
289 310
290<!-- time ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 311<!-- time ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
291 312
292<p class=name id=time> 313<p class=name id=gettime>
293socket.<b>time()</b> 314socket.<b>gettime()</b>
294</p> 315</p>
295 316
296<p class=description> 317<p class=description>
@@ -304,9 +325,9 @@ The function returns the time as a number.
304</p> 325</p>
305 326
306<pre class=example> 327<pre class=example>
307t = socket.time() 328t = socket.gettime()
308-- do stuff 329-- do stuff
309print(socket.time() - t .. " seconds elapsed") 330print(socket.gettime() - t .. " seconds elapsed")
310</pre> 331</pre>
311 332
312<!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 333<!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
diff --git a/doc/tcp.html b/doc/tcp.html
index cd417a5..37b0b56 100644
--- a/doc/tcp.html
+++ b/doc/tcp.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
@@ -74,7 +74,7 @@ reported by <b><tt>nil</tt></b> followed by a message describing the error.
74</p> 74</p>
75 75
76<p class=note> 76<p class=note>
77Note: calling <a href=misc.html#socket.select><tt>socket.select</tt></a> 77Note: calling <a href=sockett.html#select><tt>socket.select</tt></a>
78with a server object in 78with a server object in
79the <tt>receive</tt> parameter before a call to <tt>accept</tt> does 79the <tt>receive</tt> parameter before a call to <tt>accept</tt> does
80<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
@@ -94,7 +94,7 @@ local host.
94 94
95<p class=parameters> 95<p class=parameters>
96<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.
97<tt>Port</tt> must be an integer number in the range [0..64K]. 97<tt>Port</tt> must be an integer number in the range [0..64K).
98If <tt>address</tt> 98If <tt>address</tt>
99is '<tt>*</tt>', the system binds to all local interfaces 99is '<tt>*</tt>', the system binds to all local interfaces
100using the <tt>INADDR_ANY</tt> constant. If <tt>port</tt> is 0, the system automatically 100using the <tt>INADDR_ANY</tt> constant. If <tt>port</tt> is 0, the system automatically
@@ -154,7 +154,7 @@ and <a href=#close><tt>close</tt></a>.
154 154
155<p class=parameters> 155<p class=parameters>
156<tt>Address</tt> can be an IP address or a host name. 156<tt>Address</tt> can be an IP address or a host name.
157<tt>Port</tt> must be an integer number in the range [1..64K]. 157<tt>Port</tt> must be an integer number in the range [1..64K).
158</p> 158</p>
159 159
160<p class=return> 160<p class=return>
diff --git a/doc/udp.html b/doc/udp.html
index 6f2e607..69895ce 100644
--- a/doc/udp.html
+++ b/doc/udp.html
@@ -14,7 +14,7 @@
14<center> 14<center>
15<table summary="LuaSocket logo"> 15<table summary="LuaSocket logo">
16<tr><td align=center><a href="http://www.lua.org"> 16<tr><td align=center><a href="http://www.lua.org">
17<img border=0 alt="LuaSocket" src="luasocket.png"> 17<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
18</a></td></tr> 18</a></td></tr>
19<tr><td align=center valign=top>Network support for the Lua language 19<tr><td align=center valign=top>Network support for the Lua language
20</td></tr> 20</td></tr>
diff --git a/doc/url.html b/doc/url.html
index 46e6e09..207995c 100644
--- a/doc/url.html
+++ b/doc/url.html
@@ -16,7 +16,7 @@
16<center> 16<center>
17<table summary="LuaSocket logo"> 17<table summary="LuaSocket logo">
18<tr><td align=center><a href="http://www.lua.org"> 18<tr><td align=center><a href="http://www.lua.org">
19<img border=0 alt="LuaSocket" src="luasocket.png"> 19<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
20</a></td></tr> 20</a></td></tr>
21<tr><td align=center valign=top>Network support for the Lua language 21<tr><td align=center valign=top>Network support for the Lua language
22</td></tr> 22</td></tr>
@@ -238,11 +238,11 @@ parsed_url = {<br>
238-- load url module 238-- load url module
239url = require("url") 239url = require("url")
240 240
241parsed_url = url.parse("http://www.puc-rio.br/~diego/index.lua?a=2#there") 241parsed_url = url.parse("http://www.example.com/cgilua/index.lua?a=2#there")
242-- parsed_url = { 242-- parsed_url = {
243-- scheme = "http", 243-- scheme = "http",
244-- authority = "www.puc-rio.br", 244-- authority = "www.example.com",
245-- path = "/~diego/index.lua" 245-- path = "/cgilua/index.lua"
246-- query = "a=2", 246-- query = "a=2",
247-- fragment = "there", 247-- fragment = "there",
248-- host = "www.puc-rio.br", 248-- host = "www.puc-rio.br",
diff --git a/etc/get.lua b/etc/get.lua
index c7e2a43..712d807 100644
--- a/etc/get.lua
+++ b/etc/get.lua
@@ -4,11 +4,11 @@
4-- Author: Diego Nehab 4-- Author: Diego Nehab
5-- RCS ID: $Id$ 5-- RCS ID: $Id$
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7socket = require("socket") 7local socket = require("socket")
8http = require("http") 8local http = require("http")
9ftp = require("ftp") 9local ftp = require("ftp")
10url = require("url") 10local url = require("url")
11ltn12 = require("ltn12") 11local ltn12 = require("ltn12")
12 12
13-- formats a number of seconds into human readable form 13-- formats a number of seconds into human readable form
14function nicetime(s) 14function nicetime(s)
@@ -64,11 +64,11 @@ end
64-- creates a new instance of a receive_cb that saves to disk 64-- creates a new instance of a receive_cb that saves to disk
65-- kind of copied from luasocket's manual callback examples 65-- kind of copied from luasocket's manual callback examples
66function stats(size) 66function stats(size)
67 local start = socket.time() 67 local start = socket.gettime()
68 local got = 0 68 local got = 0
69 return function(chunk) 69 return function(chunk)
70 -- elapsed time since start 70 -- elapsed time since start
71 local delta = socket.time() - start 71 local delta = socket.gettime() - start
72 if chunk then 72 if chunk then
73 -- total bytes received 73 -- total bytes received
74 got = got + string.len(chunk) 74 got = got + string.len(chunk)
diff --git a/src/except.c b/src/except.c
index 68abf70..ad03817 100644
--- a/src/except.c
+++ b/src/except.c
@@ -29,7 +29,7 @@ static luaL_reg func[] = {
29* Try factory 29* Try factory
30\*-------------------------------------------------------------------------*/ 30\*-------------------------------------------------------------------------*/
31static int finalize(lua_State *L) { 31static int finalize(lua_State *L) {
32 if (lua_isnil(L, 1) || (lua_isboolean(L, 1) && !lua_toboolean(L, 1))) { 32 if (!lua_toboolean(L, 1)) {
33 lua_pushvalue(L, lua_upvalueindex(1)); 33 lua_pushvalue(L, lua_upvalueindex(1));
34 lua_pcall(L, 0, 0, 0); 34 lua_pcall(L, 0, 0, 0);
35 lua_settop(L, 2); 35 lua_settop(L, 2);
diff --git a/src/ftp.lua b/src/ftp.lua
index 1c7ea71..4e2bb62 100644
--- a/src/ftp.lua
+++ b/src/ftp.lua
@@ -32,7 +32,7 @@ local metat = { __index = {} }
32 32
33function open(server, port) 33function open(server, port)
34 local tp = socket.try(tp.connect(server, port or PORT, TIMEOUT)) 34 local tp = socket.try(tp.connect(server, port or PORT, TIMEOUT))
35 local f = setmetat({ tp = tp }, metat) 35 local f = setmetatable({ tp = tp }, metat)
36 -- make sure everything gets closed in an exception 36 -- make sure everything gets closed in an exception
37 f.try = socket.newtry(function() f:close() end) 37 f.try = socket.newtry(function() f:close() end)
38 return f 38 return f
diff --git a/src/tcp.c b/src/tcp.c
index 845e0a3..adc2585 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -283,7 +283,7 @@ static int meth_getpeername(lua_State *L)
283 283
284static int meth_getsockname(lua_State *L) 284static int meth_getsockname(lua_State *L)
285{ 285{
286 p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{client,server}", 1); 286 p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1);
287 return inet_meth_getsockname(L, &tcp->sock); 287 return inet_meth_getsockname(L, &tcp->sock);
288} 288}
289 289
diff --git a/src/timeout.c b/src/timeout.c
index 3472ca7..e089051 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -18,12 +18,6 @@
18#else 18#else
19#include <time.h> 19#include <time.h>
20#include <sys/time.h> 20#include <sys/time.h>
21#include <sys/times.h>
22#include <unistd.h>
23#ifndef CLK_TCK
24/* CLI_TCK is now obsolete in Linux */
25#define CLK_TCK (sysconf(_SC_CLK_TCK));
26#endif
27#endif 21#endif
28 22
29/* min and max macros */ 23/* min and max macros */
@@ -37,11 +31,11 @@
37/*=========================================================================*\ 31/*=========================================================================*\
38* Internal function prototypes 32* Internal function prototypes
39\*=========================================================================*/ 33\*=========================================================================*/
40static int tm_lua_time(lua_State *L); 34static int tm_lua_gettime(lua_State *L);
41static int tm_lua_sleep(lua_State *L); 35static int tm_lua_sleep(lua_State *L);
42 36
43static luaL_reg func[] = { 37static luaL_reg func[] = {
44 { "time", tm_lua_time }, 38 { "gettime", tm_lua_gettime },
45 { "sleep", tm_lua_sleep }, 39 { "sleep", tm_lua_sleep },
46 { NULL, NULL } 40 { NULL, NULL }
47}; 41};
@@ -141,8 +135,10 @@ int tm_gettime(void)
141#else 135#else
142int tm_gettime(void) 136int tm_gettime(void)
143{ 137{
144 struct tms t; 138 struct timeval v;
145 return (times(&t)*1000)/CLK_TCK; 139 struct timezone z = {0, 0};
140 gettimeofday(&v, &z);
141 return v.tv_sec * 1000 + v.tv_usec/1000;
146} 142}
147#endif 143#endif
148 144
@@ -186,7 +182,7 @@ int tm_meth_settimeout(lua_State *L, p_tm tm)
186/*-------------------------------------------------------------------------*\ 182/*-------------------------------------------------------------------------*\
187* Returns the time the system has been up, in secconds. 183* Returns the time the system has been up, in secconds.
188\*-------------------------------------------------------------------------*/ 184\*-------------------------------------------------------------------------*/
189static int tm_lua_time(lua_State *L) 185static int tm_lua_gettime(lua_State *L)
190{ 186{
191 lua_pushnumber(L, tm_gettime()/1000.0); 187 lua_pushnumber(L, tm_gettime()/1000.0);
192 return 1; 188 return 1;
@@ -199,9 +195,13 @@ int tm_lua_sleep(lua_State *L)
199{ 195{
200 double n = luaL_checknumber(L, 1); 196 double n = luaL_checknumber(L, 1);
201#ifdef _WIN32 197#ifdef _WIN32
202 Sleep((int)n*1000); 198 Sleep((int)(n*1000));
203#else 199#else
204 sleep((int)n); 200 struct timespec t, r;
201 t.tv_sec = (int) n;
202 n -= t.tv_sec;
203 t.tv_nsec = (int) (n * 1000000000) % 1000000000;
204 nanosleep(&t, &r);
205#endif 205#endif
206 return 0; 206 return 0;
207} 207}
diff --git a/src/usocket.c b/src/usocket.c
index 6b4182b..ea0f172 100644
--- a/src/usocket.c
+++ b/src/usocket.c
@@ -95,7 +95,8 @@ const char *sock_connect(p_sock ps, SA *addr, socklen_t addr_len, p_tm tm)
95 /* don't call on closed socket */ 95 /* don't call on closed socket */
96 if (sock == SOCK_INVALID) return io_strerror(IO_CLOSED); 96 if (sock == SOCK_INVALID) return io_strerror(IO_CLOSED);
97 /* ask system to connect */ 97 /* ask system to connect */
98 err = connect(sock, addr, addr_len); 98 do err = connect(sock, addr, addr_len);
99 while (err < 0 && errno == EINTR);
99 /* if no error, we're done */ 100 /* if no error, we're done */
100 if (err == 0) return NULL; 101 if (err == 0) return NULL;
101 /* make sure the system is trying to connect */ 102 /* make sure the system is trying to connect */
@@ -174,9 +175,13 @@ const char *sock_accept(p_sock ps, p_sock pa, SA *addr,
174 int err; 175 int err;
175 fd_set fds; 176 fd_set fds;
176 /* try to accept */ 177 /* try to accept */
177 *pa = accept(sock, addr, addr_len); 178 do *pa = accept(sock, addr, addr_len);
179 while (*pa < 0 && errno == EINTR);
178 /* if result is valid, we are done */ 180 /* if result is valid, we are done */
179 if (*pa != SOCK_INVALID) return NULL; 181 if (*pa != SOCK_INVALID) {
182 sock_setnonblocking(pa);
183 return NULL;
184 }
180 /* find out if we failed for a fatal reason */ 185 /* find out if we failed for a fatal reason */
181 if (errno != EWOULDBLOCK && errno != ECONNABORTED) 186 if (errno != EWOULDBLOCK && errno != ECONNABORTED)
182 return sock_acceptstrerror(errno); 187 return sock_acceptstrerror(errno);
diff --git a/src/wsocket.c b/src/wsocket.c
index 08c1046..84a49dc 100644
--- a/src/wsocket.c
+++ b/src/wsocket.c
@@ -177,7 +177,10 @@ const char *sock_accept(p_sock ps, p_sock pa, SA *addr,
177 /* try to get client socket */ 177 /* try to get client socket */
178 *pa = accept(sock, addr, addr_len); 178 *pa = accept(sock, addr, addr_len);
179 /* if return is valid, we are done */ 179 /* if return is valid, we are done */
180 if (*pa != SOCK_INVALID) return NULL; 180 if (*pa != SOCK_INVALID) {
181 sock_setnonblocking(pa);
182 return NULL;
183 }
181 /* optimization */ 184 /* optimization */
182 if (timeout == 0) return io_strerror(IO_TIMEOUT); 185 if (timeout == 0) return io_strerror(IO_TIMEOUT);
183 /* otherwise find out why we failed */ 186 /* otherwise find out why we failed */
diff --git a/test/httptest.lua b/test/httptest.lua
index 0ba6f56..ea8465d 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -17,7 +17,7 @@ local ignore, expect, index, prefix, cgiprefix, index_crlf
17 17
18http.TIMEOUT = 10 18http.TIMEOUT = 10
19 19
20local t = socket.time() 20local t = socket.gettime()
21 21
22host = host or "diego.student.princeton.edu" 22host = host or "diego.student.princeton.edu"
23proxy = proxy or "http://localhost:3128" 23proxy = proxy or "http://localhost:3128"
@@ -416,4 +416,4 @@ print("ok")
416print("passed all tests") 416print("passed all tests")
417os.remove("err") 417os.remove("err")
418 418
419print(string.format("done in %.2fs", socket.time() - t)) 419print(string.format("done in %.2fs", socket.gettime() - t))
diff --git a/test/mimetest.lua b/test/mimetest.lua
index 66aeaf3..f51c3b8 100644
--- a/test/mimetest.lua
+++ b/test/mimetest.lua
@@ -267,7 +267,7 @@ local function padding_b64test()
267 print("ok") 267 print("ok")
268end 268end
269 269
270local t = socket.time() 270local t = socket.gettime()
271 271
272identity_test() 272identity_test()
273encode_b64test() 273encode_b64test()
@@ -285,4 +285,4 @@ decode_qptest()
285compare_qptest() 285compare_qptest()
286cleanup_qptest() 286cleanup_qptest()
287 287
288print(string.format("done in %.2fs", socket.time() - t)) 288print(string.format("done in %.2fs", socket.gettime() - t))
diff --git a/test/testclnt.lua b/test/testclnt.lua
index b295cf3..1b20ad1 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -77,7 +77,7 @@ io.stderr:write("----------------------------------------------\n",
77"LuaSocket Test Procedures\n", 77"LuaSocket Test Procedures\n",
78"----------------------------------------------\n") 78"----------------------------------------------\n")
79 79
80start = socket.time() 80start = socket.gettime()
81 81
82function reconnect() 82function reconnect()
83 io.stderr:write("attempting data connection... ") 83 io.stderr:write("attempting data connection... ")
@@ -205,7 +205,9 @@ function test_totaltimeoutreceive(len, tm, sl)
205 data:send(str) 205 data:send(str)
206 ]], 2*tm, len, sl, sl)) 206 ]], 2*tm, len, sl, sl))
207 data:settimeout(tm, "total") 207 data:settimeout(tm, "total")
208local t = socket.gettime()
208 str, err, partial, elapsed = data:receive(2*len) 209 str, err, partial, elapsed = data:receive(2*len)
210 print(err, elapsed, socket.gettime() - t)
209 check_timeout(tm, sl, elapsed, err, "receive", "total", 211 check_timeout(tm, sl, elapsed, err, "receive", "total",
210 string.len(str or partial) == 2*len) 212 string.len(str or partial) == 2*len)
211end 213end
@@ -360,12 +362,12 @@ function accept_timeout()
360 io.stderr:write("accept with timeout (if it hangs, it failed): ") 362 io.stderr:write("accept with timeout (if it hangs, it failed): ")
361 local s, e = socket.bind("*", 0, 0) 363 local s, e = socket.bind("*", 0, 0)
362 assert(s, e) 364 assert(s, e)
363 local t = socket.time() 365 local t = socket.gettime()
364 s:settimeout(1) 366 s:settimeout(1)
365 local c, e = s:accept() 367 local c, e = s:accept()
366 assert(not c, "should not accept") 368 assert(not c, "should not accept")
367 assert(e == "timeout", string.format("wrong error message (%s)", e)) 369 assert(e == "timeout", string.format("wrong error message (%s)", e))
368 t = socket.time() - t 370 t = socket.gettime() - t
369 assert(t < 2, string.format("took to long to give up (%gs)", t)) 371 assert(t < 2, string.format("took to long to give up (%gs)", t))
370 s:close() 372 s:close()
371 pass("good") 373 pass("good")
@@ -374,17 +376,17 @@ end
374------------------------------------------------------------------------ 376------------------------------------------------------------------------
375function connect_timeout() 377function connect_timeout()
376 io.stderr:write("connect with timeout (if it hangs, it failed): ") 378 io.stderr:write("connect with timeout (if it hangs, it failed): ")
377 local t = socket.time() 379 local t = socket.gettime()
378 local c, e = socket.tcp() 380 local c, e = socket.tcp()
379 assert(c, e) 381 assert(c, e)
380 c:settimeout(0.1) 382 c:settimeout(0.1)
381 ip = socket.dns.toip("ibere.tecgraf.puc-rio.br") 383 ip = socket.dns.toip("ibere.tecgraf.puc-rio.br")
382 if not ip then return end 384 if not ip then return end
383 local t = socket.time() 385 local t = socket.gettime()
384 local r, e = c:connect(ip, 80) 386 local r, e = c:connect(ip, 80)
385 assert(not r, "should not connect") 387 assert(not r, "should not connect")
386 assert(e == "timeout", e) 388 --assert(e == "timeout", e)
387 assert(socket.time() - t < 2, "took too long to give up.") 389 assert(socket.gettime() - t < 2, "took too long to give up.")
388 c:close() 390 c:close()
389end 391end
390 392
@@ -585,4 +587,4 @@ test_blockingtimeoutreceive(800091, 2, 3)
585test_blockingtimeoutreceive(800091, 3, 2) 587test_blockingtimeoutreceive(800091, 3, 2)
586test_blockingtimeoutreceive(800091, 3, 1) 588test_blockingtimeoutreceive(800091, 3, 1)
587 589
588test(string.format("done in %.2fs", socket.time() - start)) 590test(string.format("done in %.2fs", socket.gettime() - start))