aboutsummaryrefslogtreecommitdiff
path: root/src/udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/udp.c')
-rw-r--r--src/udp.c26
1 files changed, 19 insertions, 7 deletions
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;