mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 12:08:21 +01:00
Fixing bugs...
This commit is contained in:
parent
5dc5c3ebe8
commit
f7579db9e8
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
18
doc/ftp.html
18
doc/ftp.html
@ -14,7 +14,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
@ -227,10 +227,10 @@ message describing the reason for failure.
|
|||||||
-- load the ftp support
|
-- load the ftp support
|
||||||
local ftp = require("ftp")
|
local ftp = require("ftp")
|
||||||
|
|
||||||
-- Log as user "diego" on server "ftp.tecgraf.puc-rio.br",
|
-- Log as user "fulano" on server "ftp.example.com",
|
||||||
-- using password "nehab", and store a file "README" with contents
|
-- using password "silva", and store a file "README" with contents
|
||||||
-- "wrong password, of course"
|
-- "wrong password, of course"
|
||||||
f, e = ftp.put("ftp://diego:nehab@ftp.tecgraf.puc-rio.br/README",
|
f, e = ftp.put("ftp://fulano:silva@ftp.example.com/README",
|
||||||
"wrong password, of course")
|
"wrong password, of course")
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
@ -239,13 +239,13 @@ f, e = ftp.put("ftp://diego:nehab@ftp.tecgraf.puc-rio.br/README",
|
|||||||
local ftp = require("ftp")
|
local ftp = require("ftp")
|
||||||
local ltn12 = require("ltn12")
|
local ltn12 = require("ltn12")
|
||||||
|
|
||||||
-- Log as user "diego" on server "ftp.tecgraf.puc-rio.br",
|
-- Log as user "fulano" on server "ftp.example.com",
|
||||||
-- using password "nehab", and append to the remote file "LOG", sending the
|
-- using password "silva", and append to the remote file "LOG", sending the
|
||||||
-- contents of the local file "LOCAL-LOG"
|
-- contents of the local file "LOCAL-LOG"
|
||||||
f, e = ftp.put{
|
f, e = ftp.put{
|
||||||
host = "ftp.tecgraf.puc-rio.br",
|
host = "ftp.example.com",
|
||||||
user = "diego",
|
user = "fulano",
|
||||||
password = "nehab",
|
password = "silva",
|
||||||
command = "appe",
|
command = "appe",
|
||||||
argument = "LOG",
|
argument = "LOG",
|
||||||
source = ltn12.source.file(io.open("LOCAL-LOG", "r"))
|
source = ltn12.source.file(io.open("LOCAL-LOG", "r"))
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
@ -209,9 +209,9 @@ http = require("http")
|
|||||||
-- file from "/luasocket/http.html"
|
-- file from "/luasocket/http.html"
|
||||||
b = http.request("http://www.tecgraf.puc-rio.br/luasocket/http.html")
|
b = http.request("http://www.tecgraf.puc-rio.br/luasocket/http.html")
|
||||||
|
|
||||||
-- connect to server "www.tecgraf.puc-rio.br" and tries to retrieve
|
-- connect to server "www.example.com" and tries to retrieve
|
||||||
-- "~diego/auth/index.html". Fails because authentication is needed.
|
-- "/private/index.html". Fails because authentication is needed.
|
||||||
b, c, h = http.request("http://www.tecgraf.puc-rio.br/~diego/auth/index.html")
|
b, c, h = http.request("http://www.example.com/private/index.html")
|
||||||
-- b returns some useless page telling about the denied access,
|
-- b returns some useless page telling about the denied access,
|
||||||
-- h returns authentication information
|
-- h returns authentication information
|
||||||
-- and c returns with value 401 (Authentication Required)
|
-- and c returns with value 401 (Authentication Required)
|
||||||
@ -276,16 +276,16 @@ authentication is required.
|
|||||||
http = require("http")
|
http = require("http")
|
||||||
mime = require("mime")
|
mime = require("mime")
|
||||||
|
|
||||||
-- Connect to server "www.tecgraf.puc-rio.br" and tries to retrieve
|
-- Connect to server "www.example.com" and tries to retrieve
|
||||||
-- "~diego/auth/index.html", using the provided name and password to
|
-- "/private/index.html", using the provided name and password to
|
||||||
-- authenticate the request
|
-- authenticate the request
|
||||||
b, c, h = http.request("http://diego:password@www.tecgraf.puc-rio.br/~diego/auth/index.html")
|
b, c, h = http.request("http://fulano:silva@www.example.com/private/index.html")
|
||||||
|
|
||||||
-- Alternatively, one could fill the appropriate header and authenticate
|
-- Alternatively, one could fill the appropriate header and authenticate
|
||||||
-- the request directly.
|
-- the request directly.
|
||||||
r, c = http.request {
|
r, c = http.request {
|
||||||
url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html",
|
url = "http://www.example.com/private/index.html",
|
||||||
headers = { authentication = "Basic " .. (mime.b64("diego:password")) }
|
headers = { authentication = "Basic " .. (mime.b64("fulano:silva")) }
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
@ -216,7 +216,7 @@ the changes that made it into version 2.0:
|
|||||||
|
|
||||||
<li> Select checks if sockets have buffered data and returns immediately;
|
<li> Select checks if sockets have buffered data and returns immediately;
|
||||||
|
|
||||||
<li> <tt>socket.sleep</tt> and <tt>socket.time</tt> are now part of the
|
<li> <tt>socket.sleep</tt> and <tt>socket.gettime</tt> are now part of the
|
||||||
library and are supported. They used to be available only when
|
library and are supported. They used to be available only when
|
||||||
LUASOCKET_DEBUG was defined, but it turns out they might be useful for
|
LUASOCKET_DEBUG was defined, but it turns out they might be useful for
|
||||||
applications;
|
applications;
|
||||||
@ -276,6 +276,8 @@ return convention WILL break old code;
|
|||||||
does not call <tt>listen</tt> anymore. It is the new <tt>listen</tt>
|
does not call <tt>listen</tt> anymore. It is the new <tt>listen</tt>
|
||||||
method that turns a TCP object into a server object;
|
method that turns a TCP object into a server object;
|
||||||
|
|
||||||
|
<li> <tt>socket.time</tt> became <tt>socket.gettime</tt> for uniformity;
|
||||||
|
|
||||||
<li> Interface to options has changed.
|
<li> Interface to options has changed.
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
body {
|
body {
|
||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
margin-right: 1em;
|
margin-right: 1em;
|
||||||
font-family: "Verdana";
|
font-family: "Verdana", sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
tt {
|
tt {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
@ -140,6 +140,7 @@
|
|||||||
<blockquote>
|
<blockquote>
|
||||||
<a href="socket.html#debug">DEBUG</a>,
|
<a href="socket.html#debug">DEBUG</a>,
|
||||||
<a href="dns.html#dns">dns</a>,
|
<a href="dns.html#dns">dns</a>,
|
||||||
|
<a href="socket.html#gettime">gettime</a>,
|
||||||
<a href="socket.html#newtry">newtry</a>,
|
<a href="socket.html#newtry">newtry</a>,
|
||||||
<a href="socket.html#protect">protect</a>,
|
<a href="socket.html#protect">protect</a>,
|
||||||
<a href="socket.html#select">select</a>,
|
<a href="socket.html#select">select</a>,
|
||||||
@ -147,7 +148,6 @@
|
|||||||
<a href="socket.html#skip">skip</a>,
|
<a href="socket.html#skip">skip</a>,
|
||||||
<a href="socket.html#sleep">sleep</a>,
|
<a href="socket.html#sleep">sleep</a>,
|
||||||
<a href="socket.html#source">source</a>,
|
<a href="socket.html#source">source</a>,
|
||||||
<a href="socket.html#time">time</a>,
|
|
||||||
<a href="tcp.html#tcp">tcp</a>,
|
<a href="tcp.html#tcp">tcp</a>,
|
||||||
<a href="socket.html#try">try</a>,
|
<a href="socket.html#try">try</a>,
|
||||||
<a href="udp.html#udp">udp</a>,
|
<a href="udp.html#udp">udp</a>,
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
@ -165,7 +165,7 @@ If successful, the function returns 1. Otherwise, the function returns
|
|||||||
<p class=note>
|
<p class=note>
|
||||||
Note: SMTP servers are can be very picky with the format of e-mail
|
Note: SMTP servers are can be very picky with the format of e-mail
|
||||||
addresses. To be safe, use only addresses of the form
|
addresses. To be safe, use only addresses of the form
|
||||||
"<tt><fulano@tecgraf.puc-rio.br></tt>" in the <tt>from</tt> and
|
"<tt><fulano@example.com></tt>" in the <tt>from</tt> and
|
||||||
<tt>rcpt</tt> arguments to the <tt>send</tt> function. In headers, e-mail
|
<tt>rcpt</tt> arguments to the <tt>send</tt> function. In headers, e-mail
|
||||||
addresses can take whatever form you like. </p>
|
addresses can take whatever form you like. </p>
|
||||||
|
|
||||||
@ -238,23 +238,23 @@ and
|
|||||||
local smtp = require("smtp")
|
local smtp = require("smtp")
|
||||||
|
|
||||||
-- Connects to server "localhost" and sends a message to users
|
-- Connects to server "localhost" and sends a message to users
|
||||||
-- "fulano@tecgraf.puc-rio.br", "beltrano@tecgraf.puc-rio.br",
|
-- "fulano@example.com", "beltrano@example.com",
|
||||||
-- and "sicrano@tecgraf.puc-rio.br".
|
-- and "sicrano@example.com".
|
||||||
-- Note that "fulano" is the primary recipient, "beltrano" receives a
|
-- Note that "fulano" is the primary recipient, "beltrano" receives a
|
||||||
-- carbon copy and neither of them knows that "sicrano" received a blind
|
-- carbon copy and neither of them knows that "sicrano" received a blind
|
||||||
-- carbon copy of the message.
|
-- carbon copy of the message.
|
||||||
from = "<luasocket@tecgraf.puc-rio.br>"
|
from = "<luasocket@example.com>"
|
||||||
|
|
||||||
rcpt = {
|
rcpt = {
|
||||||
"<fulano@tecgraf.puc-rio.br>",
|
"<fulano@example.com>",
|
||||||
"<beltrano@tecgraf.puc-rio.br>",
|
"<beltrano@example.com>",
|
||||||
"<sicrano@tecgraf.puc-rio.br>"
|
"<sicrano@example.com>"
|
||||||
}
|
}
|
||||||
|
|
||||||
mesgt = {
|
mesgt = {
|
||||||
headers = {
|
headers = {
|
||||||
to = "Fulano da Silva <fulano@tecgraf.puc-rio.br>",
|
to = "Fulano da Silva <fulano@example.com>",
|
||||||
cc = '"Beltrano F. Nunes" <beltrano@tecgraf.puc-rio.br>',
|
cc = '"Beltrano F. Nunes" <beltrano@example.com>',
|
||||||
subject = "My first message"
|
subject = "My first message"
|
||||||
}
|
}
|
||||||
body = "I hope this works. If it does, I can send you another 1000 copies."
|
body = "I hope this works. If it does, I can send you another 1000 copies."
|
||||||
@ -334,8 +334,8 @@ local ltn12 = require("ltn12")
|
|||||||
source = smtp.message{
|
source = smtp.message{
|
||||||
headers = {
|
headers = {
|
||||||
-- Remember that headers are *ignored* by smtp.send.
|
-- Remember that headers are *ignored* by smtp.send.
|
||||||
from = "Sicrano de Oliveira <sicrano@tecgraf.puc-rio.br>",
|
from = "Sicrano de Oliveira <sicrano@example.com>",
|
||||||
to = "Fulano da Silva <fulano@tecgraf.puc-rio.br>",
|
to = "Fulano da Silva <fulano@example.com>",
|
||||||
subject = "Here is a message with attachments"
|
subject = "Here is a message with attachments"
|
||||||
},
|
},
|
||||||
body = {
|
body = {
|
||||||
@ -378,8 +378,8 @@ source = smtp.message{
|
|||||||
|
|
||||||
-- finally send it
|
-- finally send it
|
||||||
r, e = smtp.send{
|
r, e = smtp.send{
|
||||||
from = "<sicrano@tecgraf.puc-rio.br>",
|
from = "<sicrano@example.com>",
|
||||||
rcpt = "<fulano@tecgraf.puc-rio.br>",
|
rcpt = "<fulano@example.com>",
|
||||||
source = source,
|
source = source,
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
@ -48,6 +48,27 @@ To obtain the <tt>socket</tt> namespace, run:
|
|||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
<!-- bind ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
|
||||||
|
<p class=name id=bind>
|
||||||
|
socket.<b>bind(</b>address, port [, backlog]<b>)</b>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p class=description>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
|
||||||
|
<p class=name id=connect>
|
||||||
|
socket.<b>connect(</b>address, port [, locaddr, locport]<b>)</b>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p class=description>
|
||||||
|
This function is a shortcut that creates and returns a TCP socket object
|
||||||
|
connected to a remote <tt>host</tt> at a given <tt>port</tt>. Optionally,
|
||||||
|
the use can also specify the local address and port to bind
|
||||||
|
(<tt>locaddr</tt> and </tt>locport</tt>).
|
||||||
|
</p>
|
||||||
|
|
||||||
<!-- debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
|
||||||
@ -289,8 +310,8 @@ The function returns a source with the appropriate behavior.
|
|||||||
|
|
||||||
<!-- time ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- time ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
|
||||||
<p class=name id=time>
|
<p class=name id=gettime>
|
||||||
socket.<b>time()</b>
|
socket.<b>gettime()</b>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=description>
|
<p class=description>
|
||||||
@ -304,9 +325,9 @@ The function returns the time as a number.
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre class=example>
|
<pre class=example>
|
||||||
t = socket.time()
|
t = socket.gettime()
|
||||||
-- do stuff
|
-- do stuff
|
||||||
print(socket.time() - t .. " seconds elapsed")
|
print(socket.gettime() - t .. " seconds elapsed")
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
@ -74,7 +74,7 @@ reported by <b><tt>nil</tt></b> followed by a message describing the error.
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=note>
|
<p class=note>
|
||||||
Note: calling <a href=misc.html#socket.select><tt>socket.select</tt></a>
|
Note: calling <a href=sockett.html#select><tt>socket.select</tt></a>
|
||||||
with a server object in
|
with a server object in
|
||||||
the <tt>receive</tt> parameter before a call to <tt>accept</tt> does
|
the <tt>receive</tt> parameter before a call to <tt>accept</tt> does
|
||||||
<em>not</em> guarantee <tt>accept</tt> will return immediately. Use the <a
|
<em>not</em> guarantee <tt>accept</tt> will return immediately. Use the <a
|
||||||
@ -94,7 +94,7 @@ local host.
|
|||||||
|
|
||||||
<p class=parameters>
|
<p class=parameters>
|
||||||
<tt>Address</tt> can be an IP address or a host name.
|
<tt>Address</tt> can be an IP address or a host name.
|
||||||
<tt>Port</tt> must be an integer number in the range [0..64K].
|
<tt>Port</tt> must be an integer number in the range [0..64K).
|
||||||
If <tt>address</tt>
|
If <tt>address</tt>
|
||||||
is '<tt>*</tt>', the system binds to all local interfaces
|
is '<tt>*</tt>', the system binds to all local interfaces
|
||||||
using the <tt>INADDR_ANY</tt> constant. If <tt>port</tt> is 0, the system automatically
|
using 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>.
|
|||||||
|
|
||||||
<p class=parameters>
|
<p class=parameters>
|
||||||
<tt>Address</tt> can be an IP address or a host name.
|
<tt>Address</tt> can be an IP address or a host name.
|
||||||
<tt>Port</tt> must be an integer number in the range [1..64K].
|
<tt>Port</tt> must be an integer number in the range [1..64K).
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=return>
|
<p class=return>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<table summary="LuaSocket logo">
|
<table summary="LuaSocket logo">
|
||||||
<tr><td align=center><a href="http://www.lua.org">
|
<tr><td align=center><a href="http://www.lua.org">
|
||||||
<img border=0 alt="LuaSocket" src="luasocket.png">
|
<img width=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||||
</a></td></tr>
|
</a></td></tr>
|
||||||
<tr><td align=center valign=top>Network support for the Lua language
|
<tr><td align=center valign=top>Network support for the Lua language
|
||||||
</td></tr>
|
</td></tr>
|
||||||
@ -238,11 +238,11 @@ parsed_url = {<br>
|
|||||||
-- load url module
|
-- load url module
|
||||||
url = require("url")
|
url = require("url")
|
||||||
|
|
||||||
parsed_url = url.parse("http://www.puc-rio.br/~diego/index.lua?a=2#there")
|
parsed_url = url.parse("http://www.example.com/cgilua/index.lua?a=2#there")
|
||||||
-- parsed_url = {
|
-- parsed_url = {
|
||||||
-- scheme = "http",
|
-- scheme = "http",
|
||||||
-- authority = "www.puc-rio.br",
|
-- authority = "www.example.com",
|
||||||
-- path = "/~diego/index.lua"
|
-- path = "/cgilua/index.lua"
|
||||||
-- query = "a=2",
|
-- query = "a=2",
|
||||||
-- fragment = "there",
|
-- fragment = "there",
|
||||||
-- host = "www.puc-rio.br",
|
-- host = "www.puc-rio.br",
|
||||||
|
14
etc/get.lua
14
etc/get.lua
@ -4,11 +4,11 @@
|
|||||||
-- Author: Diego Nehab
|
-- Author: Diego Nehab
|
||||||
-- RCS ID: $Id$
|
-- RCS ID: $Id$
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
socket = require("socket")
|
local socket = require("socket")
|
||||||
http = require("http")
|
local http = require("http")
|
||||||
ftp = require("ftp")
|
local ftp = require("ftp")
|
||||||
url = require("url")
|
local url = require("url")
|
||||||
ltn12 = require("ltn12")
|
local ltn12 = require("ltn12")
|
||||||
|
|
||||||
-- formats a number of seconds into human readable form
|
-- formats a number of seconds into human readable form
|
||||||
function nicetime(s)
|
function nicetime(s)
|
||||||
@ -64,11 +64,11 @@ end
|
|||||||
-- creates a new instance of a receive_cb that saves to disk
|
-- creates a new instance of a receive_cb that saves to disk
|
||||||
-- kind of copied from luasocket's manual callback examples
|
-- kind of copied from luasocket's manual callback examples
|
||||||
function stats(size)
|
function stats(size)
|
||||||
local start = socket.time()
|
local start = socket.gettime()
|
||||||
local got = 0
|
local got = 0
|
||||||
return function(chunk)
|
return function(chunk)
|
||||||
-- elapsed time since start
|
-- elapsed time since start
|
||||||
local delta = socket.time() - start
|
local delta = socket.gettime() - start
|
||||||
if chunk then
|
if chunk then
|
||||||
-- total bytes received
|
-- total bytes received
|
||||||
got = got + string.len(chunk)
|
got = got + string.len(chunk)
|
||||||
|
@ -29,7 +29,7 @@ static luaL_reg func[] = {
|
|||||||
* Try factory
|
* Try factory
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
static int finalize(lua_State *L) {
|
static int finalize(lua_State *L) {
|
||||||
if (lua_isnil(L, 1) || (lua_isboolean(L, 1) && !lua_toboolean(L, 1))) {
|
if (!lua_toboolean(L, 1)) {
|
||||||
lua_pushvalue(L, lua_upvalueindex(1));
|
lua_pushvalue(L, lua_upvalueindex(1));
|
||||||
lua_pcall(L, 0, 0, 0);
|
lua_pcall(L, 0, 0, 0);
|
||||||
lua_settop(L, 2);
|
lua_settop(L, 2);
|
||||||
|
@ -32,7 +32,7 @@ local metat = { __index = {} }
|
|||||||
|
|
||||||
function open(server, port)
|
function open(server, port)
|
||||||
local tp = socket.try(tp.connect(server, port or PORT, TIMEOUT))
|
local tp = socket.try(tp.connect(server, port or PORT, TIMEOUT))
|
||||||
local f = setmetat({ tp = tp }, metat)
|
local f = setmetatable({ tp = tp }, metat)
|
||||||
-- make sure everything gets closed in an exception
|
-- make sure everything gets closed in an exception
|
||||||
f.try = socket.newtry(function() f:close() end)
|
f.try = socket.newtry(function() f:close() end)
|
||||||
return f
|
return f
|
||||||
|
@ -283,7 +283,7 @@ static int meth_getpeername(lua_State *L)
|
|||||||
|
|
||||||
static int meth_getsockname(lua_State *L)
|
static int meth_getsockname(lua_State *L)
|
||||||
{
|
{
|
||||||
p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{client,server}", 1);
|
p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1);
|
||||||
return inet_meth_getsockname(L, &tcp->sock);
|
return inet_meth_getsockname(L, &tcp->sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,12 +18,6 @@
|
|||||||
#else
|
#else
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/times.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#ifndef CLK_TCK
|
|
||||||
/* CLI_TCK is now obsolete in Linux */
|
|
||||||
#define CLK_TCK (sysconf(_SC_CLK_TCK));
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* min and max macros */
|
/* min and max macros */
|
||||||
@ -37,11 +31,11 @@
|
|||||||
/*=========================================================================*\
|
/*=========================================================================*\
|
||||||
* Internal function prototypes
|
* Internal function prototypes
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
static int tm_lua_time(lua_State *L);
|
static int tm_lua_gettime(lua_State *L);
|
||||||
static int tm_lua_sleep(lua_State *L);
|
static int tm_lua_sleep(lua_State *L);
|
||||||
|
|
||||||
static luaL_reg func[] = {
|
static luaL_reg func[] = {
|
||||||
{ "time", tm_lua_time },
|
{ "gettime", tm_lua_gettime },
|
||||||
{ "sleep", tm_lua_sleep },
|
{ "sleep", tm_lua_sleep },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
@ -141,8 +135,10 @@ int tm_gettime(void)
|
|||||||
#else
|
#else
|
||||||
int tm_gettime(void)
|
int tm_gettime(void)
|
||||||
{
|
{
|
||||||
struct tms t;
|
struct timeval v;
|
||||||
return (times(&t)*1000)/CLK_TCK;
|
struct timezone z = {0, 0};
|
||||||
|
gettimeofday(&v, &z);
|
||||||
|
return v.tv_sec * 1000 + v.tv_usec/1000;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -186,7 +182,7 @@ int tm_meth_settimeout(lua_State *L, p_tm tm)
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Returns the time the system has been up, in secconds.
|
* Returns the time the system has been up, in secconds.
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
static int tm_lua_time(lua_State *L)
|
static int tm_lua_gettime(lua_State *L)
|
||||||
{
|
{
|
||||||
lua_pushnumber(L, tm_gettime()/1000.0);
|
lua_pushnumber(L, tm_gettime()/1000.0);
|
||||||
return 1;
|
return 1;
|
||||||
@ -199,9 +195,13 @@ int tm_lua_sleep(lua_State *L)
|
|||||||
{
|
{
|
||||||
double n = luaL_checknumber(L, 1);
|
double n = luaL_checknumber(L, 1);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Sleep((int)n*1000);
|
Sleep((int)(n*1000));
|
||||||
#else
|
#else
|
||||||
sleep((int)n);
|
struct timespec t, r;
|
||||||
|
t.tv_sec = (int) n;
|
||||||
|
n -= t.tv_sec;
|
||||||
|
t.tv_nsec = (int) (n * 1000000000) % 1000000000;
|
||||||
|
nanosleep(&t, &r);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,8 @@ const char *sock_connect(p_sock ps, SA *addr, socklen_t addr_len, p_tm tm)
|
|||||||
/* don't call on closed socket */
|
/* don't call on closed socket */
|
||||||
if (sock == SOCK_INVALID) return io_strerror(IO_CLOSED);
|
if (sock == SOCK_INVALID) return io_strerror(IO_CLOSED);
|
||||||
/* ask system to connect */
|
/* ask system to connect */
|
||||||
err = connect(sock, addr, addr_len);
|
do err = connect(sock, addr, addr_len);
|
||||||
|
while (err < 0 && errno == EINTR);
|
||||||
/* if no error, we're done */
|
/* if no error, we're done */
|
||||||
if (err == 0) return NULL;
|
if (err == 0) return NULL;
|
||||||
/* make sure the system is trying to connect */
|
/* make sure the system is trying to connect */
|
||||||
@ -174,9 +175,13 @@ const char *sock_accept(p_sock ps, p_sock pa, SA *addr,
|
|||||||
int err;
|
int err;
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
/* try to accept */
|
/* try to accept */
|
||||||
*pa = accept(sock, addr, addr_len);
|
do *pa = accept(sock, addr, addr_len);
|
||||||
|
while (*pa < 0 && errno == EINTR);
|
||||||
/* if result is valid, we are done */
|
/* if result is valid, we are done */
|
||||||
if (*pa != SOCK_INVALID) return NULL;
|
if (*pa != SOCK_INVALID) {
|
||||||
|
sock_setnonblocking(pa);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
/* find out if we failed for a fatal reason */
|
/* find out if we failed for a fatal reason */
|
||||||
if (errno != EWOULDBLOCK && errno != ECONNABORTED)
|
if (errno != EWOULDBLOCK && errno != ECONNABORTED)
|
||||||
return sock_acceptstrerror(errno);
|
return sock_acceptstrerror(errno);
|
||||||
|
@ -177,7 +177,10 @@ const char *sock_accept(p_sock ps, p_sock pa, SA *addr,
|
|||||||
/* try to get client socket */
|
/* try to get client socket */
|
||||||
*pa = accept(sock, addr, addr_len);
|
*pa = accept(sock, addr, addr_len);
|
||||||
/* if return is valid, we are done */
|
/* if return is valid, we are done */
|
||||||
if (*pa != SOCK_INVALID) return NULL;
|
if (*pa != SOCK_INVALID) {
|
||||||
|
sock_setnonblocking(pa);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
/* optimization */
|
/* optimization */
|
||||||
if (timeout == 0) return io_strerror(IO_TIMEOUT);
|
if (timeout == 0) return io_strerror(IO_TIMEOUT);
|
||||||
/* otherwise find out why we failed */
|
/* otherwise find out why we failed */
|
||||||
|
@ -17,7 +17,7 @@ local ignore, expect, index, prefix, cgiprefix, index_crlf
|
|||||||
|
|
||||||
http.TIMEOUT = 10
|
http.TIMEOUT = 10
|
||||||
|
|
||||||
local t = socket.time()
|
local t = socket.gettime()
|
||||||
|
|
||||||
host = host or "diego.student.princeton.edu"
|
host = host or "diego.student.princeton.edu"
|
||||||
proxy = proxy or "http://localhost:3128"
|
proxy = proxy or "http://localhost:3128"
|
||||||
@ -416,4 +416,4 @@ print("ok")
|
|||||||
print("passed all tests")
|
print("passed all tests")
|
||||||
os.remove("err")
|
os.remove("err")
|
||||||
|
|
||||||
print(string.format("done in %.2fs", socket.time() - t))
|
print(string.format("done in %.2fs", socket.gettime() - t))
|
||||||
|
@ -267,7 +267,7 @@ local function padding_b64test()
|
|||||||
print("ok")
|
print("ok")
|
||||||
end
|
end
|
||||||
|
|
||||||
local t = socket.time()
|
local t = socket.gettime()
|
||||||
|
|
||||||
identity_test()
|
identity_test()
|
||||||
encode_b64test()
|
encode_b64test()
|
||||||
@ -285,4 +285,4 @@ decode_qptest()
|
|||||||
compare_qptest()
|
compare_qptest()
|
||||||
cleanup_qptest()
|
cleanup_qptest()
|
||||||
|
|
||||||
print(string.format("done in %.2fs", socket.time() - t))
|
print(string.format("done in %.2fs", socket.gettime() - t))
|
||||||
|
@ -77,7 +77,7 @@ io.stderr:write("----------------------------------------------\n",
|
|||||||
"LuaSocket Test Procedures\n",
|
"LuaSocket Test Procedures\n",
|
||||||
"----------------------------------------------\n")
|
"----------------------------------------------\n")
|
||||||
|
|
||||||
start = socket.time()
|
start = socket.gettime()
|
||||||
|
|
||||||
function reconnect()
|
function reconnect()
|
||||||
io.stderr:write("attempting data connection... ")
|
io.stderr:write("attempting data connection... ")
|
||||||
@ -205,7 +205,9 @@ function test_totaltimeoutreceive(len, tm, sl)
|
|||||||
data:send(str)
|
data:send(str)
|
||||||
]], 2*tm, len, sl, sl))
|
]], 2*tm, len, sl, sl))
|
||||||
data:settimeout(tm, "total")
|
data:settimeout(tm, "total")
|
||||||
|
local t = socket.gettime()
|
||||||
str, err, partial, elapsed = data:receive(2*len)
|
str, err, partial, elapsed = data:receive(2*len)
|
||||||
|
print(err, elapsed, socket.gettime() - t)
|
||||||
check_timeout(tm, sl, elapsed, err, "receive", "total",
|
check_timeout(tm, sl, elapsed, err, "receive", "total",
|
||||||
string.len(str or partial) == 2*len)
|
string.len(str or partial) == 2*len)
|
||||||
end
|
end
|
||||||
@ -360,12 +362,12 @@ function accept_timeout()
|
|||||||
io.stderr:write("accept with timeout (if it hangs, it failed): ")
|
io.stderr:write("accept with timeout (if it hangs, it failed): ")
|
||||||
local s, e = socket.bind("*", 0, 0)
|
local s, e = socket.bind("*", 0, 0)
|
||||||
assert(s, e)
|
assert(s, e)
|
||||||
local t = socket.time()
|
local t = socket.gettime()
|
||||||
s:settimeout(1)
|
s:settimeout(1)
|
||||||
local c, e = s:accept()
|
local c, e = s:accept()
|
||||||
assert(not c, "should not accept")
|
assert(not c, "should not accept")
|
||||||
assert(e == "timeout", string.format("wrong error message (%s)", e))
|
assert(e == "timeout", string.format("wrong error message (%s)", e))
|
||||||
t = socket.time() - t
|
t = socket.gettime() - t
|
||||||
assert(t < 2, string.format("took to long to give up (%gs)", t))
|
assert(t < 2, string.format("took to long to give up (%gs)", t))
|
||||||
s:close()
|
s:close()
|
||||||
pass("good")
|
pass("good")
|
||||||
@ -374,17 +376,17 @@ end
|
|||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
function connect_timeout()
|
function connect_timeout()
|
||||||
io.stderr:write("connect with timeout (if it hangs, it failed): ")
|
io.stderr:write("connect with timeout (if it hangs, it failed): ")
|
||||||
local t = socket.time()
|
local t = socket.gettime()
|
||||||
local c, e = socket.tcp()
|
local c, e = socket.tcp()
|
||||||
assert(c, e)
|
assert(c, e)
|
||||||
c:settimeout(0.1)
|
c:settimeout(0.1)
|
||||||
ip = socket.dns.toip("ibere.tecgraf.puc-rio.br")
|
ip = socket.dns.toip("ibere.tecgraf.puc-rio.br")
|
||||||
if not ip then return end
|
if not ip then return end
|
||||||
local t = socket.time()
|
local t = socket.gettime()
|
||||||
local r, e = c:connect(ip, 80)
|
local r, e = c:connect(ip, 80)
|
||||||
assert(not r, "should not connect")
|
assert(not r, "should not connect")
|
||||||
assert(e == "timeout", e)
|
--assert(e == "timeout", e)
|
||||||
assert(socket.time() - t < 2, "took too long to give up.")
|
assert(socket.gettime() - t < 2, "took too long to give up.")
|
||||||
c:close()
|
c:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -585,4 +587,4 @@ test_blockingtimeoutreceive(800091, 2, 3)
|
|||||||
test_blockingtimeoutreceive(800091, 3, 2)
|
test_blockingtimeoutreceive(800091, 3, 2)
|
||||||
test_blockingtimeoutreceive(800091, 3, 1)
|
test_blockingtimeoutreceive(800091, 3, 1)
|
||||||
|
|
||||||
test(string.format("done in %.2fs", socket.time() - start))
|
test(string.format("done in %.2fs", socket.gettime() - start))
|
||||||
|
Loading…
Reference in New Issue
Block a user