aboutsummaryrefslogtreecommitdiff
path: root/src/unix.c
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2005-02-08 10:01:01 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2005-02-08 10:01:01 +0000
commit8d4e240f6ae50d9b22ddc44f5e207018935da907 (patch)
treed8ca9a51dc35534592f700e42740feac20242ede /src/unix.c
parent5d32848674b723521e87836eafa24f5ae8f80a89 (diff)
downloadluasocket-8d4e240f6ae50d9b22ddc44f5e207018935da907.tar.gz
luasocket-8d4e240f6ae50d9b22ddc44f5e207018935da907.tar.bz2
luasocket-8d4e240f6ae50d9b22ddc44f5e207018935da907.zip
Forward server working on Mac OS X...
Diffstat (limited to 'src/unix.c')
-rw-r--r--src/unix.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/unix.c b/src/unix.c
index 1e0e252..c169268 100644
--- a/src/unix.c
+++ b/src/unix.c
@@ -32,6 +32,8 @@ static int meth_settimeout(lua_State *L);
32static int meth_getfd(lua_State *L); 32static int meth_getfd(lua_State *L);
33static int meth_setfd(lua_State *L); 33static int meth_setfd(lua_State *L);
34static int meth_dirty(lua_State *L); 34static int meth_dirty(lua_State *L);
35static int meth_getstats(lua_State *L);
36static int meth_setstats(lua_State *L);
35 37
36static const char *unix_tryconnect(p_unix un, const char *path); 38static const char *unix_tryconnect(p_unix un, const char *path);
37static const char *unix_trybind(p_unix un, const char *path); 39static const char *unix_trybind(p_unix un, const char *path);
@@ -46,6 +48,8 @@ static luaL_reg un[] = {
46 {"connect", meth_connect}, 48 {"connect", meth_connect},
47 {"dirty", meth_dirty}, 49 {"dirty", meth_dirty},
48 {"getfd", meth_getfd}, 50 {"getfd", meth_getfd},
51 {"getstats", meth_getstats},
52 {"setstats", meth_setstats},
49 {"listen", meth_listen}, 53 {"listen", meth_listen},
50 {"receive", meth_receive}, 54 {"receive", meth_receive},
51 {"send", meth_send}, 55 {"send", meth_send},
@@ -75,7 +79,7 @@ static luaL_reg func[] = {
75/*-------------------------------------------------------------------------*\ 79/*-------------------------------------------------------------------------*\
76* Initializes module 80* Initializes module
77\*-------------------------------------------------------------------------*/ 81\*-------------------------------------------------------------------------*/
78int unix_open(lua_State *L) { 82int luaopen_socketunix(lua_State *L) {
79 /* create classes */ 83 /* create classes */
80 aux_newclass(L, "unix{master}", un); 84 aux_newclass(L, "unix{master}", un);
81 aux_newclass(L, "unix{client}", un); 85 aux_newclass(L, "unix{client}", un);
@@ -84,11 +88,9 @@ int unix_open(lua_State *L) {
84 aux_add2group(L, "unix{master}", "unix{any}"); 88 aux_add2group(L, "unix{master}", "unix{any}");
85 aux_add2group(L, "unix{client}", "unix{any}"); 89 aux_add2group(L, "unix{client}", "unix{any}");
86 aux_add2group(L, "unix{server}", "unix{any}"); 90 aux_add2group(L, "unix{server}", "unix{any}");
87 aux_add2group(L, "unix{client}", "unix{client,server}");
88 aux_add2group(L, "unix{server}", "unix{client,server}");
89 /* define library functions */ 91 /* define library functions */
90 luaL_openlib(L, NULL, func, 0); 92 luaL_openlib(L, "socket", func, 0);
91 return 0; 93 return 1;
92} 94}
93 95
94/*=========================================================================*\ 96/*=========================================================================*\
@@ -107,6 +109,16 @@ static int meth_receive(lua_State *L) {
107 return buf_meth_receive(L, &un->buf); 109 return buf_meth_receive(L, &un->buf);
108} 110}
109 111
112static int meth_getstats(lua_State *L) {
113 p_unix un = (p_unix) aux_checkclass(L, "unix{client}", 1);
114 return buf_meth_getstats(L, &un->buf);
115}
116
117static int meth_setstats(lua_State *L) {
118 p_unix un = (p_unix) aux_checkclass(L, "unix{client}", 1);
119 return buf_meth_setstats(L, &un->buf);
120}
121
110/*-------------------------------------------------------------------------*\ 122/*-------------------------------------------------------------------------*\
111* Just call option handler 123* Just call option handler
112\*-------------------------------------------------------------------------*/ 124\*-------------------------------------------------------------------------*/
@@ -250,7 +262,8 @@ static int meth_close(lua_State *L)
250{ 262{
251 p_unix un = (p_unix) aux_checkgroup(L, "unix{any}", 1); 263 p_unix un = (p_unix) aux_checkgroup(L, "unix{any}", 1);
252 sock_destroy(&un->sock); 264 sock_destroy(&un->sock);
253 return 0; 265 lua_pushnumber(L, 1);
266 return 1;
254} 267}
255 268
256/*-------------------------------------------------------------------------*\ 269/*-------------------------------------------------------------------------*\
@@ -277,7 +290,7 @@ static int meth_listen(lua_State *L)
277\*-------------------------------------------------------------------------*/ 290\*-------------------------------------------------------------------------*/
278static int meth_shutdown(lua_State *L) 291static int meth_shutdown(lua_State *L)
279{ 292{
280 p_unix un = (p_unix) aux_checkgroup(L, "unix{client}", 1); 293 p_unix un = (p_unix) aux_checkclass(L, "unix{client}", 1);
281 const char *how = luaL_optstring(L, 2, "both"); 294 const char *how = luaL_optstring(L, 2, "both");
282 switch (how[0]) { 295 switch (how[0]) {
283 case 'b': 296 case 'b':