diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-28 21:08:50 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-28 21:08:50 +0000 |
commit | f18d1b7cd0ec4708518ab5e18ea33b6eadca0301 (patch) | |
tree | e831c6b1957af47db1301675b52c0d2a2e315fa7 | |
parent | 307603b24dde69eac62d2cb52123488137520c9c (diff) | |
download | luasocket-f18d1b7cd0ec4708518ab5e18ea33b6eadca0301.tar.gz luasocket-f18d1b7cd0ec4708518ab5e18ea33b6eadca0301.tar.bz2 luasocket-f18d1b7cd0ec4708518ab5e18ea33b6eadca0301.zip |
Closer to release...
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | etc/check-links.lua | 8 | ||||
-rw-r--r-- | etc/dict.lua | 19 | ||||
-rw-r--r-- | etc/get.lua | 12 | ||||
-rw-r--r-- | samples/daytimeclnt.lua | 6 | ||||
-rw-r--r-- | samples/echoclnt.lua | 12 | ||||
-rw-r--r-- | samples/echosrvr.lua | 6 | ||||
-rw-r--r-- | samples/listener.lua | 6 | ||||
-rw-r--r-- | src/buffer.c | 2 | ||||
-rw-r--r-- | src/buffer.h | 3 | ||||
-rw-r--r-- | src/ftp.lua | 1 | ||||
-rw-r--r-- | src/http.lua | 1 | ||||
-rw-r--r-- | src/inet.c | 9 | ||||
-rw-r--r-- | src/inet.h | 4 | ||||
-rw-r--r-- | src/luasocket.c | 7 | ||||
-rw-r--r-- | src/select.c | 18 | ||||
-rw-r--r-- | src/select.h | 4 | ||||
-rw-r--r-- | src/smtp.lua | 1 | ||||
-rw-r--r-- | src/socket.h | 6 | ||||
-rw-r--r-- | src/timeout.c | 11 | ||||
-rw-r--r-- | src/timeout.h | 5 | ||||
-rw-r--r-- | src/udp.c | 26 | ||||
-rw-r--r-- | src/udp.h | 6 | ||||
-rw-r--r-- | src/unix.c | 15 | ||||
-rw-r--r-- | src/unix.h | 5 | ||||
-rw-r--r-- | src/url.lua | 1 | ||||
-rw-r--r-- | test/smtptest.lua | 2 | ||||
-rw-r--r-- | test/testclnt.lua | 12 | ||||
-rw-r--r-- | test/testsrvr.lua | 6 | ||||
-rw-r--r-- | test/tftptest.lua | 22 | ||||
-rw-r--r-- | test/urltest.lua | 3 |
31 files changed, 163 insertions, 77 deletions
@@ -1,4 +1,5 @@ | |||
1 | - Inicializaccao das classes pode falhar? | 1 | - Inicializaccao das classes pode falhar? |
2 | - Ajeitar melhor a hierarquia de classes. Ajeitar o file... | ||
2 | 3 | ||
3 | * Como mostrar um erro em lua_socketlibopen()... | 4 | * Como mostrar um erro em lua_socketlibopen()... |
4 | * O location do "redirect" pode ser relativo ao servidor atual (não pode, | 5 | * O location do "redirect" pode ser relativo ao servidor atual (não pode, |
diff --git a/etc/check-links.lua b/etc/check-links.lua index 0dca27c..705c0ce 100644 --- a/etc/check-links.lua +++ b/etc/check-links.lua | |||
@@ -1,3 +1,7 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- Little program that checks links in HTML files | ||
3 | -- LuaSocket 1.5 sample files. | ||
4 | ----------------------------------------------------------------------------- | ||
1 | socket.http.TIMEOUT = 10 | 5 | socket.http.TIMEOUT = 10 |
2 | 6 | ||
3 | cache = {} | 7 | cache = {} |
@@ -14,7 +18,7 @@ end | |||
14 | 18 | ||
15 | function getstatus(url) | 19 | function getstatus(url) |
16 | local parsed = socket.url.parse(url, { scheme = "file" }) | 20 | local parsed = socket.url.parse(url, { scheme = "file" }) |
17 | if cache[url] then return cache[url].res end | 21 | if cache[url] then return cache[url] end |
18 | local res | 22 | local res |
19 | if parsed.scheme == "http" then | 23 | if parsed.scheme == "http" then |
20 | local request = { url = url } | 24 | local request = { url = url } |
@@ -34,7 +38,7 @@ function getstatus(url) | |||
34 | res = nil | 38 | res = nil |
35 | else res = error end | 39 | else res = error end |
36 | else res = string.format("unhandled scheme '%s'", parsed.scheme) end | 40 | else res = string.format("unhandled scheme '%s'", parsed.scheme) end |
37 | cache[url] = { res = res } | 41 | cache[url] = res |
38 | return res | 42 | return res |
39 | end | 43 | end |
40 | 44 | ||
diff --git a/etc/dict.lua b/etc/dict.lua index 4685ca1..6790cab 100644 --- a/etc/dict.lua +++ b/etc/dict.lua | |||
@@ -1,12 +1,16 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- Little program to download DICT word definitions | ||
3 | -- LuaSocket 1.5 sample files | ||
4 | ----------------------------------------------------------------------------- | ||
1 | function get_status(sock, valid) | 5 | function get_status(sock, valid) |
2 | local line, err = sock:receive() | 6 | local line, err = sock:receive() |
3 | local code, par | 7 | local code, par |
4 | if not line then sock:close() return err end | 8 | if not line then sock:close() return err end |
5 | _, _, code = strfind(line, "^(%d%d%d)") | 9 | _, _, code = string.find(line, "^(%d%d%d)") |
6 | code = tonumber(code) | 10 | code = tonumber(code) |
7 | if code ~= valid then return code end | 11 | if code ~= valid then return code end |
8 | if code == 150 then | 12 | if code == 150 then |
9 | _,_,_, par = strfind(line, "^(%d%d%d) (%d*)") | 13 | _,_,_, par = string.find(line, "^(%d%d%d) (%d*)") |
10 | par = tonumber(par) | 14 | par = tonumber(par) |
11 | end | 15 | end |
12 | return nil, par | 16 | return nil, par |
@@ -24,7 +28,7 @@ function get_def(sock) | |||
24 | end | 28 | end |
25 | 29 | ||
26 | function dict_open() | 30 | function dict_open() |
27 | local sock, err = connect("dict.org", 2628) | 31 | local sock, err = socket.connect("dict.org", 2628) |
28 | if not sock then return nil, err end | 32 | if not sock then return nil, err end |
29 | sock:timeout(10) | 33 | sock:timeout(10) |
30 | local code, par = get_status(sock, 220) | 34 | local code, par = get_status(sock, 220) |
@@ -48,7 +52,7 @@ function dict_define(sock, word, dict) | |||
48 | end | 52 | end |
49 | code, par = get_status(sock, 250) | 53 | code, par = get_status(sock, 250) |
50 | if code then return nil, code end | 54 | if code then return nil, code end |
51 | return gsub(defs, "%s%s$", "") | 55 | return string.gsub(defs, "%s%s$", "") |
52 | end | 56 | end |
53 | 57 | ||
54 | function dict_close(sock) | 58 | function dict_close(sock) |
@@ -65,3 +69,10 @@ function dict_get(word, dict) | |||
65 | dict_close(sock) | 69 | dict_close(sock) |
66 | return defs, err | 70 | return defs, err |
67 | end | 71 | end |
72 | |||
73 | if arg and arg[1] then | ||
74 | defs, err = dict_get(arg[1], arg[2]) | ||
75 | print(defs or err) | ||
76 | else | ||
77 | io.write("Usage:\n luasocket dict.lua <word> [<dictionary>]\n") | ||
78 | end | ||
diff --git a/etc/get.lua b/etc/get.lua index 33da653..af46c16 100644 --- a/etc/get.lua +++ b/etc/get.lua | |||
@@ -1,3 +1,7 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- Little program to download files from URLs | ||
3 | -- LuaSocket 1.5 sample files | ||
4 | ----------------------------------------------------------------------------- | ||
1 | -- formats a number of seconds into human readable form | 5 | -- formats a number of seconds into human readable form |
2 | function nicetime(s) | 6 | function nicetime(s) |
3 | local l = "s" | 7 | local l = "s" |
@@ -63,15 +67,15 @@ function receive2disk(file, size) | |||
63 | size = size | 67 | size = size |
64 | } | 68 | } |
65 | local receive_cb = function(chunk, err) | 69 | local receive_cb = function(chunk, err) |
66 | local dt = socket._time() - %aux.start -- elapsed time since start | 70 | local dt = socket._time() - aux.start -- elapsed time since start |
67 | if not chunk or chunk == "" then | 71 | if not chunk or chunk == "" then |
68 | io.write("\n") | 72 | io.write("\n") |
69 | aux.file:close() | 73 | aux.file:close() |
70 | return | 74 | return |
71 | end | 75 | end |
72 | aux.file:write(chunk) | 76 | aux.file:write(chunk) |
73 | aux.got = aux.got + string.len(chunk) -- total bytes received | 77 | aux.got = aux.got + string.len(chunk) -- total bytes received |
74 | if dt < 0.1 then return 1 end -- not enough time for estimate | 78 | if dt < 0.1 then return 1 end -- not enough time for estimate |
75 | io.write("\r", gauge(aux.got, dt, aux.size)) | 79 | io.write("\r", gauge(aux.got, dt, aux.size)) |
76 | return 1 | 80 | return 1 |
77 | end | 81 | end |
@@ -122,7 +126,7 @@ function getschemeandname(url, name) | |||
122 | return parsed.scheme, name | 126 | return parsed.scheme, name |
123 | end | 127 | end |
124 | 128 | ||
125 | -- gets a file either by http or url, saving as name | 129 | -- gets a file either by http or ftp, saving as <name> |
126 | function get(url, name) | 130 | function get(url, name) |
127 | local scheme | 131 | local scheme |
128 | scheme, name = getschemeandname(url, name) | 132 | scheme, name = getschemeandname(url, name) |
diff --git a/samples/daytimeclnt.lua b/samples/daytimeclnt.lua index 1107c6a..000dfd5 100644 --- a/samples/daytimeclnt.lua +++ b/samples/daytimeclnt.lua | |||
@@ -4,11 +4,11 @@ if arg then | |||
4 | host = arg[1] or host | 4 | host = arg[1] or host |
5 | port = arg[2] or port | 5 | port = arg[2] or port |
6 | end | 6 | end |
7 | host = toip(host) | 7 | host = socket.toip(host) |
8 | udp = udpsocket() | 8 | udp = socket.udp() |
9 | print("Using host '" ..host.. "' and port " ..port.. "...") | 9 | print("Using host '" ..host.. "' and port " ..port.. "...") |
10 | err = udp:sendto("anything", host, port) | 10 | err = udp:sendto("anything", host, port) |
11 | if err then print(err) exit() end | 11 | if err then print(err) exit() end |
12 | dgram, err = udp:receive() | 12 | dgram, err = udp:receive() |
13 | if not dgram then print(err) exit() end | 13 | if not dgram then print(err) exit() end |
14 | write(dgram) | 14 | io.write(dgram) |
diff --git a/samples/echoclnt.lua b/samples/echoclnt.lua index 043b2f0..cd8b450 100644 --- a/samples/echoclnt.lua +++ b/samples/echoclnt.lua | |||
@@ -4,18 +4,18 @@ if arg then | |||
4 | host = arg[1] or host | 4 | host = arg[1] or host |
5 | port = arg[2] or port | 5 | port = arg[2] or port |
6 | end | 6 | end |
7 | host = toip(host) | 7 | host = socket.toip(host) |
8 | udp, err = udpsocket() | 8 | udp, err = socket.udp() |
9 | if not udp then print(err) exit() end | 9 | if not udp then print(err) exit() end |
10 | err = udp:setpeername(host, port) | 10 | err = udp:setpeername(host, port) |
11 | if err then print(err) exit() end | 11 | if err then print(err) exit() end |
12 | print("Using host '" ..host.. "' and port " .. port .. "...") | 12 | print("Using host '" ..host.. "' and port " .. port .. "...") |
13 | while 1 do | 13 | while 1 do |
14 | line = read() | 14 | line = io.read() |
15 | if not line then exit() end | 15 | if not line then os.exit() end |
16 | err = udp:send(line) | 16 | err = udp:send(line) |
17 | if err then print(err) exit() end | 17 | if err then print(err) os.exit() end |
18 | dgram, err = udp:receive() | 18 | dgram, err = udp:receive() |
19 | if not dgram then print(err) exit() end | 19 | if not dgram then print(err) os.exit() end |
20 | print(dgram) | 20 | print(dgram) |
21 | end | 21 | end |
diff --git a/samples/echosrvr.lua b/samples/echosrvr.lua index 330f9e6..6117557 100644 --- a/samples/echosrvr.lua +++ b/samples/echosrvr.lua | |||
@@ -5,10 +5,10 @@ if arg then | |||
5 | port = arg[2] or port | 5 | port = arg[2] or port |
6 | end | 6 | end |
7 | print("Binding to host '" ..host.. "' and port " ..port.. "...") | 7 | print("Binding to host '" ..host.. "' and port " ..port.. "...") |
8 | udp, err = udpsocket() | 8 | udp, err = socket.udp() |
9 | if not udp then print(err) exit() end | 9 | if not udp then print(err) os.exit() end |
10 | err = udp:setsockname(host, port) | 10 | err = udp:setsockname(host, port) |
11 | if err then print(err) exit() end | 11 | if err then print(err) os.exit() end |
12 | udp:timeout(5) | 12 | udp:timeout(5) |
13 | ip, port = udp:getsockname() | 13 | ip, port = udp:getsockname() |
14 | print("Waiting packets on " .. ip .. ":" .. port .. "...") | 14 | print("Waiting packets on " .. ip .. ":" .. port .. "...") |
diff --git a/samples/listener.lua b/samples/listener.lua index 8e2c7ce..c035ab2 100644 --- a/samples/listener.lua +++ b/samples/listener.lua | |||
@@ -1,3 +1,7 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- Little program to dump lines received at a given port | ||
3 | -- LuaSocket 1.5 sample files | ||
4 | ----------------------------------------------------------------------------- | ||
1 | host = host or "*" | 5 | host = host or "*" |
2 | port = port or 8080 | 6 | port = port or 8080 |
3 | if arg then | 7 | if arg then |
@@ -5,7 +9,7 @@ if arg then | |||
5 | port = arg[2] or port | 9 | port = arg[2] or port |
6 | end | 10 | end |
7 | print("Binding to host '" ..host.. "' and port " ..port.. "...") | 11 | print("Binding to host '" ..host.. "' and port " ..port.. "...") |
8 | s, e = bind(host, port) | 12 | s, e = socket.bind(host, port) |
9 | if not s then | 13 | if not s then |
10 | print(e) | 14 | print(e) |
11 | exit() | 15 | exit() |
diff --git a/src/buffer.c b/src/buffer.c index 2938b52..73df8b3 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
@@ -3,6 +3,8 @@ | |||
3 | * Lua methods: | 3 | * Lua methods: |
4 | * send: unbuffered send using C base_send | 4 | * send: unbuffered send using C base_send |
5 | * receive: buffered read using C base_receive | 5 | * receive: buffered read using C base_receive |
6 | * | ||
7 | * RCS ID: $Id$ | ||
6 | \*=========================================================================*/ | 8 | \*=========================================================================*/ |
7 | #include <lua.h> | 9 | #include <lua.h> |
8 | #include <lauxlib.h> | 10 | #include <lauxlib.h> |
diff --git a/src/buffer.h b/src/buffer.h index 7463a67..4943e3b 100644 --- a/src/buffer.h +++ b/src/buffer.h | |||
@@ -1,5 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Buffered input/output routines | 2 | * Buffered input/output routines |
3 | * | ||
3 | * RCS ID: $Id$ | 4 | * RCS ID: $Id$ |
4 | \*=========================================================================*/ | 5 | \*=========================================================================*/ |
5 | #ifndef BUF_H_ | 6 | #ifndef BUF_H_ |
@@ -16,7 +17,7 @@ | |||
16 | \*-------------------------------------------------------------------------*/ | 17 | \*-------------------------------------------------------------------------*/ |
17 | typedef struct t_buf_tag { | 18 | typedef struct t_buf_tag { |
18 | size_t buf_first, buf_last; | 19 | size_t buf_first, buf_last; |
19 | uchar buf_data[BUF_SIZE]; | 20 | char buf_data[BUF_SIZE]; |
20 | p_base buf_base; | 21 | p_base buf_base; |
21 | } t_buf; | 22 | } t_buf; |
22 | typedef t_buf *p_buf; | 23 | typedef t_buf *p_buf; |
diff --git a/src/ftp.lua b/src/ftp.lua index f6fffbb..4017eb5 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- FTP support for the Lua language | 2 | -- FTP support for the Lua language |
3 | -- LuaSocket 1.5 toolkit. | 3 | -- LuaSocket 1.5 toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- Date: 26/12/2000 | ||
6 | -- Conforming to: RFC 959, LTN7 | 5 | -- Conforming to: RFC 959, LTN7 |
7 | -- RCS ID: $Id$ | 6 | -- RCS ID: $Id$ |
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
diff --git a/src/http.lua b/src/http.lua index 3275e3b..59645ee 100644 --- a/src/http.lua +++ b/src/http.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- HTTP/1.1 client support for the Lua language. | 2 | -- HTTP/1.1 client support for the Lua language. |
3 | -- LuaSocket 1.5 toolkit. | 3 | -- LuaSocket 1.5 toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- Date: 26/12/2000 | ||
6 | -- Conforming to: RFC 2616, LTN7 | 5 | -- Conforming to: RFC 2616, LTN7 |
7 | -- RCS ID: $Id$ | 6 | -- RCS ID: $Id$ |
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
@@ -1,11 +1,14 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Internet domain class | 2 | * Internet domain class: inherits from the Socket class, and implement |
3 | * a few methods shared by all internet related objects | ||
3 | * Lua methods: | 4 | * Lua methods: |
4 | * getpeername: gets socket peer ip address and port | 5 | * getpeername: gets socket peer ip address and port |
5 | * getsockname: gets local socket ip address and port | 6 | * getsockname: gets local socket ip address and port |
6 | * Global Lua fuctions: | 7 | * Global Lua fuctions: |
7 | * toip: gets resolver info on host name | 8 | * toip: gets resolver info on host name |
8 | * tohostname: gets resolver info on dotted-quad | 9 | * tohostname: gets resolver info on dotted-quad |
10 | * | ||
11 | * RCS ID: $Id$ | ||
9 | \*=========================================================================*/ | 12 | \*=========================================================================*/ |
10 | #include <string.h> | 13 | #include <string.h> |
11 | 14 | ||
@@ -145,7 +148,7 @@ static int inet_lua_getpeername(lua_State *L) | |||
145 | { | 148 | { |
146 | p_sock sock = (p_sock) lua_touserdata(L, 1); | 149 | p_sock sock = (p_sock) lua_touserdata(L, 1); |
147 | struct sockaddr_in peer; | 150 | struct sockaddr_in peer; |
148 | int peer_len = sizeof(peer); | 151 | size_t peer_len = sizeof(peer); |
149 | if (getpeername(sock->fd, (SA *) &peer, &peer_len) < 0) { | 152 | if (getpeername(sock->fd, (SA *) &peer, &peer_len) < 0) { |
150 | lua_pushnil(L); | 153 | lua_pushnil(L); |
151 | return 1; | 154 | return 1; |
@@ -167,7 +170,7 @@ static int inet_lua_getsockname(lua_State *L) | |||
167 | { | 170 | { |
168 | p_sock sock = (p_sock) lua_touserdata(L, 1); | 171 | p_sock sock = (p_sock) lua_touserdata(L, 1); |
169 | struct sockaddr_in local; | 172 | struct sockaddr_in local; |
170 | int local_len = sizeof(local); | 173 | size_t local_len = sizeof(local); |
171 | if (getsockname(sock->fd, (SA *) &local, &local_len) < 0) { | 174 | if (getsockname(sock->fd, (SA *) &local, &local_len) < 0) { |
172 | lua_pushnil(L); | 175 | lua_pushnil(L); |
173 | return 1; | 176 | return 1; |
@@ -1,5 +1,7 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Internet domain class | 2 | * Internet domain class: inherits from the Socket class, and implement |
3 | * a few methods shared by all internet related objects | ||
4 | * | ||
3 | * RCS ID: $Id$ | 5 | * RCS ID: $Id$ |
4 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
5 | #ifndef INET_H_ | 7 | #ifndef INET_H_ |
diff --git a/src/luasocket.c b/src/luasocket.c index f6d1df7..358b25e 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
@@ -63,6 +63,13 @@ LUASOCKET_API int lua_socketlibopen(lua_State *L) | |||
63 | lua_dofile(L, "http.lua"); | 63 | lua_dofile(L, "http.lua"); |
64 | lua_dofile(L, "smtp.lua"); | 64 | lua_dofile(L, "smtp.lua"); |
65 | lua_dofile(L, "ftp.lua"); | 65 | lua_dofile(L, "ftp.lua"); |
66 | #else | ||
67 | #include "concat.loh" | ||
68 | #include "code.loh" | ||
69 | #include "url.loh" | ||
70 | #include "http.loh" | ||
71 | #include "smtp.loh" | ||
72 | #include "ftp.loh" | ||
66 | #endif | 73 | #endif |
67 | return 0; | 74 | return 0; |
68 | } | 75 | } |
diff --git a/src/select.c b/src/select.c index 4dcfd26..6afdb87 100644 --- a/src/select.c +++ b/src/select.c | |||
@@ -1,6 +1,13 @@ | |||
1 | /*=========================================================================*\ | ||
2 | * Select implementation | ||
3 | * Global Lua fuctions: | ||
4 | * select: waits until socket ready | ||
5 | * RCS ID: $Id$ | ||
6 | \*=========================================================================*/ | ||
1 | #include <lua.h> | 7 | #include <lua.h> |
2 | #include <lauxlib.h> | 8 | #include <lauxlib.h> |
3 | 9 | ||
10 | #include "luasocket.h" | ||
4 | #include "lspriv.h" | 11 | #include "lspriv.h" |
5 | #include "lsselect.h" | 12 | #include "lsselect.h" |
6 | #include "lsfd.h" | 13 | #include "lsfd.h" |
@@ -33,10 +40,17 @@ void select_open(lua_State *L) | |||
33 | { | 40 | { |
34 | /* push select auxiliar lua function and register | 41 | /* push select auxiliar lua function and register |
35 | * select_lua_select with it as an upvalue */ | 42 | * select_lua_select with it as an upvalue */ |
36 | luaL_loadfile(L, "lsselect.lua"); | 43 | #ifdef LUASOCKET_DEBUG |
37 | lua_call(L, 0, 1); | 44 | lua_dofile(L, "lsselect.lua"); |
45 | #else | ||
46 | #include "lsselect.loh" | ||
47 | #endif | ||
48 | lua_getglobal(L, LUASOCKET_LIBNAME); | ||
49 | lua_pushstring(L, "_select"); | ||
50 | lua_gettable(L, -2); | ||
38 | lua_pushcclosure(L, select_lua_select, 1); | 51 | lua_pushcclosure(L, select_lua_select, 1); |
39 | priv_newglobal(L, "select"); | 52 | priv_newglobal(L, "select"); |
53 | lua_pop(L, 1); | ||
40 | /* create luasocket(select) table */ | 54 | /* create luasocket(select) table */ |
41 | lua_pushstring(L, "luasocket(select)"); | 55 | lua_pushstring(L, "luasocket(select)"); |
42 | lua_newtable(L); | 56 | lua_newtable(L); |
diff --git a/src/select.h b/src/select.h index c3267ad..2b2ed19 100644 --- a/src/select.h +++ b/src/select.h | |||
@@ -1,3 +1,7 @@ | |||
1 | /*=========================================================================*\ | ||
2 | * Select implementation | ||
3 | * RCS ID: $Id$ | ||
4 | \*=========================================================================*/ | ||
1 | #ifndef SLCT_H_ | 5 | #ifndef SLCT_H_ |
2 | #define SLCT_H_ | 6 | #define SLCT_H_ |
3 | 7 | ||
diff --git a/src/smtp.lua b/src/smtp.lua index 5da9a6f..0ba2b0f 100644 --- a/src/smtp.lua +++ b/src/smtp.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- SMTP support for the Lua language. | 2 | -- SMTP support for the Lua language. |
3 | -- LuaSocket 1.5 toolkit | 3 | -- LuaSocket 1.5 toolkit |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- Date: 26/12/2000 | ||
6 | -- Conforming to: RFC 821, LTN7 | 5 | -- Conforming to: RFC 821, LTN7 |
7 | -- RCS ID: $Id$ | 6 | -- RCS ID: $Id$ |
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
diff --git a/src/socket.h b/src/socket.h index c9dee20..9972639 100644 --- a/src/socket.h +++ b/src/socket.h | |||
@@ -1,3 +1,9 @@ | |||
1 | /*=========================================================================*\ | ||
2 | * Socket class: inherits from the File Descriptor class and is here just | ||
3 | * for extensibility in the future | ||
4 | * | ||
5 | * RCS ID: $id$ | ||
6 | \*=========================================================================*/ | ||
1 | #ifndef SOCK_H_ | 7 | #ifndef SOCK_H_ |
2 | #define SOCK_H_ | 8 | #define SOCK_H_ |
3 | 9 | ||
diff --git a/src/timeout.c b/src/timeout.c index 50a84da..5549c89 100644 --- a/src/timeout.c +++ b/src/timeout.c | |||
@@ -1,5 +1,10 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Timeout management functions | 2 | * Timeout management functions |
3 | * Global Lua functions: | ||
4 | * _sleep: (debug mode only) | ||
5 | * _time: (debug mode only) | ||
6 | * | ||
7 | * RCS ID: $Id$ | ||
3 | \*=========================================================================*/ | 8 | \*=========================================================================*/ |
4 | #include <lua.h> | 9 | #include <lua.h> |
5 | #include <lauxlib.h> | 10 | #include <lauxlib.h> |
@@ -20,10 +25,8 @@ | |||
20 | /*=========================================================================*\ | 25 | /*=========================================================================*\ |
21 | * Internal function prototypes | 26 | * Internal function prototypes |
22 | \*=========================================================================*/ | 27 | \*=========================================================================*/ |
23 | #ifdef LUASOCKET_DEBUG | ||
24 | static int tm_lua_time(lua_State *L); | 28 | static int tm_lua_time(lua_State *L); |
25 | static int tm_lua_sleep(lua_State *L); | 29 | static int tm_lua_sleep(lua_State *L); |
26 | #endif | ||
27 | 30 | ||
28 | /*=========================================================================*\ | 31 | /*=========================================================================*\ |
29 | * Exported functions. | 32 | * Exported functions. |
@@ -123,12 +126,10 @@ int tm_gettime(void) | |||
123 | void tm_open(lua_State *L) | 126 | void tm_open(lua_State *L) |
124 | { | 127 | { |
125 | (void) L; | 128 | (void) L; |
126 | #ifdef LUASOCKET_DEBUG | ||
127 | lua_pushcfunction(L, tm_lua_time); | 129 | lua_pushcfunction(L, tm_lua_time); |
128 | priv_newglobal(L, "_time"); | 130 | priv_newglobal(L, "_time"); |
129 | lua_pushcfunction(L, tm_lua_sleep); | 131 | lua_pushcfunction(L, tm_lua_sleep); |
130 | priv_newglobal(L, "_sleep"); | 132 | priv_newglobal(L, "_sleep"); |
131 | #endif | ||
132 | } | 133 | } |
133 | 134 | ||
134 | /*=========================================================================*\ | 135 | /*=========================================================================*\ |
@@ -137,7 +138,6 @@ void tm_open(lua_State *L) | |||
137 | /*-------------------------------------------------------------------------*\ | 138 | /*-------------------------------------------------------------------------*\ |
138 | * Returns the time the system has been up, in secconds. | 139 | * Returns the time the system has been up, in secconds. |
139 | \*-------------------------------------------------------------------------*/ | 140 | \*-------------------------------------------------------------------------*/ |
140 | #ifdef LUASOCKET_DEBUG | ||
141 | static int tm_lua_time(lua_State *L) | 141 | static int tm_lua_time(lua_State *L) |
142 | { | 142 | { |
143 | lua_pushnumber(L, tm_gettime()/1000.0); | 143 | lua_pushnumber(L, tm_gettime()/1000.0); |
@@ -157,4 +157,3 @@ int tm_lua_sleep(lua_State *L) | |||
157 | #endif | 157 | #endif |
158 | return 0; | 158 | return 0; |
159 | } | 159 | } |
160 | #endif | ||
diff --git a/src/timeout.h b/src/timeout.h index af7e591..1dc0a5a 100644 --- a/src/timeout.h +++ b/src/timeout.h | |||
@@ -1,3 +1,8 @@ | |||
1 | /*=========================================================================*\ | ||
2 | * Timeout management functions | ||
3 | * | ||
4 | * RCS ID: $Id$ | ||
5 | \*=========================================================================*/ | ||
1 | #ifndef _TM_H | 6 | #ifndef _TM_H |
2 | #define _TM_H | 7 | #define _TM_H |
3 | 8 | ||
@@ -1,5 +1,17 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * UDP socket object implementation (inherits from sock and inet) | 2 | * UDP class: inherits from Socked and Internet domain classes and provides |
3 | * all the functionality for UDP objects. | ||
4 | * Lua methods: | ||
5 | * send: using compat module | ||
6 | * sendto: using compat module | ||
7 | * receive: using compat module | ||
8 | * receivefrom: using compat module | ||
9 | * setpeername: using internet module | ||
10 | * setsockname: using internet module | ||
11 | * Global Lua functions: | ||
12 | * udp: creates the udp object | ||
13 | * | ||
14 | * RCS ID: $Id$ | ||
3 | \*=========================================================================*/ | 15 | \*=========================================================================*/ |
4 | #include <string.h> | 16 | #include <string.h> |
5 | 17 | ||
@@ -21,7 +33,7 @@ static int udp_lua_receivefrom(lua_State *L); | |||
21 | static int udp_lua_setpeername(lua_State *L); | 33 | static int udp_lua_setpeername(lua_State *L); |
22 | static int udp_lua_setsockname(lua_State *L); | 34 | static int udp_lua_setsockname(lua_State *L); |
23 | 35 | ||
24 | static int udp_global_udpsocket(lua_State *L); | 36 | static int udp_global_udp(lua_State *L); |
25 | 37 | ||
26 | static struct luaL_reg funcs[] = { | 38 | static struct luaL_reg funcs[] = { |
27 | {"send", udp_lua_send}, | 39 | {"send", udp_lua_send}, |
@@ -44,7 +56,7 @@ void udp_open(lua_State *L) | |||
44 | priv_newclass(L, UDP_CLASS); | 56 | priv_newclass(L, UDP_CLASS); |
45 | udp_inherit(L, UDP_CLASS); | 57 | udp_inherit(L, UDP_CLASS); |
46 | /* declare global functions */ | 58 | /* declare global functions */ |
47 | lua_pushcfunction(L, udp_global_udpsocket); | 59 | lua_pushcfunction(L, udp_global_udp); |
48 | priv_newglobal(L, "udp"); | 60 | priv_newglobal(L, "udp"); |
49 | for (i = 0; i < sizeof(funcs)/sizeof(funcs[0]); i++) | 61 | for (i = 0; i < sizeof(funcs)/sizeof(funcs[0]); i++) |
50 | priv_newglobalmethod(L, funcs[i].name); | 62 | priv_newglobalmethod(L, funcs[i].name); |
@@ -99,7 +111,7 @@ p_udp udp_push(lua_State *L) | |||
99 | * On success: udp socket | 111 | * On success: udp socket |
100 | * On error: nil, followed by an error message | 112 | * On error: nil, followed by an error message |
101 | \*-------------------------------------------------------------------------*/ | 113 | \*-------------------------------------------------------------------------*/ |
102 | static int udp_global_udpsocket(lua_State *L) | 114 | static int udp_global_udp(lua_State *L) |
103 | { | 115 | { |
104 | int oldtop = lua_gettop(L); | 116 | int oldtop = lua_gettop(L); |
105 | p_udp udp = udp_push(L); | 117 | p_udp udp = udp_push(L); |
@@ -134,7 +146,7 @@ static int udp_global_udpsocket(lua_State *L) | |||
134 | static int udp_lua_receive(lua_State *L) | 146 | static int udp_lua_receive(lua_State *L) |
135 | { | 147 | { |
136 | p_udp udp = (p_udp) lua_touserdata(L, 1); | 148 | p_udp udp = (p_udp) lua_touserdata(L, 1); |
137 | unsigned char buffer[UDP_DATAGRAMSIZE]; | 149 | char buffer[UDP_DATAGRAMSIZE]; |
138 | size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); | 150 | size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); |
139 | int err; | 151 | int err; |
140 | p_tm tm = &udp->base_tm; | 152 | p_tm tm = &udp->base_tm; |
@@ -162,8 +174,8 @@ static int udp_lua_receivefrom(lua_State *L) | |||
162 | p_udp udp = (p_udp) lua_touserdata(L, 1); | 174 | p_udp udp = (p_udp) lua_touserdata(L, 1); |
163 | p_tm tm = &udp->base_tm; | 175 | p_tm tm = &udp->base_tm; |
164 | struct sockaddr_in peer; | 176 | struct sockaddr_in peer; |
165 | int peer_len = sizeof(peer); | 177 | size_t peer_len = sizeof(peer); |
166 | unsigned char buffer[UDP_DATAGRAMSIZE]; | 178 | char buffer[UDP_DATAGRAMSIZE]; |
167 | size_t wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); | 179 | size_t wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); |
168 | size_t got; | 180 | size_t got; |
169 | int err; | 181 | int err; |
@@ -1,3 +1,9 @@ | |||
1 | /*=========================================================================*\ | ||
2 | * UDP class: inherits from Socked and Internet domain classes and provides | ||
3 | * all the functionality for UDP objects. | ||
4 | * | ||
5 | * RCS ID: $Id$ | ||
6 | \*=========================================================================*/ | ||
1 | #ifndef UDP_H_ | 7 | #ifndef UDP_H_ |
2 | #define UDP_H_ | 8 | #define UDP_H_ |
3 | 9 | ||
@@ -1,8 +1,11 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Network compatibilization module | 2 | * Network compatibilization module: Unix version |
3 | * | ||
4 | * RCS ID: $Id$ | ||
3 | \*=========================================================================*/ | 5 | \*=========================================================================*/ |
4 | #include <lua.h> | 6 | #include <lua.h> |
5 | #include <lauxlib.h> | 7 | #include <lauxlib.h> |
8 | #include <string.h> | ||
6 | 9 | ||
7 | #include "lscompat.h" | 10 | #include "lscompat.h" |
8 | 11 | ||
@@ -26,7 +29,7 @@ int compat_open(lua_State *L) | |||
26 | } | 29 | } |
27 | 30 | ||
28 | COMPAT_FD compat_accept(COMPAT_FD s, struct sockaddr *addr, | 31 | COMPAT_FD compat_accept(COMPAT_FD s, struct sockaddr *addr, |
29 | int *len, int deadline) | 32 | size_t *len, int deadline) |
30 | { | 33 | { |
31 | struct timeval tv; | 34 | struct timeval tv; |
32 | fd_set fds; | 35 | fd_set fds; |
@@ -72,7 +75,7 @@ int compat_send(COMPAT_FD c, cchar *data, size_t count, size_t *sent, | |||
72 | } | 75 | } |
73 | 76 | ||
74 | int compat_sendto(COMPAT_FD c, cchar *data, size_t count, size_t *sent, | 77 | int compat_sendto(COMPAT_FD c, cchar *data, size_t count, size_t *sent, |
75 | int deadline, SA *addr, int len) | 78 | int deadline, SA *addr, size_t len) |
76 | { | 79 | { |
77 | struct timeval tv; | 80 | struct timeval tv; |
78 | fd_set fds; | 81 | fd_set fds; |
@@ -104,7 +107,7 @@ int compat_sendto(COMPAT_FD c, cchar *data, size_t count, size_t *sent, | |||
104 | } | 107 | } |
105 | } | 108 | } |
106 | 109 | ||
107 | int compat_recv(COMPAT_FD c, uchar *data, size_t count, size_t *got, | 110 | int compat_recv(COMPAT_FD c, char *data, size_t count, size_t *got, |
108 | int deadline) | 111 | int deadline) |
109 | { | 112 | { |
110 | struct timeval tv; | 113 | struct timeval tv; |
@@ -131,8 +134,8 @@ int compat_recv(COMPAT_FD c, uchar *data, size_t count, size_t *got, | |||
131 | } | 134 | } |
132 | } | 135 | } |
133 | 136 | ||
134 | int compat_recvfrom(COMPAT_FD c, uchar *data, size_t count, size_t *got, | 137 | int compat_recvfrom(COMPAT_FD c, char *data, size_t count, size_t *got, |
135 | int deadline, SA *addr, int *len) | 138 | int deadline, SA *addr, size_t *len) |
136 | { | 139 | { |
137 | struct timeval tv; | 140 | struct timeval tv; |
138 | fd_set fds; | 141 | fd_set fds; |
@@ -1,3 +1,8 @@ | |||
1 | /*=========================================================================*\ | ||
2 | * Network compatibilization module: Unix version | ||
3 | * | ||
4 | * RCS ID: $Id$ | ||
5 | \*=========================================================================*/ | ||
1 | #ifndef UNIX_H_ | 6 | #ifndef UNIX_H_ |
2 | #define UNIX_H_ | 7 | #define UNIX_H_ |
3 | 8 | ||
diff --git a/src/url.lua b/src/url.lua index 2cf9669..06de9d3 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- URI parsing, composition and relative URL resolution | 2 | -- URI parsing, composition and relative URL resolution |
3 | -- LuaSocket 1.5 toolkit. | 3 | -- LuaSocket 1.5 toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- Date: 20/7/2001 | ||
6 | -- Conforming to: RFC 2396, LTN7 | 5 | -- Conforming to: RFC 2396, LTN7 |
7 | -- RCS ID: $Id$ | 6 | -- RCS ID: $Id$ |
8 | ---------------------------------------------------------------------------- | 7 | ---------------------------------------------------------------------------- |
diff --git a/test/smtptest.lua b/test/smtptest.lua index 1bba27f..27ba400 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua | |||
@@ -60,7 +60,7 @@ local empty = function() | |||
60 | end | 60 | end |
61 | 61 | ||
62 | local get = function() | 62 | local get = function() |
63 | s = "" | 63 | local s = "" |
64 | for i,v in ipairs(files) do | 64 | for i,v in ipairs(files) do |
65 | s = s .. "\n" .. readfile(v) | 65 | s = s .. "\n" .. readfile(v) |
66 | end | 66 | end |
diff --git a/test/testclnt.lua b/test/testclnt.lua index 7c65823..3e80a36 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | HOST = HOST or "localhost" | 1 | host = host or "localhost" |
2 | PORT = PORT or "8080" | 2 | port = port or "8080" |
3 | 3 | ||
4 | function pass(...) | 4 | function pass(...) |
5 | local s = string.format(unpack(arg)) | 5 | local s = string.format(unpack(arg)) |
@@ -83,14 +83,14 @@ function tcpreconnect() | |||
83 | if data then data:close() data = nil end | 83 | if data then data:close() data = nil end |
84 | data = server:accept() | 84 | data = server:accept() |
85 | ]] | 85 | ]] |
86 | data, err = socket.connect(HOST, PORT) | 86 | data, err = socket.connect(host, port) |
87 | if not data then fail(err) | 87 | if not data then fail(err) |
88 | else pass("connected!") end | 88 | else pass("connected!") end |
89 | end | 89 | end |
90 | reconnect = tcpreconnect | 90 | reconnect = tcpreconnect |
91 | 91 | ||
92 | pass("attempting control connection...") | 92 | pass("attempting control connection...") |
93 | control, err = socket.connect(HOST, PORT) | 93 | control, err = socket.connect(host, port) |
94 | if err then fail(err) | 94 | if err then fail(err) |
95 | else pass("connected!") end | 95 | else pass("connected!") end |
96 | 96 | ||
@@ -104,10 +104,10 @@ function empty_connect() | |||
104 | if data then data:close() data = nil end | 104 | if data then data:close() data = nil end |
105 | data = server:accept() | 105 | data = server:accept() |
106 | ]] | 106 | ]] |
107 | data, err = socket.connect("", PORT) | 107 | data, err = socket.connect("", port) |
108 | if not data then | 108 | if not data then |
109 | pass("ok") | 109 | pass("ok") |
110 | data = socket.connect(HOST, PORT) | 110 | data = socket.connect(host, port) |
111 | else fail("should not have connected!") end | 111 | else fail("should not have connected!") end |
112 | end | 112 | end |
113 | 113 | ||
diff --git a/test/testsrvr.lua b/test/testsrvr.lua index 141c058..fb77ea5 100644 --- a/test/testsrvr.lua +++ b/test/testsrvr.lua | |||
@@ -1,7 +1,7 @@ | |||
1 | HOST = HOST or "localhost" | 1 | host = host or "localhost" |
2 | PORT = PORT or "8080" | 2 | port = port or "8080" |
3 | 3 | ||
4 | server, error = socket.bind(HOST, PORT) | 4 | server, error = socket.bind(host, port) |
5 | if not server then print("server: " .. tostring(error)) os.exit() end | 5 | if not server then print("server: " .. tostring(error)) os.exit() end |
6 | while 1 do | 6 | while 1 do |
7 | print("server: waiting for client connection..."); | 7 | print("server: waiting for client connection..."); |
diff --git a/test/tftptest.lua b/test/tftptest.lua index b29657a..a435ad4 100644 --- a/test/tftptest.lua +++ b/test/tftptest.lua | |||
@@ -1,25 +1,23 @@ | |||
1 | -- load tftpclng.lua | 1 | -- load tftpclnt.lua |
2 | assert(dofile("../examples/tftpclnt.lua")) | 2 | dofile("tftpclnt.lua") |
3 | 3 | ||
4 | -- needs tftp server running on localhost, with root pointing to | 4 | -- needs tftp server running on localhost, with root pointing to |
5 | -- /home/i/diego/public/html/luasocket/test | 5 | -- a directory with index.html in it |
6 | 6 | ||
7 | function readfile(file) | 7 | function readfile(file) |
8 | local f = openfile("file", "rb") | 8 | local f = io.open(file, "r") |
9 | local a | 9 | if not f then return nil end |
10 | if f then | 10 | local a = f:read("*a") |
11 | a = read(f, "*a") | 11 | f:close() |
12 | closefile(f) | 12 | return a |
13 | end | ||
14 | return a | ||
15 | end | 13 | end |
16 | 14 | ||
17 | host = host or "localhost" | 15 | host = host or "localhost" |
18 | print("downloading") | 16 | print("downloading") |
19 | err = tftp_get(host, 69, "index.html", "index.got") | 17 | err = tftp_get(host, 69, "index.html", "index.got") |
20 | assert(not err, err) | 18 | assert(not err, err) |
21 | original = readfile("index.index") | 19 | original = readfile("test/index.html") |
22 | retrieved = readfile("index.got") | 20 | retrieved = readfile("index.got") |
23 | remove("index.got") | 21 | os.remove("index.got") |
24 | assert(original == retrieved, "files differ!") | 22 | assert(original == retrieved, "files differ!") |
25 | print("passed") | 23 | print("passed") |
diff --git a/test/urltest.lua b/test/urltest.lua index b97844d..7b1f0c0 100644 --- a/test/urltest.lua +++ b/test/urltest.lua | |||
@@ -1,5 +1,4 @@ | |||
1 | 1 | dofile("noglobals.lua") | |
2 | |||
3 | 2 | ||
4 | local check_build_url = function(parsed) | 3 | local check_build_url = function(parsed) |
5 | local built = socket.url.build(parsed) | 4 | local built = socket.url.build(parsed) |