From f18d1b7cd0ec4708518ab5e18ea33b6eadca0301 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 28 Mar 2003 21:08:50 +0000 Subject: Closer to release... --- 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 - 18 files changed, 95 insertions(+), 30 deletions(-) (limited to 'src') 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$ ---------------------------------------------------------------------------- -- cgit v1.2.3-55-g6feb