@@ -276,7 +278,7 @@ return convention WILL break old code;
does not call listen anymore. It is the new listen
method that turns a TCP object into a server object;
-
socket.time became socket.gettime for uniformity;
+
socket.time changed to socket.gettime for uniformity;
Interface to options has changed.
diff --git a/doc/introduction.html b/doc/introduction.html
index 2c738d6..6468148 100644
--- a/doc/introduction.html
+++ b/doc/introduction.html
@@ -3,7 +3,9 @@
-LuaSocket: Network support for the Lua language
+
+
+LuaSocket: Introduction to the core
@@ -16,7 +18,7 @@
@@ -209,7 +211,7 @@ print("Please telnet to localhost on port " .. port)
print("After connecting, you have 10s to enter a line to be echoed")
-- loop forever waiting for clients
while 1 do
- -- wait for a conection from any client
+ -- wait for a connection from any client
local client = server:accept()
-- make sure we don't block waiting for this client's line
client:settimeout(10)
diff --git a/doc/ltn12.html b/doc/ltn12.html
index bfb9b51..40dcf96 100644
--- a/doc/ltn12.html
+++ b/doc/ltn12.html
@@ -3,7 +3,10 @@
-LuaSocket: Network support for the Lua language
+
+
+LuaSocket: LTN12 module
@@ -16,7 +19,7 @@
@@ -92,7 +94,7 @@ The function returns a filter that performs the conversion.
Note: There is no perfect solution to this problem. Different end-of-line
markers are an evil that will probably plague developers forever.
This function, however, will work perfectly for text created with any of
-the most common end-of-line markers, i.e. the MacOS (CR), the Unix (LF),
+the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF),
or the DOS (CRLF) conventions. Even if the data has mixed end-of-line
markers, the function will still work well, although it doesn't
guarantee that the number of empty lines will be correct.
diff --git a/doc/reference.html b/doc/reference.html
index 5c07c4d..8d129e3 100644
--- a/doc/reference.html
+++ b/doc/reference.html
@@ -3,7 +3,9 @@
-LuaSocket: Network support for the Lua language
+
+
+LuaSocket: Index to reference manual
@@ -16,7 +18,7 @@
@@ -48,7 +50,7 @@ control (if you bother to read the code).
Another RFC of interest is RFC 2822,
which governs the Internet Message Format.
-Multipart messages (those that contain attatchments) are part
+Multipart messages (those that contain attachments) are part
of the MIME standard, but described mainly
in RFC
2046
@@ -98,7 +100,7 @@ in representing them in a Lua table.
-The following constants can be set to control the default behaviour of
+The following constants can be set to control the default behavior of
the SMTP module:
@@ -256,7 +258,7 @@ mesgt = {
to = "Fulano da Silva <fulano@example.com>",
cc = '"Beltrano F. Nunes" <beltrano@example.com>',
subject = "My first message"
- }
+ },
body = "I hope this works. If it does, I can send you another 1000 copies."
}
diff --git a/doc/socket.html b/doc/socket.html
index 1bbeb7f..129b134 100644
--- a/doc/socket.html
+++ b/doc/socket.html
@@ -3,7 +3,9 @@
-LuaSocket: Network support for the Lua language
+
+
+LuaSocket: The socket namespace
@@ -16,7 +18,7 @@
@@ -55,6 +57,16 @@ socket.bind(address, port [, backlog])
+This function is a shortcut that creates and returns a TCP server object
+bound to a local address and port, ready to
+accept client connections. Optionally,
+user can also specify the backlog argument to the
+listen method (defaults to 32).
+
+
+
+Note: The server object returned will have the option "reuseaddr"
+set to true.
@@ -64,9 +76,9 @@ socket.connect(address, port [, locaddr, locport])
-This function is a shortcut that creates and returns a TCP socket object
+This function is a shortcut that creates and returns a TCP client object
connected to a remote host at a given port. Optionally,
-the use can also specify the local address and port to bind
+the user can also specify the local address and port to bind
(locaddr and locport).
diff --git a/doc/tcp.html b/doc/tcp.html
index 37b0b56..5c0da75 100644
--- a/doc/tcp.html
+++ b/doc/tcp.html
@@ -3,7 +3,9 @@
-LuaSocket: Network support for the Lua language
+
+
+LuaSocket: TCP/IP support
@@ -16,7 +18,7 @@
-Note: The function socket.bind
+Note: The function socket.bind
is available and is a shortcut for the creation server sockets.
@@ -163,15 +165,15 @@ describing the error. In case of success, the method returns 1.
-Note: The function socket.connect
+Note: The function socket.connect
is available and is a shortcut for the creation of client sockets.
Note: Starting with LuaSocket 2.0,
the settimeout
-function affects the behavior of connect, causing it to return in case of
-a timeout error.
+method affects the behavior of connect, causing it to return in case of
+a timeout.
@@ -197,6 +199,7 @@ Note: It makes no sense to call this method on server objects.
@@ -135,7 +137,7 @@ Rebuilds an URL from its parts.
Parsed_url is a table with same components returned by
parse.
Lower level components, if specified,
-take precedence over hight level components of the URL grammar.
+take precedence over high level components of the URL grammar.
@@ -279,8 +281,8 @@ Breaks a <path> URL component into all its
Since some characters are reserved in URLs, they must be escaped
whenever present in a <path> component. Therefore, before
-returning a list with all the parsed segments, the function unescapes all
-of them.
+returning a list with all the parsed segments, the function removes
+escaping from all of them.
diff --git a/samples/cddb.lua b/samples/cddb.lua
index aefa04e..daa5df1 100644
--- a/samples/cddb.lua
+++ b/samples/cddb.lua
@@ -1,5 +1,5 @@
-socket = require("socket")
-http = require("http")
+local socket = require("socket")
+local http = require("http")
if not arg or not arg[1] or not arg[2] then
print("luasocket cddb.lua []")
diff --git a/samples/daytimeclnt.lua b/samples/daytimeclnt.lua
index b4075e9..6a26ffc 100644
--- a/samples/daytimeclnt.lua
+++ b/samples/daytimeclnt.lua
@@ -4,7 +4,7 @@
-- Author: Diego Nehab
-- RCS ID: $Id$
-----------------------------------------------------------------------------
-require"socket"
+local socket = require"socket"
host = host or "127.0.0.1"
port = port or 13
if arg then
diff --git a/samples/echosrvr.lua b/samples/echosrvr.lua
index 73bf374..3ebbe85 100644
--- a/samples/echosrvr.lua
+++ b/samples/echosrvr.lua
@@ -4,7 +4,7 @@
-- Author: Diego Nehab
-- RCS ID: $Id$
-----------------------------------------------------------------------------
-socket = require("socket")
+local socket = require("socket")
host = host or "127.0.0.1"
port = port or 7
if arg then
diff --git a/samples/talker.lua b/samples/talker.lua
index bafd021..3f6e69c 100644
--- a/samples/talker.lua
+++ b/samples/talker.lua
@@ -4,7 +4,7 @@
-- Author: Diego Nehab
-- RCS ID: $Id$
-----------------------------------------------------------------------------
-socket = require("socket")
+local socket = require("socket")
host = host or "localhost"
port = port or 8080
if arg then
diff --git a/samples/tinyirc.lua b/samples/tinyirc.lua
index 85ebe29..13f42ec 100644
--- a/samples/tinyirc.lua
+++ b/samples/tinyirc.lua
@@ -4,7 +4,7 @@
-- Author: Diego Nehab
-- RCS ID: $Id$
-----------------------------------------------------------------------------
-socket = require("socket")
+local socket = require("socket")
host = host or "*"
port1 = port1 or 8080
port2 = port2 or 8181
diff --git a/src/http.lua b/src/http.lua
index 9c568bc..cdb435d 100644
--- a/src/http.lua
+++ b/src/http.lua
@@ -22,8 +22,6 @@ TIMEOUT = 60
PORT = 80
-- user agent field sent in request
USERAGENT = socket.VERSION
--- block size used in transfers
-BLOCKSIZE = 2048
-----------------------------------------------------------------------------
-- Low level HTTP API
diff --git a/src/luasocket.h b/src/luasocket.h
index 6d30605..35dc3d9 100644
--- a/src/luasocket.h
+++ b/src/luasocket.h
@@ -25,7 +25,10 @@
/*-------------------------------------------------------------------------*\
* Initializes the library.
\*-------------------------------------------------------------------------*/
+#ifndef LUASOCKET_LIBNAME
#define LUASOCKET_LIBNAME "socket"
+#endif
+
LUASOCKET_API int luaopen_socket(lua_State *L);
#endif /* LUASOCKET_H */
diff --git a/src/mime.h b/src/mime.h
index be16920..ad8a573 100644
--- a/src/mime.h
+++ b/src/mime.h
@@ -19,7 +19,10 @@
#define MIME_API extern
#endif
+#ifndef MIME_LIBNAME
#define MIME_LIBNAME "mime"
+#endif
+
MIME_API int luaopen_mime(lua_State *L);
#endif /* MIME_H */
diff --git a/src/mime.lua b/src/mime.lua
index 345bd25..fcdc358 100644
--- a/src/mime.lua
+++ b/src/mime.lua
@@ -12,9 +12,9 @@ local mime = requirelib("mime", "luaopen_mime", getfenv(1))
local ltn12 = require("ltn12")
-- encode, decode and wrap algorithm tables
-encodet = {}
-decodet = {}
-wrapt = {}
+mime.encodet = {}
+mime.decodet = {}
+mime.wrapt = {}
-- creates a function that chooses a filter by name from a given table
local function choose(table)
@@ -29,47 +29,47 @@ local function choose(table)
end
-- define the encoding filters
-encodet['base64'] = function()
+mime.encodet['base64'] = function()
return ltn12.filter.cycle(b64, "")
end
-encodet['quoted-printable'] = function(mode)
+mime.encodet['quoted-printable'] = function(mode)
return ltn12.filter.cycle(qp, "",
(mode == "binary") and "=0D=0A" or "\r\n")
end
-- define the decoding filters
-decodet['base64'] = function()
+mime.decodet['base64'] = function()
return ltn12.filter.cycle(unb64, "")
end
-decodet['quoted-printable'] = function()
+mime.decodet['quoted-printable'] = function()
return ltn12.filter.cycle(unqp, "")
end
-- define the line-wrap filters
-wrapt['text'] = function(length)
+mime.wrapt['text'] = function(length)
length = length or 76
return ltn12.filter.cycle(wrp, length, length)
end
-wrapt['base64'] = wrapt['text']
-wrapt['default'] = wrapt['text']
+mime.wrapt['base64'] = wrapt['text']
+mime.wrapt['default'] = wrapt['text']
-wrapt['quoted-printable'] = function()
+mime.wrapt['quoted-printable'] = function()
return ltn12.filter.cycle(qpwrp, 76, 76)
end
-- function that choose the encoding, decoding or wrap algorithm
-encode = choose(encodet)
-decode = choose(decodet)
-wrap = choose(wrapt)
+mime.encode = choose(encodet)
+mime.decode = choose(decodet)
+mime.wrap = choose(wrapt)
-- define the end-of-line normalization filter
-function normalize(marker)
+function mime.normalize(marker)
return ltn12.filter.cycle(eol, 0, marker)
end
-- high level stuffing filter
-function stuff()
+function mime.stuff()
return ltn12.filter.cycle(dot, 2)
end
diff --git a/src/socket.lua b/src/socket.lua
index 4d64651..b3889d7 100644
--- a/src/socket.lua
+++ b/src/socket.lua
@@ -8,7 +8,6 @@
-- Load LuaSocket from dynamic library
-----------------------------------------------------------------------------
local socket = requirelib("luasocket", "luaopen_socket", getfenv(1))
-_LOADED["socket"] = socket
-----------------------------------------------------------------------------
-- Auxiliar functions
@@ -31,7 +30,7 @@ function socket.bind(host, port, backlog)
sock:setoption("reuseaddr", true)
local res, err = sock:bind(host, port)
if not res then return nil, err end
- backlog = backlog or 1
+ backlog = backlog or 32
res, err = sock:listen(backlog)
if not res then return nil, err end
return sock
diff --git a/src/tcp.c b/src/tcp.c
index adc2585..cbfebdb 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -130,7 +130,7 @@ static int meth_setoption(lua_State *L)
static int meth_getfd(lua_State *L)
{
p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1);
- lua_pushnumber(L, tcp->sock);
+ lua_pushnumber(L, (int) tcp->sock);
return 1;
}
@@ -164,6 +164,7 @@ static int meth_accept(lua_State *L)
p_tcp clnt = lua_newuserdata(L, sizeof(t_tcp));
aux_setclass(L, "tcp{client}", -1);
/* initialize structure fields */
+ sock_setnonblocking(&sock);
clnt->sock = sock;
io_init(&clnt->io, (p_send)sock_send, (p_recv)sock_recv, &clnt->sock);
tm_init(&clnt->tm, -1, -1);
@@ -310,10 +311,11 @@ static int global_create(lua_State *L)
if (!err) {
/* allocate tcp object */
p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp));
- tcp->sock = sock;
/* set its type as master object */
aux_setclass(L, "tcp{master}", -1);
/* initialize remaining structure fields */
+ sock_setnonblocking(&sock);
+ tcp->sock = sock;
io_init(&tcp->io, (p_send) sock_send, (p_recv) sock_recv, &tcp->sock);
tm_init(&tcp->tm, -1, -1);
buf_init(&tcp->buf, &tcp->io, &tcp->tm);
diff --git a/src/udp.c b/src/udp.c
index 512cc0b..d20d61b 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -208,7 +208,7 @@ static int meth_receivefrom(lua_State *L)
static int meth_getfd(lua_State *L)
{
p_udp udp = (p_udp) aux_checkgroup(L, "udp{any}", 1);
- lua_pushnumber(L, udp->sock);
+ lua_pushnumber(L, (int) udp->sock);
return 1;
}
@@ -328,10 +328,10 @@ static int global_create(lua_State *L)
if (!err) {
/* allocate tcp object */
p_udp udp = (p_udp) lua_newuserdata(L, sizeof(t_udp));
- udp->sock = sock;
- /* set its type as master object */
aux_setclass(L, "udp{unconnected}", -1);
/* initialize remaining structure fields */
+ sock_setnonblocking(&sock);
+ udp->sock = sock;
tm_init(&udp->tm, -1, -1);
return 1;
} else {
diff --git a/src/usocket.c b/src/usocket.c
index ea0f172..617b1ea 100644
--- a/src/usocket.c
+++ b/src/usocket.c
@@ -81,7 +81,6 @@ const char *sock_create(p_sock ps, int domain, int type, int protocol)
t_sock sock = socket(domain, type, protocol);
if (sock == SOCK_INVALID) return sock_createstrerror(errno);
*ps = sock;
- sock_setnonblocking(ps);
return NULL;
}
@@ -178,10 +177,7 @@ const char *sock_accept(p_sock ps, p_sock pa, SA *addr,
do *pa = accept(sock, addr, addr_len);
while (*pa < 0 && errno == EINTR);
/* if result is valid, we are done */
- if (*pa != SOCK_INVALID) {
- sock_setnonblocking(pa);
- return NULL;
- }
+ if (*pa != SOCK_INVALID) return NULL;
/* find out if we failed for a fatal reason */
if (errno != EWOULDBLOCK && errno != ECONNABORTED)
return sock_acceptstrerror(errno);
diff --git a/src/wsocket.c b/src/wsocket.c
index 84a49dc..e276fe0 100644
--- a/src/wsocket.c
+++ b/src/wsocket.c
@@ -88,7 +88,6 @@ const char *sock_create(p_sock ps, int domain, int type, int protocol)
if (sock == SOCK_INVALID)
return sock_createstrerror(WSAGetLastError());
*ps = sock;
- sock_setnonblocking(ps);
return NULL;
}
@@ -177,10 +176,7 @@ const char *sock_accept(p_sock ps, p_sock pa, SA *addr,
/* try to get client socket */
*pa = accept(sock, addr, addr_len);
/* if return is valid, we are done */
- if (*pa != SOCK_INVALID) {
- sock_setnonblocking(pa);
- return NULL;
- }
+ if (*pa != SOCK_INVALID) return NULL;
/* optimization */
if (timeout == 0) return io_strerror(IO_TIMEOUT);
/* otherwise find out why we failed */
diff --git a/test/httptest.lua b/test/httptest.lua
index ea8465d..3a4d461 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -4,11 +4,11 @@
-- to "/luasocket-test-cgi" and "/luasocket-test-cgi/"
-- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth
-socket = require("socket")
-http = require("http")
-mime = require("mime")
-url = require("url")
-ltn12 = require("ltn12")
+local socket = require("socket")
+local http = require("http")
+local mime = require("mime")
+local url = require("url")
+local ltn12 = require("ltn12")
dofile("testsupport.lua")
diff --git a/test/mimetest.lua b/test/mimetest.lua
index f51c3b8..685c610 100644
--- a/test/mimetest.lua
+++ b/test/mimetest.lua
@@ -8,7 +8,7 @@ local qptest = "qptest.bin"
local eqptest = "qptest.bin2"
local dqptest = "qptest.bin3"
-local b64test = "luasocket.dll"
+local b64test = "luasocket.dylib"
local eb64test = "b64test.bin"
local db64test = "b64test.bin2"
diff --git a/test/stufftest.lua b/test/stufftest.lua
index eddf636..490053f 100644
--- a/test/stufftest.lua
+++ b/test/stufftest.lua
@@ -1,4 +1,4 @@
-mime = require("mime")
+local mime = require("mime")
function test_dot(original, right)
local result, n = mime.dot(2, original)
diff --git a/test/testclnt.lua b/test/testclnt.lua
index 1b20ad1..9aa07fe 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -1,4 +1,4 @@
-socket = require"socket"
+local socket = require"socket"
host = host or "localhost"
port = port or "8080"
@@ -418,7 +418,7 @@ function connect_errors()
assert(not c and e == "connection refused", e)
print("ok")
io.stderr:write("host not found: ")
- local c, e = socket.connect("not.exist.com", 1);
+ local c, e = socket.connect("host.is.invalid", 1);
assert(not c and e == "host not found", e)
print("ok")
end
diff --git a/test/testsrvr.lua b/test/testsrvr.lua
index 5b842f1..71281cf 100644
--- a/test/testsrvr.lua
+++ b/test/testsrvr.lua
@@ -1,4 +1,4 @@
-socket = require"socket"
+local socket = require"socket"
host = host or "localhost"
port = port or "8080"
diff --git a/test/urltest.lua b/test/urltest.lua
index 92f2fae..eb15bcf 100644
--- a/test/urltest.lua
+++ b/test/urltest.lua
@@ -1,4 +1,4 @@
-socket = require("socket")
+local socket = require("socket")
socket.url = require("url")
dofile("testsupport.lua")