From f18d1b7cd0ec4708518ab5e18ea33b6eadca0301 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 28 Mar 2003 21:08:50 +0000 Subject: [PATCH] Closer to release... --- TODO | 1 + etc/check-links.lua | 8 ++++++-- etc/dict.lua | 19 +++++++++++++++---- etc/get.lua | 12 ++++++++---- samples/daytimeclnt.lua | 6 +++--- samples/echoclnt.lua | 12 ++++++------ samples/echosrvr.lua | 6 +++--- samples/listener.lua | 6 +++++- src/buffer.c | 2 ++ src/buffer.h | 3 ++- src/ftp.lua | 1 - src/http.lua | 1 - src/inet.c | 9 ++++++--- src/inet.h | 4 +++- src/luasocket.c | 7 +++++++ src/select.c | 18 ++++++++++++++++-- src/select.h | 4 ++++ src/smtp.lua | 1 - src/socket.h | 6 ++++++ src/timeout.c | 11 +++++------ src/timeout.h | 5 +++++ src/udp.c | 26 +++++++++++++++++++------- src/udp.h | 6 ++++++ src/unix.c | 15 +++++++++------ src/unix.h | 5 +++++ src/url.lua | 1 - test/smtptest.lua | 2 +- test/testclnt.lua | 12 ++++++------ test/testsrvr.lua | 6 +++--- test/tftptest.lua | 22 ++++++++++------------ test/urltest.lua | 3 +-- 31 files changed, 163 insertions(+), 77 deletions(-) diff --git a/TODO b/TODO index 50031b1..25d2586 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,5 @@ - Inicializaccao das classes pode falhar? +- Ajeitar melhor a hierarquia de classes. Ajeitar o file... * Como mostrar um erro em lua_socketlibopen()... * 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 @@ +----------------------------------------------------------------------------- +-- Little program that checks links in HTML files +-- LuaSocket 1.5 sample files. +----------------------------------------------------------------------------- socket.http.TIMEOUT = 10 cache = {} @@ -14,7 +18,7 @@ end function getstatus(url) local parsed = socket.url.parse(url, { scheme = "file" }) - if cache[url] then return cache[url].res end + if cache[url] then return cache[url] end local res if parsed.scheme == "http" then local request = { url = url } @@ -34,7 +38,7 @@ function getstatus(url) res = nil else res = error end else res = string.format("unhandled scheme '%s'", parsed.scheme) end - cache[url] = { res = res } + cache[url] = res return res end 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 @@ +----------------------------------------------------------------------------- +-- Little program to download DICT word definitions +-- LuaSocket 1.5 sample files +----------------------------------------------------------------------------- function get_status(sock, valid) local line, err = sock:receive() local code, par if not line then sock:close() return err end - _, _, code = strfind(line, "^(%d%d%d)") + _, _, code = string.find(line, "^(%d%d%d)") code = tonumber(code) if code ~= valid then return code end if code == 150 then - _,_,_, par = strfind(line, "^(%d%d%d) (%d*)") + _,_,_, par = string.find(line, "^(%d%d%d) (%d*)") par = tonumber(par) end return nil, par @@ -24,7 +28,7 @@ function get_def(sock) end function dict_open() - local sock, err = connect("dict.org", 2628) + local sock, err = socket.connect("dict.org", 2628) if not sock then return nil, err end sock:timeout(10) local code, par = get_status(sock, 220) @@ -48,7 +52,7 @@ function dict_define(sock, word, dict) end code, par = get_status(sock, 250) if code then return nil, code end - return gsub(defs, "%s%s$", "") + return string.gsub(defs, "%s%s$", "") end function dict_close(sock) @@ -65,3 +69,10 @@ function dict_get(word, dict) dict_close(sock) return defs, err end + +if arg and arg[1] then + defs, err = dict_get(arg[1], arg[2]) + print(defs or err) +else + io.write("Usage:\n luasocket dict.lua []\n") +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 @@ +----------------------------------------------------------------------------- +-- Little program to download files from URLs +-- LuaSocket 1.5 sample files +----------------------------------------------------------------------------- -- formats a number of seconds into human readable form function nicetime(s) local l = "s" @@ -63,15 +67,15 @@ function receive2disk(file, size) size = size } local receive_cb = function(chunk, err) - local dt = socket._time() - %aux.start -- elapsed time since start + local dt = socket._time() - aux.start -- elapsed time since start if not chunk or chunk == "" then io.write("\n") aux.file:close() return end aux.file:write(chunk) - aux.got = aux.got + string.len(chunk) -- total bytes received - if dt < 0.1 then return 1 end -- not enough time for estimate + aux.got = aux.got + string.len(chunk) -- total bytes received + if dt < 0.1 then return 1 end -- not enough time for estimate io.write("\r", gauge(aux.got, dt, aux.size)) return 1 end @@ -122,7 +126,7 @@ function getschemeandname(url, name) return parsed.scheme, name end --- gets a file either by http or url, saving as name +-- gets a file either by http or ftp, saving as function get(url, name) local scheme 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 host = arg[1] or host port = arg[2] or port end -host = toip(host) -udp = udpsocket() +host = socket.toip(host) +udp = socket.udp() print("Using host '" ..host.. "' and port " ..port.. "...") err = udp:sendto("anything", host, port) if err then print(err) exit() end dgram, err = udp:receive() if not dgram then print(err) exit() end -write(dgram) +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 host = arg[1] or host port = arg[2] or port end -host = toip(host) -udp, err = udpsocket() +host = socket.toip(host) +udp, err = socket.udp() if not udp then print(err) exit() end err = udp:setpeername(host, port) if err then print(err) exit() end print("Using host '" ..host.. "' and port " .. port .. "...") while 1 do - line = read() - if not line then exit() end + line = io.read() + if not line then os.exit() end err = udp:send(line) - if err then print(err) exit() end + if err then print(err) os.exit() end dgram, err = udp:receive() - if not dgram then print(err) exit() end + if not dgram then print(err) os.exit() end print(dgram) 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 port = arg[2] or port end print("Binding to host '" ..host.. "' and port " ..port.. "...") -udp, err = udpsocket() -if not udp then print(err) exit() end +udp, err = socket.udp() +if not udp then print(err) os.exit() end err = udp:setsockname(host, port) -if err then print(err) exit() end +if err then print(err) os.exit() end udp:timeout(5) ip, port = udp:getsockname() 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 @@ +----------------------------------------------------------------------------- +-- Little program to dump lines received at a given port +-- LuaSocket 1.5 sample files +----------------------------------------------------------------------------- host = host or "*" port = port or 8080 if arg then @@ -5,7 +9,7 @@ if arg then port = arg[2] or port end print("Binding to host '" ..host.. "' and port " ..port.. "...") -s, e = bind(host, port) +s, e = socket.bind(host, port) if not s then print(e) 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 @@ * Lua methods: * send: unbuffered send using C base_send * receive: buffered read using C base_receive +* +* RCS ID: $Id$ \*=========================================================================*/ #include #include 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 @@ /*=========================================================================*\ * Buffered input/output routines +* * RCS ID: $Id$ \*=========================================================================*/ #ifndef BUF_H_ @@ -16,7 +17,7 @@ \*-------------------------------------------------------------------------*/ typedef struct t_buf_tag { size_t buf_first, buf_last; - uchar buf_data[BUF_SIZE]; + char buf_data[BUF_SIZE]; p_base buf_base; } t_buf; 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 @@ -- FTP support for the Lua language -- LuaSocket 1.5 toolkit. -- Author: Diego Nehab --- Date: 26/12/2000 -- Conforming to: RFC 959, LTN7 -- RCS ID: $Id$ ----------------------------------------------------------------------------- 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 @@ -- HTTP/1.1 client support for the Lua language. -- LuaSocket 1.5 toolkit. -- Author: Diego Nehab --- Date: 26/12/2000 -- Conforming to: RFC 2616, LTN7 -- RCS ID: $Id$ ----------------------------------------------------------------------------- diff --git a/src/inet.c b/src/inet.c index eb4124b..341c60e 100644 --- a/src/inet.c +++ b/src/inet.c @@ -1,11 +1,14 @@ /*=========================================================================*\ -* Internet domain class +* Internet domain class: inherits from the Socket class, and implement +* a few methods shared by all internet related objects * Lua methods: * getpeername: gets socket peer ip address and port * getsockname: gets local socket ip address and port * Global Lua fuctions: * toip: gets resolver info on host name * tohostname: gets resolver info on dotted-quad +* +* RCS ID: $Id$ \*=========================================================================*/ #include @@ -145,7 +148,7 @@ static int inet_lua_getpeername(lua_State *L) { p_sock sock = (p_sock) lua_touserdata(L, 1); struct sockaddr_in peer; - int peer_len = sizeof(peer); + size_t peer_len = sizeof(peer); if (getpeername(sock->fd, (SA *) &peer, &peer_len) < 0) { lua_pushnil(L); return 1; @@ -167,7 +170,7 @@ static int inet_lua_getsockname(lua_State *L) { p_sock sock = (p_sock) lua_touserdata(L, 1); struct sockaddr_in local; - int local_len = sizeof(local); + size_t local_len = sizeof(local); if (getsockname(sock->fd, (SA *) &local, &local_len) < 0) { lua_pushnil(L); return 1; diff --git a/src/inet.h b/src/inet.h index 3b0453e..93fcedf 100644 --- a/src/inet.h +++ b/src/inet.h @@ -1,5 +1,7 @@ /*=========================================================================*\ -* Internet domain class +* Internet domain class: inherits from the Socket class, and implement +* a few methods shared by all internet related objects +* * RCS ID: $Id$ \*=========================================================================*/ #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) lua_dofile(L, "http.lua"); lua_dofile(L, "smtp.lua"); lua_dofile(L, "ftp.lua"); +#else +#include "concat.loh" +#include "code.loh" +#include "url.loh" +#include "http.loh" +#include "smtp.loh" +#include "ftp.loh" #endif return 0; } 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 @@ +/*=========================================================================*\ +* Select implementation +* Global Lua fuctions: +* select: waits until socket ready +* RCS ID: $Id$ +\*=========================================================================*/ #include #include +#include "luasocket.h" #include "lspriv.h" #include "lsselect.h" #include "lsfd.h" @@ -33,10 +40,17 @@ void select_open(lua_State *L) { /* push select auxiliar lua function and register * select_lua_select with it as an upvalue */ - luaL_loadfile(L, "lsselect.lua"); - lua_call(L, 0, 1); +#ifdef LUASOCKET_DEBUG + lua_dofile(L, "lsselect.lua"); +#else +#include "lsselect.loh" +#endif + lua_getglobal(L, LUASOCKET_LIBNAME); + lua_pushstring(L, "_select"); + lua_gettable(L, -2); lua_pushcclosure(L, select_lua_select, 1); priv_newglobal(L, "select"); + lua_pop(L, 1); /* create luasocket(select) table */ lua_pushstring(L, "luasocket(select)"); 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 @@ +/*=========================================================================*\ +* Select implementation +* RCS ID: $Id$ +\*=========================================================================*/ #ifndef SLCT_H_ #define SLCT_H_ 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 @@ -- SMTP support for the Lua language. -- LuaSocket 1.5 toolkit -- Author: Diego Nehab --- Date: 26/12/2000 -- Conforming to: RFC 821, LTN7 -- RCS ID: $Id$ ----------------------------------------------------------------------------- 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 @@ +/*=========================================================================*\ +* Socket class: inherits from the File Descriptor class and is here just +* for extensibility in the future +* +* RCS ID: $id$ +\*=========================================================================*/ #ifndef SOCK_H_ #define SOCK_H_ 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 @@ /*=========================================================================*\ * Timeout management functions +* Global Lua functions: +* _sleep: (debug mode only) +* _time: (debug mode only) +* +* RCS ID: $Id$ \*=========================================================================*/ #include #include @@ -20,10 +25,8 @@ /*=========================================================================*\ * Internal function prototypes \*=========================================================================*/ -#ifdef LUASOCKET_DEBUG static int tm_lua_time(lua_State *L); static int tm_lua_sleep(lua_State *L); -#endif /*=========================================================================*\ * Exported functions. @@ -123,12 +126,10 @@ int tm_gettime(void) void tm_open(lua_State *L) { (void) L; -#ifdef LUASOCKET_DEBUG lua_pushcfunction(L, tm_lua_time); priv_newglobal(L, "_time"); lua_pushcfunction(L, tm_lua_sleep); priv_newglobal(L, "_sleep"); -#endif } /*=========================================================================*\ @@ -137,7 +138,6 @@ void tm_open(lua_State *L) /*-------------------------------------------------------------------------*\ * Returns the time the system has been up, in secconds. \*-------------------------------------------------------------------------*/ -#ifdef LUASOCKET_DEBUG static int tm_lua_time(lua_State *L) { lua_pushnumber(L, tm_gettime()/1000.0); @@ -157,4 +157,3 @@ int tm_lua_sleep(lua_State *L) #endif return 0; } -#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 @@ +/*=========================================================================*\ +* Timeout management functions +* +* RCS ID: $Id$ +\*=========================================================================*/ #ifndef _TM_H #define _TM_H diff --git a/src/udp.c b/src/udp.c index fd569c6..361816c 100644 --- a/src/udp.c +++ b/src/udp.c @@ -1,5 +1,17 @@ /*=========================================================================*\ -* UDP socket object implementation (inherits from sock and inet) +* UDP class: inherits from Socked and Internet domain classes and provides +* all the functionality for UDP objects. +* Lua methods: +* send: using compat module +* sendto: using compat module +* receive: using compat module +* receivefrom: using compat module +* setpeername: using internet module +* setsockname: using internet module +* Global Lua functions: +* udp: creates the udp object +* +* RCS ID: $Id$ \*=========================================================================*/ #include @@ -21,7 +33,7 @@ static int udp_lua_receivefrom(lua_State *L); static int udp_lua_setpeername(lua_State *L); static int udp_lua_setsockname(lua_State *L); -static int udp_global_udpsocket(lua_State *L); +static int udp_global_udp(lua_State *L); static struct luaL_reg funcs[] = { {"send", udp_lua_send}, @@ -44,7 +56,7 @@ void udp_open(lua_State *L) priv_newclass(L, UDP_CLASS); udp_inherit(L, UDP_CLASS); /* declare global functions */ - lua_pushcfunction(L, udp_global_udpsocket); + lua_pushcfunction(L, udp_global_udp); priv_newglobal(L, "udp"); for (i = 0; i < sizeof(funcs)/sizeof(funcs[0]); i++) priv_newglobalmethod(L, funcs[i].name); @@ -99,7 +111,7 @@ p_udp udp_push(lua_State *L) * On success: udp socket * On error: nil, followed by an error message \*-------------------------------------------------------------------------*/ -static int udp_global_udpsocket(lua_State *L) +static int udp_global_udp(lua_State *L) { int oldtop = lua_gettop(L); p_udp udp = udp_push(L); @@ -134,7 +146,7 @@ static int udp_global_udpsocket(lua_State *L) static int udp_lua_receive(lua_State *L) { p_udp udp = (p_udp) lua_touserdata(L, 1); - unsigned char buffer[UDP_DATAGRAMSIZE]; + char buffer[UDP_DATAGRAMSIZE]; size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); int err; p_tm tm = &udp->base_tm; @@ -162,8 +174,8 @@ static int udp_lua_receivefrom(lua_State *L) p_udp udp = (p_udp) lua_touserdata(L, 1); p_tm tm = &udp->base_tm; struct sockaddr_in peer; - int peer_len = sizeof(peer); - unsigned char buffer[UDP_DATAGRAMSIZE]; + size_t peer_len = sizeof(peer); + char buffer[UDP_DATAGRAMSIZE]; size_t wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); size_t got; int err; diff --git a/src/udp.h b/src/udp.h index 3c82c29..928a99f 100644 --- a/src/udp.h +++ b/src/udp.h @@ -1,3 +1,9 @@ +/*=========================================================================*\ +* UDP class: inherits from Socked and Internet domain classes and provides +* all the functionality for UDP objects. +* +* RCS ID: $Id$ +\*=========================================================================*/ #ifndef UDP_H_ #define UDP_H_ diff --git a/src/unix.c b/src/unix.c index 511a6bb..23984b0 100644 --- a/src/unix.c +++ b/src/unix.c @@ -1,8 +1,11 @@ /*=========================================================================*\ -* Network compatibilization module +* Network compatibilization module: Unix version +* +* RCS ID: $Id$ \*=========================================================================*/ #include #include +#include #include "lscompat.h" @@ -26,7 +29,7 @@ int compat_open(lua_State *L) } COMPAT_FD compat_accept(COMPAT_FD s, struct sockaddr *addr, - int *len, int deadline) + size_t *len, int deadline) { struct timeval tv; fd_set fds; @@ -72,7 +75,7 @@ int compat_send(COMPAT_FD c, cchar *data, size_t count, size_t *sent, } int compat_sendto(COMPAT_FD c, cchar *data, size_t count, size_t *sent, - int deadline, SA *addr, int len) + int deadline, SA *addr, size_t len) { struct timeval tv; fd_set fds; @@ -104,7 +107,7 @@ int compat_sendto(COMPAT_FD c, cchar *data, size_t count, size_t *sent, } } -int compat_recv(COMPAT_FD c, uchar *data, size_t count, size_t *got, +int compat_recv(COMPAT_FD c, char *data, size_t count, size_t *got, int deadline) { struct timeval tv; @@ -131,8 +134,8 @@ int compat_recv(COMPAT_FD c, uchar *data, size_t count, size_t *got, } } -int compat_recvfrom(COMPAT_FD c, uchar *data, size_t count, size_t *got, - int deadline, SA *addr, int *len) +int compat_recvfrom(COMPAT_FD c, char *data, size_t count, size_t *got, + int deadline, SA *addr, size_t *len) { struct timeval tv; fd_set fds; diff --git a/src/unix.h b/src/unix.h index 5f89569..863e478 100644 --- a/src/unix.h +++ b/src/unix.h @@ -1,3 +1,8 @@ +/*=========================================================================*\ +* Network compatibilization module: Unix version +* +* RCS ID: $Id$ +\*=========================================================================*/ #ifndef UNIX_H_ #define UNIX_H_ 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 @@ -- URI parsing, composition and relative URL resolution -- LuaSocket 1.5 toolkit. -- Author: Diego Nehab --- Date: 20/7/2001 -- Conforming to: RFC 2396, LTN7 -- RCS ID: $Id$ ---------------------------------------------------------------------------- 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() end local get = function() - s = "" + local s = "" for i,v in ipairs(files) do s = s .. "\n" .. readfile(v) 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 @@ -HOST = HOST or "localhost" -PORT = PORT or "8080" +host = host or "localhost" +port = port or "8080" function pass(...) local s = string.format(unpack(arg)) @@ -83,14 +83,14 @@ function tcpreconnect() if data then data:close() data = nil end data = server:accept() ]] - data, err = socket.connect(HOST, PORT) + data, err = socket.connect(host, port) if not data then fail(err) else pass("connected!") end end reconnect = tcpreconnect pass("attempting control connection...") -control, err = socket.connect(HOST, PORT) +control, err = socket.connect(host, port) if err then fail(err) else pass("connected!") end @@ -104,10 +104,10 @@ function empty_connect() if data then data:close() data = nil end data = server:accept() ]] - data, err = socket.connect("", PORT) + data, err = socket.connect("", port) if not data then pass("ok") - data = socket.connect(HOST, PORT) + data = socket.connect(host, port) else fail("should not have connected!") end end 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 @@ -HOST = HOST or "localhost" -PORT = PORT or "8080" +host = host or "localhost" +port = port or "8080" -server, error = socket.bind(HOST, PORT) +server, error = socket.bind(host, port) if not server then print("server: " .. tostring(error)) os.exit() end while 1 do 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 @@ --- load tftpclng.lua -assert(dofile("../examples/tftpclnt.lua")) +-- load tftpclnt.lua +dofile("tftpclnt.lua") -- needs tftp server running on localhost, with root pointing to --- /home/i/diego/public/html/luasocket/test +-- a directory with index.html in it function readfile(file) - local f = openfile("file", "rb") - local a - if f then - a = read(f, "*a") - closefile(f) - end - return a + local f = io.open(file, "r") + if not f then return nil end + local a = f:read("*a") + f:close() + return a end host = host or "localhost" print("downloading") err = tftp_get(host, 69, "index.html", "index.got") assert(not err, err) -original = readfile("index.index") +original = readfile("test/index.html") retrieved = readfile("index.got") -remove("index.got") +os.remove("index.got") assert(original == retrieved, "files differ!") 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 @@ - - +dofile("noglobals.lua") local check_build_url = function(parsed) local built = socket.url.build(parsed)