From 4e5ad6d5ee9e72ddf6550a6795c18039b265e501 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Mon, 29 Nov 2004 06:55:47 +0000 Subject: [PATCH] Bug in poll. Debug garbage in compat-5.1.c. Improvements to the user manual. --- doc/index.html | 38 ++++++++++++++++++-------------------- doc/installation.html | 38 +++++++++++++++++++++++--------------- doc/introduction.html | 16 ++++++++-------- src/usocket.c | 8 +++++--- 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.

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 -been properly initialized by the interpreter running the -Lua application. The code has been tested and runs well on several Windows -and Unix platforms. -

+simple to use. It is available to any Lua application once it has been +properly initialized by the interpreter in use. The code has been tested +and runs well on several Windows and Unix platforms.

-The most used modules implement the +Among the support modules, the most commonly used implement the SMTP (sending e-mails), HTTP (WWW access) and FTP (uploading and downloading files) client -protocols. These provide a very natural and generic interface to the e -functionality covered by the protocols. +protocols. These provide a very natural and generic interface to the +functionality defined by each protocol. In addition, you will find that the MIME (common encodings), URL @@ -107,12 +105,12 @@ The library can be downloaded in source code from the following links:

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.

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 make):

@@ -126,12 +124,12 @@ The quick and dirty way to use these binaries is to unpack everything into a directory, say c:\luasocket (include all Lua files from the LuaSocket distrbitution in the same directory too!). Then set LUA_INIT to load the compat-5.1.lua and set -LUA_PATH and LUA_CPATH to look for files in that +LUA_PATH and LUA_CPATH to look for files in the current directory:

-c:\luasocket\> set LUA_INIT=@compat-5.1.lua
+c:\luasocket\> set LUA_INIT=@c:\luasocket\compat-5.1.lua
 c:\luasocket\> set LUA_CPATH=?.dll
 c:\luasocket\> set LUA_PATH=?.lua
 
@@ -147,12 +145,12 @@ c:\luasocket\> lua Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio > http = require"http" > print(http.request"http://www.tecgraf.puc-rio.br/luasocket/") ---> this gets dumped to terminal +--> the source to this webpage gets dumped to terminal -

Take a look at the installation section of -the manual to find out how to properly install the library after you are -done playing with it.

+

When you are done playing, take a look at the +installation section of the manual to find out +how to properly install the library.

@@ -175,7 +173,7 @@ has been helping a lot too! Thanks to you all!

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).

@@ -195,7 +193,7 @@ beta, is a beta).
  • Fixed udp:sendto to call sock_sendto instead of sock_send;
  • close wasn't returning 1! -
  • socket.gettime returns time since Unix Epoch 1/1/1970 (UTC) +
  • socket.gettime returns time since Unix Epoch 1/1/1970 (UTC);
  • socket.sleep is robust to interrupts;
  • socket.select wasn't calling tm_markstart;
  • http.PROXY wasn't working. @@ -206,8 +204,8 @@ beta, is a beta).

    Incompatibilities with previous versions

      -
    • Namespaces are hierarchical again. This means that whoever called -require("url") should update their code to +
    • Namespaces are hierarchical again. This means that whoever used to +call require("url") should update their code to require("socket.url").
    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">

    Instalation

    -

    LuaSocket 2.0 uses the new package proposal for Lua 5.1, throught the -compatibility module -Compat-5.1 released in conjunction with Roberto Ierusalimschy and The Kepler project. The proposal -was considered important enough by the community to justify early adoption. -All Lua library developers are encouraged to change their libraries in -preparation for the release of Lua 5.1.

    +

    LuaSocket 2.0 uses the new package proposal for Lua 5.1. +All Lua library developers are encouraged to update their libraries so that +all libraries can coexist peacefully and users can benefit from the +standardization and flexibility of the standard. +

    + +

    +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 +compat-5.1 +has been released in conjunction with Roberto Ierusalimschy and The Kepler Project team. +It implements the Lua 5.1 package proposal on top of Lua 5.0.

    As far as LuaSocket is concerned, this means that whoever is -deploying a solution that uses LuaSocket has a lot of freedom. Here we -describe only the standard distribution. If the standard doesn't meet your -needs, we refer you to the Lua discussion list, where any quesetion about -the package scheme will likely be answered promptly. +deploying a non-standard distribution of LuaSocket will probably +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 question about +the package scheme will likely already have been answered.

    Directory structure

    -

    The new package scheme has a root directory for the libraries installed +

    The standard distribution reserves a directory to be the root of +the libraries installed on a given system. Let's call this directory <ROOT>. On my system, this is the /usr/local/share/lua/5.0 directory. Here is the standard LuaSocket distribution directory structure:

    @@ -82,7 +90,7 @@ X, they would be replaced by lsocket.dylib and

    In order for the interpreter to find all LuaSocket components, three environment variables need to be set. The first environment variable tells -the interpreter to load the compat-5.1.lua module.

    +the interpreter to load the compat-5.1.lua module at startup:

     LUA_INIT=@<ROOT>/compat-5.1.lua
    @@ -98,7 +106,7 @@ LUA_CPATH=<ROOT>/?.dll;?.dll
     

    Again, naturally, in Unix the shared library extension would be -.so instead of .dll and on Mac OS X they would be +.so instead of .dll and on Mac OS X it would be .dylib

    Using LuaSocket

    @@ -115,7 +123,7 @@ Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio

    Each module loads their dependencies automatically, so you only need to -load the modues you are directly dependent upon.

    +load the modues you directly depend upon:

     Lua 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.
     

    -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. 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. @@ -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 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 -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 toip and tohostname @@ -299,14 +299,14 @@ io.write(socket.try((udp:receive()))) -

    Much more

    +

    Support modules

    -

    LuaSocket offers much more than TCP and UDP support. As the library +

    Although not covered in the introduction, LuaSocket offers +much more than TCP and UDP functionality. As the library evolved, support for HTTP, FTP, -SMTP, MIME, URLs and much more was made available. These are -mostly implemented in Lua itself, with critical parts implemented in C for -efficiency

    +and SMTP were built on top of these. These modules +and many others are covered by the reference manual. +

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