aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2003-03-28 21:08:50 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2003-03-28 21:08:50 +0000
commitf18d1b7cd0ec4708518ab5e18ea33b6eadca0301 (patch)
treee831c6b1957af47db1301675b52c0d2a2e315fa7 /src
parent307603b24dde69eac62d2cb52123488137520c9c (diff)
downloadluasocket-f18d1b7cd0ec4708518ab5e18ea33b6eadca0301.tar.gz
luasocket-f18d1b7cd0ec4708518ab5e18ea33b6eadca0301.tar.bz2
luasocket-f18d1b7cd0ec4708518ab5e18ea33b6eadca0301.zip
Closer to release...
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c2
-rw-r--r--src/buffer.h3
-rw-r--r--src/ftp.lua1
-rw-r--r--src/http.lua1
-rw-r--r--src/inet.c9
-rw-r--r--src/inet.h4
-rw-r--r--src/luasocket.c7
-rw-r--r--src/select.c18
-rw-r--r--src/select.h4
-rw-r--r--src/smtp.lua1
-rw-r--r--src/socket.h6
-rw-r--r--src/timeout.c11
-rw-r--r--src/timeout.h5
-rw-r--r--src/udp.c26
-rw-r--r--src/udp.h6
-rw-r--r--src/unix.c15
-rw-r--r--src/unix.h5
-rw-r--r--src/url.lua1
18 files changed, 95 insertions, 30 deletions
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\*-------------------------------------------------------------------------*/
17typedef struct t_buf_tag { 18typedef 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;
22typedef t_buf *p_buf; 23typedef 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-----------------------------------------------------------------------------
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 @@
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;
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 @@
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
24static int tm_lua_time(lua_State *L); 28static int tm_lua_time(lua_State *L);
25static int tm_lua_sleep(lua_State *L); 29static 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)
123void tm_open(lua_State *L) 126void 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
141static int tm_lua_time(lua_State *L) 141static 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
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 @@
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);
21static int udp_lua_setpeername(lua_State *L); 33static int udp_lua_setpeername(lua_State *L);
22static int udp_lua_setsockname(lua_State *L); 34static int udp_lua_setsockname(lua_State *L);
23 35
24static int udp_global_udpsocket(lua_State *L); 36static int udp_global_udp(lua_State *L);
25 37
26static struct luaL_reg funcs[] = { 38static 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\*-------------------------------------------------------------------------*/
102static int udp_global_udpsocket(lua_State *L) 114static 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)
134static int udp_lua_receive(lua_State *L) 146static 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;
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 @@
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
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 @@
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
28COMPAT_FD compat_accept(COMPAT_FD s, struct sockaddr *addr, 31COMPAT_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
74int compat_sendto(COMPAT_FD c, cchar *data, size_t count, size_t *sent, 77int 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
107int compat_recv(COMPAT_FD c, uchar *data, size_t count, size_t *got, 110int 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
134int compat_recvfrom(COMPAT_FD c, uchar *data, size_t count, size_t *got, 137int 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;
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 @@
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----------------------------------------------------------------------------