Bug in poll.

Debug garbage in compat-5.1.c.
Improvements to the user manual.
This commit is contained in:
Diego Nehab 2004-11-29 06:55:47 +00:00
parent 6abfbc742b
commit 4e5ad6d5ee
4 changed files with 54 additions and 46 deletions

View File

@ -47,22 +47,20 @@ functionality commonly needed by applications that deal with the Internet.
<p> <p>
The core support has been implemented so that it is both efficient and The core support has been implemented so that it is both efficient and
simple to use. The core can be used by any Lua application once it has simple to use. It is available to any Lua application once it has been
been properly initialized by the interpreter running the properly initialized by the interpreter in use. The code has been tested
Lua application. The code has been tested and runs well on several Windows and runs well on several Windows and Unix platforms. </p>
and Unix platforms.
</p>
<p> <p>
The most used modules implement the Among the support modules, the most commonly used implement the
<a href=smtp.html>SMTP</a> <a href=smtp.html>SMTP</a>
(sending e-mails), (sending e-mails),
<a href=http.html>HTTP</a> <a href=http.html>HTTP</a>
(WWW access) and (WWW access) and
<a href=ftp.html>FTP</a> <a href=ftp.html>FTP</a>
(uploading and downloading files) client (uploading and downloading files) client
protocols. These provide a very natural and generic interface to the e protocols. These provide a very natural and generic interface to the
functionality covered by the protocols. functionality defined by each protocol.
In addition, you will find that the In addition, you will find that the
<a href=mime.html>MIME</a> (common encodings), <a href=mime.html>MIME</a> (common encodings),
<a href=url.html>URL</a> <a href=url.html>URL</a>
@ -107,12 +105,12 @@ The library can be downloaded in source code from the following links:
<p> <p>
Besides the full C and Lua source code for the library, the distribution Besides the full C and Lua source code for the library, the distribution
contains several examples, this user's manual and the test procedures. contains several examples, this user's manual and basic test procedures.
</p> </p>
<p> <p>
I am also providing PC Win32 binaries for those that want to give I am also providing PC Win32 binaries for those that want to give
LuaSocket a quick try: LuaSocket a try (Those on Unix or Mac OS X can just type <tt>make</tt>):
</p> </p>
<blockquote> <blockquote>
@ -126,12 +124,12 @@ The quick and dirty way to use these binaries is to unpack everything into a
directory, say <tt>c:\luasocket</tt> (include all Lua files from the directory, say <tt>c:\luasocket</tt> (include all Lua files from the
LuaSocket distrbitution in the same directory too!). LuaSocket distrbitution in the same directory too!).
Then set <tt>LUA_INIT</tt> to load the <tt>compat-5.1.lua</tt> and set Then set <tt>LUA_INIT</tt> to load the <tt>compat-5.1.lua</tt> and set
<tt>LUA_PATH</tt> and <tt>LUA_CPATH</tt> to look for files in that <tt>LUA_PATH</tt> and <tt>LUA_CPATH</tt> to look for files in the current
directory: directory:
</p> </p>
<pre class=example> <pre class=example>
c:\luasocket\&gt; set LUA_INIT=@compat-5.1.lua c:\luasocket\&gt; set LUA_INIT=@c:\luasocket\compat-5.1.lua
c:\luasocket\&gt; set LUA_CPATH=?.dll c:\luasocket\&gt; set LUA_CPATH=?.dll
c:\luasocket\&gt; set LUA_PATH=?.lua c:\luasocket\&gt; set LUA_PATH=?.lua
</pre> </pre>
@ -147,12 +145,12 @@ c:\luasocket\&gt; lua
Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
&gt; http = require"http" &gt; http = require"http"
&gt; print(http.request"http://www.tecgraf.puc-rio.br/luasocket/") &gt; print(http.request"http://www.tecgraf.puc-rio.br/luasocket/")
--&gt; this gets dumped to terminal --&gt; the source to this webpage gets dumped to terminal
</pre> </pre>
<p> Take a look at the <a href=instalation.html>installation</a> section of <p> When you are done playing, take a look at the
the manual to find out how to properly install the library after you are <a href=instalation.html>installation</a> section of the manual to find out
done playing with it. </p> how to properly install the library. </p>
<!-- thanks +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- thanks +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@ -175,7 +173,7 @@ has been helping a lot too! Thanks to you all!
<p> <p>
The big change for the 2.0 (beta3) release was the adoption of the Lua 5.1 The big change for the 2.0 (beta3) release was the adoption of the Lua 5.1
package proposal. There were several bug fixes too (a beta is a package proposal. Naturally, there were a few bug fixes (a beta is a
beta, is a beta). beta, is a beta).
</p> </p>
@ -195,7 +193,7 @@ beta, is a beta).
<li> Fixed <tt>udp:sendto</tt> to call <tt>sock_sendto</tt> instead of <li> Fixed <tt>udp:sendto</tt> to call <tt>sock_sendto</tt> instead of
<tt>sock_send</tt>; <tt>sock_send</tt>;
<li> <tt>close</tt> wasn't returning 1! <li> <tt>close</tt> wasn't returning 1!
<li> <tt>socket.gettime</tt> returns time since Unix Epoch 1/1/1970 (UTC) <li> <tt>socket.gettime</tt> returns time since Unix Epoch 1/1/1970 (UTC);
<li> <tt>socket.sleep</tt> is robust to interrupts; <li> <tt>socket.sleep</tt> is robust to interrupts;
<li> <tt>socket.select</tt> wasn't calling <tt>tm_markstart</tt>; <li> <tt>socket.select</tt> wasn't calling <tt>tm_markstart</tt>;
<li> <tt>http.PROXY</tt> wasn't working. <li> <tt>http.PROXY</tt> wasn't working.
@ -206,8 +204,8 @@ beta, is a beta).
<h3 id=incompatible>Incompatibilities with previous versions</h3> <h3 id=incompatible>Incompatibilities with previous versions</h3>
<ul> <ul>
<li> Namespaces are hierarchical again. This means that whoever called <li> Namespaces are hierarchical again. This means that whoever used to
<tt>require("url")</tt> should update their code to call <tt>require("url")</tt> should update their code to
<tt>require("socket.url")</tt>. <tt>require("socket.url")</tt>.
</ul> </ul>

View File

@ -39,24 +39,32 @@ Installation">
<h2>Instalation</h2> <h2>Instalation</h2>
<p> LuaSocket 2.0 uses the new package proposal for Lua 5.1, throught the <p> LuaSocket 2.0 uses the new package proposal for Lua 5.1.
compatibility module <a href=http://www.keplerproject.org/compat/> All Lua library developers are encouraged to update their libraries so that
Compat-5.1</a> released in conjunction with Roberto Ierusalimschy and <a all libraries can coexist peacefully and users can benefit from the
href=http://www.keplerproject.org/">The Kepler project</a>. The proposal standardization and flexibility of the standard.
was considered important enough by the community to justify early adoption. </p>
All Lua library developers are encouraged to change their libraries in
preparation for the release of Lua 5.1. </p> <p>
The proposal was considered important enough by some of us to justify
early adoption, even before release of Lua 5.1.
Thus, a compability module
<a href=http://www.keplerproject.org/compat/>compat-5.1</a>
has been released in conjunction with Roberto Ierusalimschy and <a
href=http://www.keplerproject.org/">The Kepler Project</a> team.
It implements the Lua 5.1 package proposal on top of Lua 5.0. </p>
<p> As far as LuaSocket is concerned, this means that whoever is <p> As far as LuaSocket is concerned, this means that whoever is
deploying a solution that uses LuaSocket has a lot of freedom. Here we deploying a non-standard distribution of LuaSocket will probably
describe only the standard distribution. If the standard doesn't meet your have no problems customizing it. Here we will only describe the standard distribution. If the standard doesn't meet your
needs, we refer you to the Lua discussion list, where any quesetion about needs, we refer you to the Lua discussion list, where any question about
the package scheme will likely be answered promptly. the package scheme will likely already have been answered.
</p> </p>
<h3>Directory structure</h3> <h3>Directory structure</h3>
<p> The new package scheme has a root directory for the libraries installed <p> The standard distribution reserves a directory to be the root of
the libraries installed
on a given system. Let's call this directory <tt>&lt;ROOT&gt;</tt>. on a given system. Let's call this directory <tt>&lt;ROOT&gt;</tt>.
On my system, this is the <tt>/usr/local/share/lua/5.0</tt> directory. On my system, this is the <tt>/usr/local/share/lua/5.0</tt> directory.
Here is the standard LuaSocket distribution directory structure:</p> Here is the standard LuaSocket distribution directory structure:</p>
@ -82,7 +90,7 @@ X, they would be replaced by <tt>lsocket.dylib</tt> and
<p> In order for the interpreter to find all LuaSocket components, three <p> In order for the interpreter to find all LuaSocket components, three
environment variables need to be set. The first environment variable tells environment variables need to be set. The first environment variable tells
the interpreter to load the <tt>compat-5.1.lua</tt> module. </p> the interpreter to load the <tt>compat-5.1.lua</tt> module at startup: </p>
<pre class=example> <pre class=example>
LUA_INIT=@&lt;ROOT&gt;/compat-5.1.lua LUA_INIT=@&lt;ROOT&gt;/compat-5.1.lua
@ -98,7 +106,7 @@ LUA_CPATH=&lt;ROOT&gt;/?.dll;?.dll
</pre> </pre>
<p> Again, naturally, in Unix the shared library extension would be <p> Again, naturally, in Unix the shared library extension would be
<tt>.so</tt> instead of <tt>.dll</tt> and on Mac OS X they would be <tt>.so</tt> instead of <tt>.dll</tt> and on Mac OS X it would be
<tt>.dylib</tt></p> <tt>.dylib</tt></p>
<h3>Using LuaSocket</h3> <h3>Using LuaSocket</h3>
@ -115,7 +123,7 @@ Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
</pre> </pre>
<p> Each module loads their dependencies automatically, so you only need to <p> Each module loads their dependencies automatically, so you only need to
load the modues you are directly dependent upon. <p> load the modues you directly depend upon: <p>
<pre class=example> <pre class=example>
Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio

View File

@ -58,7 +58,7 @@ interface to I/O across different domains and operating systems.
</p> </p>
<p> <p>
The LuaSocket API was designed with two goals in mind. First, users The API design had two goals in mind. First, users
experienced with the C API to sockets should feel comfortable using LuaSocket. experienced with the C API to sockets should feel comfortable using LuaSocket.
Second, the simplicity and the feel of the Lua language should be Second, the simplicity and the feel of the Lua language should be
preserved. To achieve these goals, the LuaSocket API keeps the function names and semantics the C API whenever possible, but their usage in Lua has been greatly simplified. preserved. To achieve these goals, the LuaSocket API keeps the function names and semantics the C API whenever possible, but their usage in Lua has been greatly simplified.
@ -94,7 +94,7 @@ call might perform several OS calls, so that the two timeout values are
Finally, the host name resolution is transparent, meaning that most Finally, the host name resolution is transparent, meaning that most
functions and methods accept both IP addresses and host names. In case a functions and methods accept both IP addresses and host names. In case a
host name is given, the library queries the system's resolver and host name is given, the library queries the system's resolver and
tries the main returned IP address. Note that direct use of IP addresses tries the main IP address returned. Note that direct use of IP addresses
is more efficient, of course. The is more efficient, of course. The
<a href=dns.html#toip><tt>toip</tt></a> <a href=dns.html#toip><tt>toip</tt></a>
and <a href=dns.html#tohostname><tt>tohostname</tt></a> and <a href=dns.html#tohostname><tt>tohostname</tt></a>
@ -299,14 +299,14 @@ io.write(socket.try((udp:receive())))
<!-- More +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- More +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<h3 id=more>Much more</h3> <h3 id=more>Support modules</h3>
<p> LuaSocket offers much more than TCP and UDP support. As the library <p> Although not covered in the introduction, LuaSocket offers
much more than TCP and UDP functionality. As the library
evolved, support for <a href=http.html>HTTP</a>, <a href=ftp.html>FTP</a>, evolved, support for <a href=http.html>HTTP</a>, <a href=ftp.html>FTP</a>,
<a href=smtp.html>SMTP</a>, <a href=mime.html>MIME</a>, <a and <a href=smtp.html>SMTP</a> were built on top of these. These modules
href=url.html>URLs</a> and much more was made available.</a> These are and many others are covered by the <a href=reference.html>reference manual</a>.
mostly implemented in Lua itself, with critical parts implemented in C for </p>
efficiency</p>
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

View File

@ -16,7 +16,7 @@
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Wait for readable/writable/connected socket with timeout * Wait for readable/writable/connected socket with timeout
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
#ifndef SOCK_SELECT #ifdef SOCK_POLL
#include <sys/poll.h> #include <sys/poll.h>
#define WAITFD_R POLLIN #define WAITFD_R POLLIN
@ -29,8 +29,10 @@ static int sock_waitfd(int fd, int sw, p_tm tm) {
pfd.events = sw; pfd.events = sw;
pfd.revents = 0; pfd.revents = 0;
if (tm_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */ if (tm_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */
do ret = poll(&pfd, 1, (int)(tm_getretry(tm)*1e3)); do {
while (ret == -1 && errno == EINTR); int t = (int)(tm_getretry(tm)*1e3);
ret = poll(&pfd, 1, t >= 0? t: -1);
} while (ret == -1 && errno == EINTR);
if (ret == -1) return errno; if (ret == -1) return errno;
if (ret == 0) return IO_TIMEOUT; if (ret == 0) return IO_TIMEOUT;
if (sw == WAITFD_C && (pfd.revents & (POLLIN|POLLERR))) return IO_CLOSED; if (sw == WAITFD_C && (pfd.revents & (POLLIN|POLLERR))) return IO_CLOSED;