aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-11-29 06:55:47 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-11-29 06:55:47 +0000
commit4e5ad6d5ee9e72ddf6550a6795c18039b265e501 (patch)
tree0feae12e5053cde90e3cc419de7cacc56851b459
parent6abfbc742b52ef2f94bc5120781d346200535f63 (diff)
downloadluasocket-4e5ad6d5ee9e72ddf6550a6795c18039b265e501.tar.gz
luasocket-4e5ad6d5ee9e72ddf6550a6795c18039b265e501.tar.bz2
luasocket-4e5ad6d5ee9e72ddf6550a6795c18039b265e501.zip
Bug in poll.
Debug garbage in compat-5.1.c. Improvements to the user manual.
-rw-r--r--doc/index.html38
-rw-r--r--doc/installation.html38
-rw-r--r--doc/introduction.html16
-rw-r--r--src/usocket.c8
4 files changed, 54 insertions, 46 deletions
diff --git a/doc/index.html b/doc/index.html
index 7141931..727066e 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -47,22 +47,20 @@ functionality commonly needed by applications that deal with the Internet.
47 47
48<p> 48<p>
49The core support has been implemented so that it is both efficient and 49The core support has been implemented so that it is both efficient and
50simple to use. The core can be used by any Lua application once it has 50simple to use. It is available to any Lua application once it has been
51been properly initialized by the interpreter running the 51properly initialized by the interpreter in use. The code has been tested
52Lua application. The code has been tested and runs well on several Windows 52and runs well on several Windows and Unix platforms. </p>
53and Unix platforms.
54</p>
55 53
56<p> 54<p>
57The most used modules implement the 55Among the support modules, the most commonly used implement the
58<a href=smtp.html>SMTP</a> 56<a href=smtp.html>SMTP</a>
59(sending e-mails), 57(sending e-mails),
60<a href=http.html>HTTP</a> 58<a href=http.html>HTTP</a>
61(WWW access) and 59(WWW access) and
62<a href=ftp.html>FTP</a> 60<a href=ftp.html>FTP</a>
63(uploading and downloading files) client 61(uploading and downloading files) client
64protocols. These provide a very natural and generic interface to the e 62protocols. These provide a very natural and generic interface to the
65functionality covered by the protocols. 63functionality defined by each protocol.
66In addition, you will find that the 64In addition, you will find that the
67<a href=mime.html>MIME</a> (common encodings), 65<a href=mime.html>MIME</a> (common encodings),
68<a href=url.html>URL</a> 66<a href=url.html>URL</a>
@@ -107,12 +105,12 @@ The library can be downloaded in source code from the following links:
107 105
108<p> 106<p>
109Besides the full C and Lua source code for the library, the distribution 107Besides the full C and Lua source code for the library, the distribution
110contains several examples, this user's manual and the test procedures. 108contains several examples, this user's manual and basic test procedures.
111</p> 109</p>
112 110
113<p> 111<p>
114I am also providing PC Win32 binaries for those that want to give 112I am also providing PC Win32 binaries for those that want to give
115LuaSocket a quick try: 113LuaSocket a try (Those on Unix or Mac OS X can just type <tt>make</tt>):
116</p> 114</p>
117 115
118<blockquote> 116<blockquote>
@@ -126,12 +124,12 @@ The quick and dirty way to use these binaries is to unpack everything into a
126directory, say <tt>c:\luasocket</tt> (include all Lua files from the 124directory, say <tt>c:\luasocket</tt> (include all Lua files from the
127LuaSocket distrbitution in the same directory too!). 125LuaSocket distrbitution in the same directory too!).
128Then set <tt>LUA_INIT</tt> to load the <tt>compat-5.1.lua</tt> and set 126Then set <tt>LUA_INIT</tt> to load the <tt>compat-5.1.lua</tt> and set
129<tt>LUA_PATH</tt> and <tt>LUA_CPATH</tt> to look for files in that 127<tt>LUA_PATH</tt> and <tt>LUA_CPATH</tt> to look for files in the current
130directory: 128directory:
131</p> 129</p>
132 130
133<pre class=example> 131<pre class=example>
134c:\luasocket\&gt; set LUA_INIT=@compat-5.1.lua 132c:\luasocket\&gt; set LUA_INIT=@c:\luasocket\compat-5.1.lua
135c:\luasocket\&gt; set LUA_CPATH=?.dll 133c:\luasocket\&gt; set LUA_CPATH=?.dll
136c:\luasocket\&gt; set LUA_PATH=?.lua 134c:\luasocket\&gt; set LUA_PATH=?.lua
137</pre> 135</pre>
@@ -147,12 +145,12 @@ c:\luasocket\&gt; lua
147Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio 145Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
148&gt; http = require"http" 146&gt; http = require"http"
149&gt; print(http.request"http://www.tecgraf.puc-rio.br/luasocket/") 147&gt; print(http.request"http://www.tecgraf.puc-rio.br/luasocket/")
150--&gt; this gets dumped to terminal 148--&gt; the source to this webpage gets dumped to terminal
151</pre> 149</pre>
152 150
153<p> Take a look at the <a href=instalation.html>installation</a> section of 151<p> When you are done playing, take a look at the
154the manual to find out how to properly install the library after you are 152<a href=instalation.html>installation</a> section of the manual to find out
155done playing with it. </p> 153how to properly install the library. </p>
156 154
157<!-- thanks +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 155<!-- thanks +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
158 156
@@ -175,7 +173,7 @@ has been helping a lot too! Thanks to you all!
175 173
176<p> 174<p>
177The big change for the 2.0 (beta3) release was the adoption of the Lua 5.1 175The big change for the 2.0 (beta3) release was the adoption of the Lua 5.1
178package proposal. There were several bug fixes too (a beta is a 176package proposal. Naturally, there were a few bug fixes (a beta is a
179beta, is a beta). 177beta, is a beta).
180</p> 178</p>
181 179
@@ -195,7 +193,7 @@ beta, is a beta).
195<li> Fixed <tt>udp:sendto</tt> to call <tt>sock_sendto</tt> instead of 193<li> Fixed <tt>udp:sendto</tt> to call <tt>sock_sendto</tt> instead of
196 <tt>sock_send</tt>; 194 <tt>sock_send</tt>;
197<li> <tt>close</tt> wasn't returning 1! 195<li> <tt>close</tt> wasn't returning 1!
198<li> <tt>socket.gettime</tt> returns time since Unix Epoch 1/1/1970 (UTC) 196<li> <tt>socket.gettime</tt> returns time since Unix Epoch 1/1/1970 (UTC);
199<li> <tt>socket.sleep</tt> is robust to interrupts; 197<li> <tt>socket.sleep</tt> is robust to interrupts;
200<li> <tt>socket.select</tt> wasn't calling <tt>tm_markstart</tt>; 198<li> <tt>socket.select</tt> wasn't calling <tt>tm_markstart</tt>;
201<li> <tt>http.PROXY</tt> wasn't working. 199<li> <tt>http.PROXY</tt> wasn't working.
@@ -206,8 +204,8 @@ beta, is a beta).
206<h3 id=incompatible>Incompatibilities with previous versions</h3> 204<h3 id=incompatible>Incompatibilities with previous versions</h3>
207 205
208<ul> 206<ul>
209<li> Namespaces are hierarchical again. This means that whoever called 207<li> Namespaces are hierarchical again. This means that whoever used to
210<tt>require("url")</tt> should update their code to 208call <tt>require("url")</tt> should update their code to
211<tt>require("socket.url")</tt>. 209<tt>require("socket.url")</tt>.
212</ul> 210</ul>
213 211
diff --git a/doc/installation.html b/doc/installation.html
index 97888c6..63a555c 100644
--- a/doc/installation.html
+++ b/doc/installation.html
@@ -39,24 +39,32 @@ Installation">
39 39
40<h2>Instalation</h2> 40<h2>Instalation</h2>
41 41
42<p> LuaSocket 2.0 uses the new package proposal for Lua 5.1, throught the 42<p> LuaSocket 2.0 uses the new package proposal for Lua 5.1.
43compatibility module <a href=http://www.keplerproject.org/compat/> 43All Lua library developers are encouraged to update their libraries so that
44Compat-5.1</a> released in conjunction with Roberto Ierusalimschy and <a 44all libraries can coexist peacefully and users can benefit from the
45href=http://www.keplerproject.org/">The Kepler project</a>. The proposal 45standardization and flexibility of the standard.
46was considered important enough by the community to justify early adoption. 46</p>
47All Lua library developers are encouraged to change their libraries in 47
48preparation for the release of Lua 5.1. </p> 48<p>
49The proposal was considered important enough by some of us to justify
50early adoption, even before release of Lua 5.1.
51Thus, a compability module
52<a href=http://www.keplerproject.org/compat/>compat-5.1</a>
53has been released in conjunction with Roberto Ierusalimschy and <a
54href=http://www.keplerproject.org/">The Kepler Project</a> team.
55It implements the Lua 5.1 package proposal on top of Lua 5.0. </p>
49 56
50<p> As far as LuaSocket is concerned, this means that whoever is 57<p> As far as LuaSocket is concerned, this means that whoever is
51deploying a solution that uses LuaSocket has a lot of freedom. Here we 58deploying a non-standard distribution of LuaSocket will probably
52describe only the standard distribution. If the standard doesn't meet your 59have no problems customizing it. Here we will only describe the standard distribution. If the standard doesn't meet your
53needs, we refer you to the Lua discussion list, where any quesetion about 60needs, we refer you to the Lua discussion list, where any question about
54the package scheme will likely be answered promptly. 61the package scheme will likely already have been answered.
55</p> 62</p>
56 63
57<h3>Directory structure</h3> 64<h3>Directory structure</h3>
58 65
59<p> The new package scheme has a root directory for the libraries installed 66<p> The standard distribution reserves a directory to be the root of
67the libraries installed
60on a given system. Let's call this directory <tt>&lt;ROOT&gt;</tt>. 68on a given system. Let's call this directory <tt>&lt;ROOT&gt;</tt>.
61On my system, this is the <tt>/usr/local/share/lua/5.0</tt> directory. 69On my system, this is the <tt>/usr/local/share/lua/5.0</tt> directory.
62Here is the standard LuaSocket distribution directory structure:</p> 70Here is the standard LuaSocket distribution directory structure:</p>
@@ -82,7 +90,7 @@ X, they would be replaced by <tt>lsocket.dylib</tt> and
82 90
83<p> In order for the interpreter to find all LuaSocket components, three 91<p> In order for the interpreter to find all LuaSocket components, three
84environment variables need to be set. The first environment variable tells 92environment variables need to be set. The first environment variable tells
85the interpreter to load the <tt>compat-5.1.lua</tt> module. </p> 93the interpreter to load the <tt>compat-5.1.lua</tt> module at startup: </p>
86 94
87<pre class=example> 95<pre class=example>
88LUA_INIT=@&lt;ROOT&gt;/compat-5.1.lua 96LUA_INIT=@&lt;ROOT&gt;/compat-5.1.lua
@@ -98,7 +106,7 @@ LUA_CPATH=&lt;ROOT&gt;/?.dll;?.dll
98</pre> 106</pre>
99 107
100<p> Again, naturally, in Unix the shared library extension would be 108<p> Again, naturally, in Unix the shared library extension would be
101<tt>.so</tt> instead of <tt>.dll</tt> and on Mac OS X they would be 109<tt>.so</tt> instead of <tt>.dll</tt> and on Mac OS X it would be
102<tt>.dylib</tt></p> 110<tt>.dylib</tt></p>
103 111
104<h3>Using LuaSocket</h3> 112<h3>Using LuaSocket</h3>
@@ -115,7 +123,7 @@ Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
115</pre> 123</pre>
116 124
117<p> Each module loads their dependencies automatically, so you only need to 125<p> Each module loads their dependencies automatically, so you only need to
118load the modues you are directly dependent upon. <p> 126load the modues you directly depend upon: <p>
119 127
120<pre class=example> 128<pre class=example>
121Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio 129Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
diff --git a/doc/introduction.html b/doc/introduction.html
index 69a5eac..150a990 100644
--- a/doc/introduction.html
+++ b/doc/introduction.html
@@ -58,7 +58,7 @@ interface to I/O across different domains and operating systems.
58</p> 58</p>
59 59
60<p> 60<p>
61The LuaSocket API was designed with two goals in mind. First, users 61The API design had two goals in mind. First, users
62experienced with the C API to sockets should feel comfortable using LuaSocket. 62experienced with the C API to sockets should feel comfortable using LuaSocket.
63Second, the simplicity and the feel of the Lua language should be 63Second, the simplicity and the feel of the Lua language should be
64preserved. 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. 64preserved. 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
94Finally, the host name resolution is transparent, meaning that most 94Finally, the host name resolution is transparent, meaning that most
95functions and methods accept both IP addresses and host names. In case a 95functions and methods accept both IP addresses and host names. In case a
96host name is given, the library queries the system's resolver and 96host name is given, the library queries the system's resolver and
97tries the main returned IP address. Note that direct use of IP addresses 97tries the main IP address returned. Note that direct use of IP addresses
98is more efficient, of course. The 98is more efficient, of course. The
99<a href=dns.html#toip><tt>toip</tt></a> 99<a href=dns.html#toip><tt>toip</tt></a>
100and <a href=dns.html#tohostname><tt>tohostname</tt></a> 100and <a href=dns.html#tohostname><tt>tohostname</tt></a>
@@ -299,14 +299,14 @@ io.write(socket.try((udp:receive())))
299 299
300<!-- More +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 300<!-- More +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
301 301
302<h3 id=more>Much more</h3> 302<h3 id=more>Support modules</h3>
303 303
304<p> LuaSocket offers much more than TCP and UDP support. As the library 304<p> Although not covered in the introduction, LuaSocket offers
305much more than TCP and UDP functionality. As the library
305evolved, support for <a href=http.html>HTTP</a>, <a href=ftp.html>FTP</a>, 306evolved, support for <a href=http.html>HTTP</a>, <a href=ftp.html>FTP</a>,
306<a href=smtp.html>SMTP</a>, <a href=mime.html>MIME</a>, <a 307and <a href=smtp.html>SMTP</a> were built on top of these. These modules
307href=url.html>URLs</a> and much more was made available.</a> These are 308and many others are covered by the <a href=reference.html>reference manual</a>.
308mostly implemented in Lua itself, with critical parts implemented in C for 309</p>
309efficiency</p>
310 310
311<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 311<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
312 312
diff --git a/src/usocket.c b/src/usocket.c
index 2143c7d..c1ab725 100644
--- a/src/usocket.c
+++ b/src/usocket.c
@@ -16,7 +16,7 @@
16/*-------------------------------------------------------------------------*\ 16/*-------------------------------------------------------------------------*\
17* Wait for readable/writable/connected socket with timeout 17* Wait for readable/writable/connected socket with timeout
18\*-------------------------------------------------------------------------*/ 18\*-------------------------------------------------------------------------*/
19#ifndef SOCK_SELECT 19#ifdef SOCK_POLL
20#include <sys/poll.h> 20#include <sys/poll.h>
21 21
22#define WAITFD_R POLLIN 22#define WAITFD_R POLLIN
@@ -29,8 +29,10 @@ static int sock_waitfd(int fd, int sw, p_tm tm) {
29 pfd.events = sw; 29 pfd.events = sw;
30 pfd.revents = 0; 30 pfd.revents = 0;
31 if (tm_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */ 31 if (tm_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */
32 do ret = poll(&pfd, 1, (int)(tm_getretry(tm)*1e3)); 32 do {
33 while (ret == -1 && errno == EINTR); 33 int t = (int)(tm_getretry(tm)*1e3);
34 ret = poll(&pfd, 1, t >= 0? t: -1);
35 } while (ret == -1 && errno == EINTR);
34 if (ret == -1) return errno; 36 if (ret == -1) return errno;
35 if (ret == 0) return IO_TIMEOUT; 37 if (ret == 0) return IO_TIMEOUT;
36 if (sw == WAITFD_C && (pfd.revents & (POLLIN|POLLERR))) return IO_CLOSED; 38 if (sw == WAITFD_C && (pfd.revents & (POLLIN|POLLERR))) return IO_CLOSED;