Closer to release...
This commit is contained in:
parent
307603b24d
commit
f18d1b7cd0
31 changed files with 163 additions and 77 deletions
|
@ -3,6 +3,8 @@
|
|||
* Lua methods:
|
||||
* send: unbuffered send using C base_send
|
||||
* receive: buffered read using C base_receive
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include <lauxlib.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;
|
||||
|
|
|
@ -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$
|
||||
-----------------------------------------------------------------------------
|
||||
|
|
|
@ -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$
|
||||
-----------------------------------------------------------------------------
|
||||
|
|
|
@ -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 <string.h>
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
18
src/select.c
18
src/select.c
|
@ -1,6 +1,13 @@
|
|||
/*=========================================================================*\
|
||||
* Select implementation
|
||||
* Global Lua fuctions:
|
||||
* select: waits until socket ready
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
#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);
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*=========================================================================*\
|
||||
* Select implementation
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#ifndef SLCT_H_
|
||||
#define SLCT_H_
|
||||
|
||||
|
|
|
@ -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$
|
||||
-----------------------------------------------------------------------------
|
||||
|
|
|
@ -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_
|
||||
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
/*=========================================================================*\
|
||||
* Timeout management functions
|
||||
* Global Lua functions:
|
||||
* _sleep: (debug mode only)
|
||||
* _time: (debug mode only)
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
|
@ -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
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*=========================================================================*\
|
||||
* Timeout management functions
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#ifndef _TM_H
|
||||
#define _TM_H
|
||||
|
||||
|
|
26
src/udp.c
26
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 <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_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;
|
||||
|
|
|
@ -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_
|
||||
|
||||
|
|
15
src/unix.c
15
src/unix.c
|
@ -1,8 +1,11 @@
|
|||
/*=========================================================================*\
|
||||
* Network compatibilization module
|
||||
* Network compatibilization module: Unix version
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*=========================================================================*\
|
||||
* Network compatibilization module: Unix version
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#ifndef UNIX_H_
|
||||
#define UNIX_H_
|
||||
|
||||
|
|
|
@ -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$
|
||||
----------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue