Closer to release...

This commit is contained in:
Diego Nehab 2003-03-28 21:08:50 +00:00
parent 307603b24d
commit f18d1b7cd0
31 changed files with 163 additions and 77 deletions

1
TODO
View File

@ -1,4 +1,5 @@
- Inicializaccao das classes pode falhar? - Inicializaccao das classes pode falhar?
- Ajeitar melhor a hierarquia de classes. Ajeitar o file...
* Como mostrar um erro em lua_socketlibopen()... * Como mostrar um erro em lua_socketlibopen()...
* O location do "redirect" pode ser relativo ao servidor atual (não pode, * O location do "redirect" pode ser relativo ao servidor atual (não pode,

View File

@ -1,3 +1,7 @@
-----------------------------------------------------------------------------
-- Little program that checks links in HTML files
-- LuaSocket 1.5 sample files.
-----------------------------------------------------------------------------
socket.http.TIMEOUT = 10 socket.http.TIMEOUT = 10
cache = {} cache = {}
@ -14,7 +18,7 @@ end
function getstatus(url) function getstatus(url)
local parsed = socket.url.parse(url, { scheme = "file" }) 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 local res
if parsed.scheme == "http" then if parsed.scheme == "http" then
local request = { url = url } local request = { url = url }
@ -34,7 +38,7 @@ function getstatus(url)
res = nil res = nil
else res = error end else res = error end
else res = string.format("unhandled scheme '%s'", parsed.scheme) end else res = string.format("unhandled scheme '%s'", parsed.scheme) end
cache[url] = { res = res } cache[url] = res
return res return res
end end

View File

@ -1,12 +1,16 @@
-----------------------------------------------------------------------------
-- Little program to download DICT word definitions
-- LuaSocket 1.5 sample files
-----------------------------------------------------------------------------
function get_status(sock, valid) function get_status(sock, valid)
local line, err = sock:receive() local line, err = sock:receive()
local code, par local code, par
if not line then sock:close() return err end 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) code = tonumber(code)
if code ~= valid then return code end if code ~= valid then return code end
if code == 150 then if code == 150 then
_,_,_, par = strfind(line, "^(%d%d%d) (%d*)") _,_,_, par = string.find(line, "^(%d%d%d) (%d*)")
par = tonumber(par) par = tonumber(par)
end end
return nil, par return nil, par
@ -24,7 +28,7 @@ function get_def(sock)
end end
function dict_open() 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 if not sock then return nil, err end
sock:timeout(10) sock:timeout(10)
local code, par = get_status(sock, 220) local code, par = get_status(sock, 220)
@ -48,7 +52,7 @@ function dict_define(sock, word, dict)
end end
code, par = get_status(sock, 250) code, par = get_status(sock, 250)
if code then return nil, code end if code then return nil, code end
return gsub(defs, "%s%s$", "") return string.gsub(defs, "%s%s$", "")
end end
function dict_close(sock) function dict_close(sock)
@ -65,3 +69,10 @@ function dict_get(word, dict)
dict_close(sock) dict_close(sock)
return defs, err return defs, err
end 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 <word> [<dictionary>]\n")
end

View File

@ -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 -- formats a number of seconds into human readable form
function nicetime(s) function nicetime(s)
local l = "s" local l = "s"
@ -63,15 +67,15 @@ function receive2disk(file, size)
size = size size = size
} }
local receive_cb = function(chunk, err) 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 if not chunk or chunk == "" then
io.write("\n") io.write("\n")
aux.file:close() aux.file:close()
return return
end end
aux.file:write(chunk) aux.file:write(chunk)
aux.got = aux.got + string.len(chunk) -- total bytes received aux.got = aux.got + string.len(chunk) -- total bytes received
if dt < 0.1 then return 1 end -- not enough time for estimate if dt < 0.1 then return 1 end -- not enough time for estimate
io.write("\r", gauge(aux.got, dt, aux.size)) io.write("\r", gauge(aux.got, dt, aux.size))
return 1 return 1
end end
@ -122,7 +126,7 @@ function getschemeandname(url, name)
return parsed.scheme, name return parsed.scheme, name
end end
-- gets a file either by http or url, saving as name -- gets a file either by http or ftp, saving as <name>
function get(url, name) function get(url, name)
local scheme local scheme
scheme, name = getschemeandname(url, name) scheme, name = getschemeandname(url, name)

View File

@ -4,11 +4,11 @@ if arg then
host = arg[1] or host host = arg[1] or host
port = arg[2] or port port = arg[2] or port
end end
host = toip(host) host = socket.toip(host)
udp = udpsocket() udp = socket.udp()
print("Using host '" ..host.. "' and port " ..port.. "...") print("Using host '" ..host.. "' and port " ..port.. "...")
err = udp:sendto("anything", host, port) err = udp:sendto("anything", host, port)
if err then print(err) exit() end if err then print(err) exit() end
dgram, err = udp:receive() dgram, err = udp:receive()
if not dgram then print(err) exit() end if not dgram then print(err) exit() end
write(dgram) io.write(dgram)

View File

@ -4,18 +4,18 @@ if arg then
host = arg[1] or host host = arg[1] or host
port = arg[2] or port port = arg[2] or port
end end
host = toip(host) host = socket.toip(host)
udp, err = udpsocket() udp, err = socket.udp()
if not udp then print(err) exit() end if not udp then print(err) exit() end
err = udp:setpeername(host, port) err = udp:setpeername(host, port)
if err then print(err) exit() end if err then print(err) exit() end
print("Using host '" ..host.. "' and port " .. port .. "...") print("Using host '" ..host.. "' and port " .. port .. "...")
while 1 do while 1 do
line = read() line = io.read()
if not line then exit() end if not line then os.exit() end
err = udp:send(line) err = udp:send(line)
if err then print(err) exit() end if err then print(err) os.exit() end
dgram, err = udp:receive() dgram, err = udp:receive()
if not dgram then print(err) exit() end if not dgram then print(err) os.exit() end
print(dgram) print(dgram)
end end

View File

@ -5,10 +5,10 @@ if arg then
port = arg[2] or port port = arg[2] or port
end end
print("Binding to host '" ..host.. "' and port " ..port.. "...") print("Binding to host '" ..host.. "' and port " ..port.. "...")
udp, err = udpsocket() udp, err = socket.udp()
if not udp then print(err) exit() end if not udp then print(err) os.exit() end
err = udp:setsockname(host, port) err = udp:setsockname(host, port)
if err then print(err) exit() end if err then print(err) os.exit() end
udp:timeout(5) udp:timeout(5)
ip, port = udp:getsockname() ip, port = udp:getsockname()
print("Waiting packets on " .. ip .. ":" .. port .. "...") print("Waiting packets on " .. ip .. ":" .. port .. "...")

View File

@ -1,3 +1,7 @@
-----------------------------------------------------------------------------
-- Little program to dump lines received at a given port
-- LuaSocket 1.5 sample files
-----------------------------------------------------------------------------
host = host or "*" host = host or "*"
port = port or 8080 port = port or 8080
if arg then if arg then
@ -5,7 +9,7 @@ if arg then
port = arg[2] or port port = arg[2] or port
end end
print("Binding to host '" ..host.. "' and port " ..port.. "...") print("Binding to host '" ..host.. "' and port " ..port.. "...")
s, e = bind(host, port) s, e = socket.bind(host, port)
if not s then if not s then
print(e) print(e)
exit() exit()

View File

@ -3,6 +3,8 @@
* Lua methods: * Lua methods:
* send: unbuffered send using C base_send * send: unbuffered send using C base_send
* receive: buffered read using C base_receive * receive: buffered read using C base_receive
*
* RCS ID: $Id$
\*=========================================================================*/ \*=========================================================================*/
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>

View File

@ -1,5 +1,6 @@
/*=========================================================================*\ /*=========================================================================*\
* Buffered input/output routines * Buffered input/output routines
*
* RCS ID: $Id$ * RCS ID: $Id$
\*=========================================================================*/ \*=========================================================================*/
#ifndef BUF_H_ #ifndef BUF_H_
@ -16,7 +17,7 @@
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
typedef struct t_buf_tag { typedef struct t_buf_tag {
size_t buf_first, buf_last; size_t buf_first, buf_last;
uchar buf_data[BUF_SIZE]; char buf_data[BUF_SIZE];
p_base buf_base; p_base buf_base;
} t_buf; } t_buf;
typedef t_buf *p_buf; typedef t_buf *p_buf;

View File

@ -2,7 +2,6 @@
-- FTP support for the Lua language -- FTP support for the Lua language
-- LuaSocket 1.5 toolkit. -- LuaSocket 1.5 toolkit.
-- Author: Diego Nehab -- Author: Diego Nehab
-- Date: 26/12/2000
-- Conforming to: RFC 959, LTN7 -- Conforming to: RFC 959, LTN7
-- RCS ID: $Id$ -- RCS ID: $Id$
----------------------------------------------------------------------------- -----------------------------------------------------------------------------

View File

@ -2,7 +2,6 @@
-- HTTP/1.1 client support for the Lua language. -- HTTP/1.1 client support for the Lua language.
-- LuaSocket 1.5 toolkit. -- LuaSocket 1.5 toolkit.
-- Author: Diego Nehab -- Author: Diego Nehab
-- Date: 26/12/2000
-- Conforming to: RFC 2616, LTN7 -- Conforming to: RFC 2616, LTN7
-- RCS ID: $Id$ -- RCS ID: $Id$
----------------------------------------------------------------------------- -----------------------------------------------------------------------------

View File

@ -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: * Lua methods:
* getpeername: gets socket peer ip address and port * getpeername: gets socket peer ip address and port
* getsockname: gets local socket ip address and port * getsockname: gets local socket ip address and port
* Global Lua fuctions: * Global Lua fuctions:
* toip: gets resolver info on host name * toip: gets resolver info on host name
* tohostname: gets resolver info on dotted-quad * tohostname: gets resolver info on dotted-quad
*
* RCS ID: $Id$
\*=========================================================================*/ \*=========================================================================*/
#include <string.h> #include <string.h>
@ -145,7 +148,7 @@ static int inet_lua_getpeername(lua_State *L)
{ {
p_sock sock = (p_sock) lua_touserdata(L, 1); p_sock sock = (p_sock) lua_touserdata(L, 1);
struct sockaddr_in peer; struct sockaddr_in peer;
int peer_len = sizeof(peer); size_t peer_len = sizeof(peer);
if (getpeername(sock->fd, (SA *) &peer, &peer_len) < 0) { if (getpeername(sock->fd, (SA *) &peer, &peer_len) < 0) {
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;
@ -167,7 +170,7 @@ static int inet_lua_getsockname(lua_State *L)
{ {
p_sock sock = (p_sock) lua_touserdata(L, 1); p_sock sock = (p_sock) lua_touserdata(L, 1);
struct sockaddr_in local; struct sockaddr_in local;
int local_len = sizeof(local); size_t local_len = sizeof(local);
if (getsockname(sock->fd, (SA *) &local, &local_len) < 0) { if (getsockname(sock->fd, (SA *) &local, &local_len) < 0) {
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;

View File

@ -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$ * RCS ID: $Id$
\*=========================================================================*/ \*=========================================================================*/
#ifndef INET_H_ #ifndef INET_H_

View File

@ -63,6 +63,13 @@ LUASOCKET_API int lua_socketlibopen(lua_State *L)
lua_dofile(L, "http.lua"); lua_dofile(L, "http.lua");
lua_dofile(L, "smtp.lua"); lua_dofile(L, "smtp.lua");
lua_dofile(L, "ftp.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 #endif
return 0; return 0;
} }

View File

@ -1,6 +1,13 @@
/*=========================================================================*\
* Select implementation
* Global Lua fuctions:
* select: waits until socket ready
* RCS ID: $Id$
\*=========================================================================*/
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
#include "luasocket.h"
#include "lspriv.h" #include "lspriv.h"
#include "lsselect.h" #include "lsselect.h"
#include "lsfd.h" #include "lsfd.h"
@ -33,10 +40,17 @@ void select_open(lua_State *L)
{ {
/* push select auxiliar lua function and register /* push select auxiliar lua function and register
* select_lua_select with it as an upvalue */ * select_lua_select with it as an upvalue */
luaL_loadfile(L, "lsselect.lua"); #ifdef LUASOCKET_DEBUG
lua_call(L, 0, 1); 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); lua_pushcclosure(L, select_lua_select, 1);
priv_newglobal(L, "select"); priv_newglobal(L, "select");
lua_pop(L, 1);
/* create luasocket(select) table */ /* create luasocket(select) table */
lua_pushstring(L, "luasocket(select)"); lua_pushstring(L, "luasocket(select)");
lua_newtable(L); lua_newtable(L);

View File

@ -1,3 +1,7 @@
/*=========================================================================*\
* Select implementation
* RCS ID: $Id$
\*=========================================================================*/
#ifndef SLCT_H_ #ifndef SLCT_H_
#define SLCT_H_ #define SLCT_H_

View File

@ -2,7 +2,6 @@
-- SMTP support for the Lua language. -- SMTP support for the Lua language.
-- LuaSocket 1.5 toolkit -- LuaSocket 1.5 toolkit
-- Author: Diego Nehab -- Author: Diego Nehab
-- Date: 26/12/2000
-- Conforming to: RFC 821, LTN7 -- Conforming to: RFC 821, LTN7
-- RCS ID: $Id$ -- RCS ID: $Id$
----------------------------------------------------------------------------- -----------------------------------------------------------------------------

View File

@ -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_ #ifndef SOCK_H_
#define SOCK_H_ #define SOCK_H_

View File

@ -1,5 +1,10 @@
/*=========================================================================*\ /*=========================================================================*\
* Timeout management functions * Timeout management functions
* Global Lua functions:
* _sleep: (debug mode only)
* _time: (debug mode only)
*
* RCS ID: $Id$
\*=========================================================================*/ \*=========================================================================*/
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
@ -20,10 +25,8 @@
/*=========================================================================*\ /*=========================================================================*\
* Internal function prototypes * Internal function prototypes
\*=========================================================================*/ \*=========================================================================*/
#ifdef LUASOCKET_DEBUG
static int tm_lua_time(lua_State *L); static int tm_lua_time(lua_State *L);
static int tm_lua_sleep(lua_State *L); static int tm_lua_sleep(lua_State *L);
#endif
/*=========================================================================*\ /*=========================================================================*\
* Exported functions. * Exported functions.
@ -123,12 +126,10 @@ int tm_gettime(void)
void tm_open(lua_State *L) void tm_open(lua_State *L)
{ {
(void) L; (void) L;
#ifdef LUASOCKET_DEBUG
lua_pushcfunction(L, tm_lua_time); lua_pushcfunction(L, tm_lua_time);
priv_newglobal(L, "_time"); priv_newglobal(L, "_time");
lua_pushcfunction(L, tm_lua_sleep); lua_pushcfunction(L, tm_lua_sleep);
priv_newglobal(L, "_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. * Returns the time the system has been up, in secconds.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
#ifdef LUASOCKET_DEBUG
static int tm_lua_time(lua_State *L) static int tm_lua_time(lua_State *L)
{ {
lua_pushnumber(L, tm_gettime()/1000.0); lua_pushnumber(L, tm_gettime()/1000.0);
@ -157,4 +157,3 @@ int tm_lua_sleep(lua_State *L)
#endif #endif
return 0; return 0;
} }
#endif

View File

@ -1,3 +1,8 @@
/*=========================================================================*\
* Timeout management functions
*
* RCS ID: $Id$
\*=========================================================================*/
#ifndef _TM_H #ifndef _TM_H
#define _TM_H #define _TM_H

View File

@ -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 <string.h> #include <string.h>
@ -21,7 +33,7 @@ static int udp_lua_receivefrom(lua_State *L);
static int udp_lua_setpeername(lua_State *L); static int udp_lua_setpeername(lua_State *L);
static int udp_lua_setsockname(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[] = { static struct luaL_reg funcs[] = {
{"send", udp_lua_send}, {"send", udp_lua_send},
@ -44,7 +56,7 @@ void udp_open(lua_State *L)
priv_newclass(L, UDP_CLASS); priv_newclass(L, UDP_CLASS);
udp_inherit(L, UDP_CLASS); udp_inherit(L, UDP_CLASS);
/* declare global functions */ /* declare global functions */
lua_pushcfunction(L, udp_global_udpsocket); lua_pushcfunction(L, udp_global_udp);
priv_newglobal(L, "udp"); priv_newglobal(L, "udp");
for (i = 0; i < sizeof(funcs)/sizeof(funcs[0]); i++) for (i = 0; i < sizeof(funcs)/sizeof(funcs[0]); i++)
priv_newglobalmethod(L, funcs[i].name); priv_newglobalmethod(L, funcs[i].name);
@ -99,7 +111,7 @@ p_udp udp_push(lua_State *L)
* On success: udp socket * On success: udp socket
* On error: nil, followed by an error message * 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); int oldtop = lua_gettop(L);
p_udp udp = udp_push(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) static int udp_lua_receive(lua_State *L)
{ {
p_udp udp = (p_udp) lua_touserdata(L, 1); 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)); size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer));
int err; int err;
p_tm tm = &udp->base_tm; 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_udp udp = (p_udp) lua_touserdata(L, 1);
p_tm tm = &udp->base_tm; p_tm tm = &udp->base_tm;
struct sockaddr_in peer; struct sockaddr_in peer;
int peer_len = sizeof(peer); size_t peer_len = sizeof(peer);
unsigned char buffer[UDP_DATAGRAMSIZE]; char buffer[UDP_DATAGRAMSIZE];
size_t wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); size_t wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer));
size_t got; size_t got;
int err; int err;

View File

@ -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_ #ifndef UDP_H_
#define UDP_H_ #define UDP_H_

View File

@ -1,8 +1,11 @@
/*=========================================================================*\ /*=========================================================================*\
* Network compatibilization module * Network compatibilization module: Unix version
*
* RCS ID: $Id$
\*=========================================================================*/ \*=========================================================================*/
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <string.h>
#include "lscompat.h" #include "lscompat.h"
@ -26,7 +29,7 @@ int compat_open(lua_State *L)
} }
COMPAT_FD compat_accept(COMPAT_FD s, struct sockaddr *addr, COMPAT_FD compat_accept(COMPAT_FD s, struct sockaddr *addr,
int *len, int deadline) size_t *len, int deadline)
{ {
struct timeval tv; struct timeval tv;
fd_set fds; 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 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; struct timeval tv;
fd_set fds; 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) int deadline)
{ {
struct timeval tv; 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 compat_recvfrom(COMPAT_FD c, char *data, size_t count, size_t *got,
int deadline, SA *addr, int *len) int deadline, SA *addr, size_t *len)
{ {
struct timeval tv; struct timeval tv;
fd_set fds; fd_set fds;

View File

@ -1,3 +1,8 @@
/*=========================================================================*\
* Network compatibilization module: Unix version
*
* RCS ID: $Id$
\*=========================================================================*/
#ifndef UNIX_H_ #ifndef UNIX_H_
#define UNIX_H_ #define UNIX_H_

View File

@ -2,7 +2,6 @@
-- URI parsing, composition and relative URL resolution -- URI parsing, composition and relative URL resolution
-- LuaSocket 1.5 toolkit. -- LuaSocket 1.5 toolkit.
-- Author: Diego Nehab -- Author: Diego Nehab
-- Date: 20/7/2001
-- Conforming to: RFC 2396, LTN7 -- Conforming to: RFC 2396, LTN7
-- RCS ID: $Id$ -- RCS ID: $Id$
---------------------------------------------------------------------------- ----------------------------------------------------------------------------

View File

@ -60,7 +60,7 @@ local empty = function()
end end
local get = function() local get = function()
s = "" local s = ""
for i,v in ipairs(files) do for i,v in ipairs(files) do
s = s .. "\n" .. readfile(v) s = s .. "\n" .. readfile(v)
end end

View File

@ -1,5 +1,5 @@
HOST = HOST or "localhost" host = host or "localhost"
PORT = PORT or "8080" port = port or "8080"
function pass(...) function pass(...)
local s = string.format(unpack(arg)) local s = string.format(unpack(arg))
@ -83,14 +83,14 @@ function tcpreconnect()
if data then data:close() data = nil end if data then data:close() data = nil end
data = server:accept() data = server:accept()
]] ]]
data, err = socket.connect(HOST, PORT) data, err = socket.connect(host, port)
if not data then fail(err) if not data then fail(err)
else pass("connected!") end else pass("connected!") end
end end
reconnect = tcpreconnect reconnect = tcpreconnect
pass("attempting control connection...") pass("attempting control connection...")
control, err = socket.connect(HOST, PORT) control, err = socket.connect(host, port)
if err then fail(err) if err then fail(err)
else pass("connected!") end else pass("connected!") end
@ -104,10 +104,10 @@ function empty_connect()
if data then data:close() data = nil end if data then data:close() data = nil end
data = server:accept() data = server:accept()
]] ]]
data, err = socket.connect("", PORT) data, err = socket.connect("", port)
if not data then if not data then
pass("ok") pass("ok")
data = socket.connect(HOST, PORT) data = socket.connect(host, port)
else fail("should not have connected!") end else fail("should not have connected!") end
end end

View File

@ -1,7 +1,7 @@
HOST = HOST or "localhost" host = host or "localhost"
PORT = PORT or "8080" 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 if not server then print("server: " .. tostring(error)) os.exit() end
while 1 do while 1 do
print("server: waiting for client connection..."); print("server: waiting for client connection...");

View File

@ -1,25 +1,23 @@
-- load tftpclng.lua -- load tftpclnt.lua
assert(dofile("../examples/tftpclnt.lua")) dofile("tftpclnt.lua")
-- needs tftp server running on localhost, with root pointing to -- 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) function readfile(file)
local f = openfile("file", "rb") local f = io.open(file, "r")
local a if not f then return nil end
if f then local a = f:read("*a")
a = read(f, "*a") f:close()
closefile(f) return a
end
return a
end end
host = host or "localhost" host = host or "localhost"
print("downloading") print("downloading")
err = tftp_get(host, 69, "index.html", "index.got") err = tftp_get(host, 69, "index.html", "index.got")
assert(not err, err) assert(not err, err)
original = readfile("index.index") original = readfile("test/index.html")
retrieved = readfile("index.got") retrieved = readfile("index.got")
remove("index.got") os.remove("index.got")
assert(original == retrieved, "files differ!") assert(original == retrieved, "files differ!")
print("passed") print("passed")

View File

@ -1,5 +1,4 @@
dofile("noglobals.lua")
local check_build_url = function(parsed) local check_build_url = function(parsed)
local built = socket.url.build(parsed) local built = socket.url.build(parsed)