diff options
-rw-r--r-- | src/makefile | 4 | ||||
-rw-r--r-- | src/unix.c | 8 | ||||
-rw-r--r-- | src/unixdgram.c (renamed from src/unixudp.c) | 96 | ||||
-rw-r--r-- | src/unixdgram.h (renamed from src/unixudp.h) | 14 | ||||
-rw-r--r-- | src/unixstream.c (renamed from src/unixtcp.c) | 84 | ||||
-rw-r--r-- | src/unixstream.h | 21 | ||||
-rw-r--r-- | src/unixtcp.h | 21 | ||||
-rw-r--r-- | test/unixdgramclnt.lua (renamed from test/unixudpclnt.lua) | 4 | ||||
-rw-r--r-- | test/unixdgramsrvr.lua (renamed from test/unixudpsrvr.lua) | 2 | ||||
-rw-r--r-- | test/unixstreamclnt.lua (renamed from test/unixtcpclnt.lua) | 2 | ||||
-rw-r--r-- | test/unixstreamsrvr.lua (renamed from test/unixtcpsrvr.lua) | 2 |
11 files changed, 129 insertions, 129 deletions
diff --git a/src/makefile b/src/makefile index 2dfe549..494baab 100644 --- a/src/makefile +++ b/src/makefile | |||
@@ -307,8 +307,8 @@ UNIX_OBJS=\ | |||
307 | timeout.$(O) \ | 307 | timeout.$(O) \ |
308 | io.$(O) \ | 308 | io.$(O) \ |
309 | usocket.$(O) \ | 309 | usocket.$(O) \ |
310 | unixtcp.$(O) \ | 310 | unixstream.$(O) \ |
311 | unixudp.$(O) \ | 311 | unixdgram.$(O) \ |
312 | compat.$(O) \ | 312 | compat.$(O) \ |
313 | unix.$(O) | 313 | unix.$(O) |
314 | 314 | ||
@@ -5,15 +5,15 @@ | |||
5 | #include "lua.h" | 5 | #include "lua.h" |
6 | #include "lauxlib.h" | 6 | #include "lauxlib.h" |
7 | 7 | ||
8 | #include "unixtcp.h" | 8 | #include "unixstream.h" |
9 | #include "unixudp.h" | 9 | #include "unixdgram.h" |
10 | 10 | ||
11 | /*-------------------------------------------------------------------------*\ | 11 | /*-------------------------------------------------------------------------*\ |
12 | * Modules and functions | 12 | * Modules and functions |
13 | \*-------------------------------------------------------------------------*/ | 13 | \*-------------------------------------------------------------------------*/ |
14 | static const luaL_Reg mod[] = { | 14 | static const luaL_Reg mod[] = { |
15 | {"tcp", unixtcp_open}, | 15 | {"stream", unixstream_open}, |
16 | {"udp", unixudp_open}, | 16 | {"dgram", unixdgram_open}, |
17 | {NULL, NULL} | 17 | {NULL, NULL} |
18 | }; | 18 | }; |
19 | 19 | ||
diff --git a/src/unixudp.c b/src/unixdgram.c index 0e0a19a..c07cbd5 100644 --- a/src/unixudp.c +++ b/src/unixdgram.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Unix domain socket udp submodule | 2 | * Unix domain socket dgram submodule |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
5 | #include <string.h> | 5 | #include <string.h> |
@@ -15,7 +15,7 @@ | |||
15 | #include "unix.h" | 15 | #include "unix.h" |
16 | #include <sys/un.h> | 16 | #include <sys/un.h> |
17 | 17 | ||
18 | #define UNIXUDP_DATAGRAMSIZE 8192 | 18 | #define UNIXDGRAM_DATAGRAMSIZE 8192 |
19 | 19 | ||
20 | /*=========================================================================*\ | 20 | /*=========================================================================*\ |
21 | * Internal function prototypes | 21 | * Internal function prototypes |
@@ -36,11 +36,11 @@ static int meth_receivefrom(lua_State *L); | |||
36 | static int meth_sendto(lua_State *L); | 36 | static int meth_sendto(lua_State *L); |
37 | static int meth_getsockname(lua_State *L); | 37 | static int meth_getsockname(lua_State *L); |
38 | 38 | ||
39 | static const char *unixudp_tryconnect(p_unix un, const char *path); | 39 | static const char *unixdgram_tryconnect(p_unix un, const char *path); |
40 | static const char *unixudp_trybind(p_unix un, const char *path); | 40 | static const char *unixdgram_trybind(p_unix un, const char *path); |
41 | 41 | ||
42 | /* unixudp object methods */ | 42 | /* unixdgram object methods */ |
43 | static luaL_Reg unixudp_methods[] = { | 43 | static luaL_Reg unixdgram_methods[] = { |
44 | {"__gc", meth_close}, | 44 | {"__gc", meth_close}, |
45 | {"__tostring", auxiliar_tostring}, | 45 | {"__tostring", auxiliar_tostring}, |
46 | {"bind", meth_bind}, | 46 | {"bind", meth_bind}, |
@@ -70,23 +70,23 @@ static t_opt optset[] = { | |||
70 | 70 | ||
71 | /* functions in library namespace */ | 71 | /* functions in library namespace */ |
72 | static luaL_Reg func[] = { | 72 | static luaL_Reg func[] = { |
73 | {"udp", global_create}, | 73 | {"dgram", global_create}, |
74 | {NULL, NULL} | 74 | {NULL, NULL} |
75 | }; | 75 | }; |
76 | 76 | ||
77 | /*-------------------------------------------------------------------------*\ | 77 | /*-------------------------------------------------------------------------*\ |
78 | * Initializes module | 78 | * Initializes module |
79 | \*-------------------------------------------------------------------------*/ | 79 | \*-------------------------------------------------------------------------*/ |
80 | int unixudp_open(lua_State *L) | 80 | int unixdgram_open(lua_State *L) |
81 | { | 81 | { |
82 | /* create classes */ | 82 | /* create classes */ |
83 | auxiliar_newclass(L, "unixudp{connected}", unixudp_methods); | 83 | auxiliar_newclass(L, "unixdgram{connected}", unixdgram_methods); |
84 | auxiliar_newclass(L, "unixudp{unconnected}", unixudp_methods); | 84 | auxiliar_newclass(L, "unixdgram{unconnected}", unixdgram_methods); |
85 | /* create class groups */ | 85 | /* create class groups */ |
86 | auxiliar_add2group(L, "unixudp{connected}", "unixudp{any}"); | 86 | auxiliar_add2group(L, "unixdgram{connected}", "unixdgram{any}"); |
87 | auxiliar_add2group(L, "unixudp{unconnected}", "unixudp{any}"); | 87 | auxiliar_add2group(L, "unixdgram{unconnected}", "unixdgram{any}"); |
88 | auxiliar_add2group(L, "unixudp{connected}", "select{able}"); | 88 | auxiliar_add2group(L, "unixdgram{connected}", "select{able}"); |
89 | auxiliar_add2group(L, "unixudp{unconnected}", "select{able}"); | 89 | auxiliar_add2group(L, "unixdgram{unconnected}", "select{able}"); |
90 | 90 | ||
91 | luaL_setfuncs(L, func, 0); | 91 | luaL_setfuncs(L, func, 0); |
92 | return 0; | 92 | return 0; |
@@ -95,7 +95,7 @@ int unixudp_open(lua_State *L) | |||
95 | /*=========================================================================*\ | 95 | /*=========================================================================*\ |
96 | * Lua methods | 96 | * Lua methods |
97 | \*=========================================================================*/ | 97 | \*=========================================================================*/ |
98 | static const char *unixudp_strerror(int err) | 98 | static const char *unixdgram_strerror(int err) |
99 | { | 99 | { |
100 | /* a 'closed' error on an unconnected means the target address was not | 100 | /* a 'closed' error on an unconnected means the target address was not |
101 | * accepted by the transport layer */ | 101 | * accepted by the transport layer */ |
@@ -105,7 +105,7 @@ static const char *unixudp_strerror(int err) | |||
105 | 105 | ||
106 | static int meth_send(lua_State *L) | 106 | static int meth_send(lua_State *L) |
107 | { | 107 | { |
108 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{connected}", 1); | 108 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{connected}", 1); |
109 | p_timeout tm = &un->tm; | 109 | p_timeout tm = &un->tm; |
110 | size_t count, sent = 0; | 110 | size_t count, sent = 0; |
111 | int err; | 111 | int err; |
@@ -114,7 +114,7 @@ static int meth_send(lua_State *L) | |||
114 | err = socket_send(&un->sock, data, count, &sent, tm); | 114 | err = socket_send(&un->sock, data, count, &sent, tm); |
115 | if (err != IO_DONE) { | 115 | if (err != IO_DONE) { |
116 | lua_pushnil(L); | 116 | lua_pushnil(L); |
117 | lua_pushstring(L, unixudp_strerror(err)); | 117 | lua_pushstring(L, unixdgram_strerror(err)); |
118 | return 2; | 118 | return 2; |
119 | } | 119 | } |
120 | lua_pushnumber(L, (lua_Number) sent); | 120 | lua_pushnumber(L, (lua_Number) sent); |
@@ -122,11 +122,11 @@ static int meth_send(lua_State *L) | |||
122 | } | 122 | } |
123 | 123 | ||
124 | /*-------------------------------------------------------------------------*\ | 124 | /*-------------------------------------------------------------------------*\ |
125 | * Send data through unconnected unixudp socket | 125 | * Send data through unconnected unixdgram socket |
126 | \*-------------------------------------------------------------------------*/ | 126 | \*-------------------------------------------------------------------------*/ |
127 | static int meth_sendto(lua_State *L) | 127 | static int meth_sendto(lua_State *L) |
128 | { | 128 | { |
129 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); | 129 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); |
130 | size_t count, sent = 0; | 130 | size_t count, sent = 0; |
131 | const char *data = luaL_checklstring(L, 2, &count); | 131 | const char *data = luaL_checklstring(L, 2, &count); |
132 | const char *path = luaL_checkstring(L, 3); | 132 | const char *path = luaL_checkstring(L, 3); |
@@ -155,7 +155,7 @@ static int meth_sendto(lua_State *L) | |||
155 | #endif | 155 | #endif |
156 | if (err != IO_DONE) { | 156 | if (err != IO_DONE) { |
157 | lua_pushnil(L); | 157 | lua_pushnil(L); |
158 | lua_pushstring(L, unixudp_strerror(err)); | 158 | lua_pushstring(L, unixdgram_strerror(err)); |
159 | return 2; | 159 | return 2; |
160 | } | 160 | } |
161 | lua_pushnumber(L, (lua_Number) sent); | 161 | lua_pushnumber(L, (lua_Number) sent); |
@@ -163,8 +163,8 @@ static int meth_sendto(lua_State *L) | |||
163 | } | 163 | } |
164 | 164 | ||
165 | static int meth_receive(lua_State *L) { | 165 | static int meth_receive(lua_State *L) { |
166 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | 166 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
167 | char buf[UNIXUDP_DATAGRAMSIZE]; | 167 | char buf[UNIXDGRAM_DATAGRAMSIZE]; |
168 | size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); | 168 | size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); |
169 | char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; | 169 | char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; |
170 | int err; | 170 | int err; |
@@ -176,10 +176,10 @@ static int meth_receive(lua_State *L) { | |||
176 | return 2; | 176 | return 2; |
177 | } | 177 | } |
178 | err = socket_recv(&un->sock, dgram, wanted, &got, tm); | 178 | err = socket_recv(&un->sock, dgram, wanted, &got, tm); |
179 | /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ | 179 | /* Unlike STREAM, recv() of zero is not closed, but a zero-length packet. */ |
180 | if (err != IO_DONE && err != IO_CLOSED) { | 180 | if (err != IO_DONE && err != IO_CLOSED) { |
181 | lua_pushnil(L); | 181 | lua_pushnil(L); |
182 | lua_pushstring(L, unixudp_strerror(err)); | 182 | lua_pushstring(L, unixdgram_strerror(err)); |
183 | if (wanted > sizeof(buf)) free(dgram); | 183 | if (wanted > sizeof(buf)) free(dgram); |
184 | return 2; | 184 | return 2; |
185 | } | 185 | } |
@@ -189,11 +189,11 @@ static int meth_receive(lua_State *L) { | |||
189 | } | 189 | } |
190 | 190 | ||
191 | /*-------------------------------------------------------------------------*\ | 191 | /*-------------------------------------------------------------------------*\ |
192 | * Receives data and sender from a UDP socket | 192 | * Receives data and sender from a DGRAM socket |
193 | \*-------------------------------------------------------------------------*/ | 193 | \*-------------------------------------------------------------------------*/ |
194 | static int meth_receivefrom(lua_State *L) { | 194 | static int meth_receivefrom(lua_State *L) { |
195 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); | 195 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); |
196 | char buf[UNIXUDP_DATAGRAMSIZE]; | 196 | char buf[UNIXDGRAM_DATAGRAMSIZE]; |
197 | size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); | 197 | size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); |
198 | char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; | 198 | char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; |
199 | struct sockaddr_un addr; | 199 | struct sockaddr_un addr; |
@@ -208,10 +208,10 @@ static int meth_receivefrom(lua_State *L) { | |||
208 | } | 208 | } |
209 | err = socket_recvfrom(&un->sock, dgram, wanted, &got, (SA *) &addr, | 209 | err = socket_recvfrom(&un->sock, dgram, wanted, &got, (SA *) &addr, |
210 | &addr_len, tm); | 210 | &addr_len, tm); |
211 | /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ | 211 | /* Unlike STREAM, recv() of zero is not closed, but a zero-length packet. */ |
212 | if (err != IO_DONE && err != IO_CLOSED) { | 212 | if (err != IO_DONE && err != IO_CLOSED) { |
213 | lua_pushnil(L); | 213 | lua_pushnil(L); |
214 | lua_pushstring(L, unixudp_strerror(err)); | 214 | lua_pushstring(L, unixdgram_strerror(err)); |
215 | if (wanted > sizeof(buf)) free(dgram); | 215 | if (wanted > sizeof(buf)) free(dgram); |
216 | return 2; | 216 | return 2; |
217 | } | 217 | } |
@@ -227,7 +227,7 @@ static int meth_receivefrom(lua_State *L) { | |||
227 | * Just call option handler | 227 | * Just call option handler |
228 | \*-------------------------------------------------------------------------*/ | 228 | \*-------------------------------------------------------------------------*/ |
229 | static int meth_setoption(lua_State *L) { | 229 | static int meth_setoption(lua_State *L) { |
230 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | 230 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
231 | return opt_meth_setoption(L, optset, &un->sock); | 231 | return opt_meth_setoption(L, optset, &un->sock); |
232 | } | 232 | } |
233 | 233 | ||
@@ -235,20 +235,20 @@ static int meth_setoption(lua_State *L) { | |||
235 | * Select support methods | 235 | * Select support methods |
236 | \*-------------------------------------------------------------------------*/ | 236 | \*-------------------------------------------------------------------------*/ |
237 | static int meth_getfd(lua_State *L) { | 237 | static int meth_getfd(lua_State *L) { |
238 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | 238 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
239 | lua_pushnumber(L, (int) un->sock); | 239 | lua_pushnumber(L, (int) un->sock); |
240 | return 1; | 240 | return 1; |
241 | } | 241 | } |
242 | 242 | ||
243 | /* this is very dangerous, but can be handy for those that are brave enough */ | 243 | /* this is very dangerous, but can be handy for those that are brave enough */ |
244 | static int meth_setfd(lua_State *L) { | 244 | static int meth_setfd(lua_State *L) { |
245 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | 245 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
246 | un->sock = (t_socket) luaL_checknumber(L, 2); | 246 | un->sock = (t_socket) luaL_checknumber(L, 2); |
247 | return 0; | 247 | return 0; |
248 | } | 248 | } |
249 | 249 | ||
250 | static int meth_dirty(lua_State *L) { | 250 | static int meth_dirty(lua_State *L) { |
251 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | 251 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
252 | (void) un; | 252 | (void) un; |
253 | lua_pushboolean(L, 0); | 253 | lua_pushboolean(L, 0); |
254 | return 1; | 254 | return 1; |
@@ -257,7 +257,7 @@ static int meth_dirty(lua_State *L) { | |||
257 | /*-------------------------------------------------------------------------*\ | 257 | /*-------------------------------------------------------------------------*\ |
258 | * Binds an object to an address | 258 | * Binds an object to an address |
259 | \*-------------------------------------------------------------------------*/ | 259 | \*-------------------------------------------------------------------------*/ |
260 | static const char *unixudp_trybind(p_unix un, const char *path) { | 260 | static const char *unixdgram_trybind(p_unix un, const char *path) { |
261 | struct sockaddr_un local; | 261 | struct sockaddr_un local; |
262 | size_t len = strlen(path); | 262 | size_t len = strlen(path); |
263 | int err; | 263 | int err; |
@@ -280,9 +280,9 @@ static const char *unixudp_trybind(p_unix un, const char *path) { | |||
280 | 280 | ||
281 | static int meth_bind(lua_State *L) | 281 | static int meth_bind(lua_State *L) |
282 | { | 282 | { |
283 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); | 283 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); |
284 | const char *path = luaL_checkstring(L, 2); | 284 | const char *path = luaL_checkstring(L, 2); |
285 | const char *err = unixudp_trybind(un, path); | 285 | const char *err = unixdgram_trybind(un, path); |
286 | if (err) { | 286 | if (err) { |
287 | lua_pushnil(L); | 287 | lua_pushnil(L); |
288 | lua_pushstring(L, err); | 288 | lua_pushstring(L, err); |
@@ -294,7 +294,7 @@ static int meth_bind(lua_State *L) | |||
294 | 294 | ||
295 | static int meth_getsockname(lua_State *L) | 295 | static int meth_getsockname(lua_State *L) |
296 | { | 296 | { |
297 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | 297 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
298 | struct sockaddr_un peer = {0}; | 298 | struct sockaddr_un peer = {0}; |
299 | socklen_t peer_len = sizeof(peer); | 299 | socklen_t peer_len = sizeof(peer); |
300 | 300 | ||
@@ -309,9 +309,9 @@ static int meth_getsockname(lua_State *L) | |||
309 | } | 309 | } |
310 | 310 | ||
311 | /*-------------------------------------------------------------------------*\ | 311 | /*-------------------------------------------------------------------------*\ |
312 | * Turns a master unixudp object into a client object. | 312 | * Turns a master unixdgram object into a client object. |
313 | \*-------------------------------------------------------------------------*/ | 313 | \*-------------------------------------------------------------------------*/ |
314 | static const char *unixudp_tryconnect(p_unix un, const char *path) | 314 | static const char *unixdgram_tryconnect(p_unix un, const char *path) |
315 | { | 315 | { |
316 | struct sockaddr_un remote; | 316 | struct sockaddr_un remote; |
317 | int err; | 317 | int err; |
@@ -335,16 +335,16 @@ static const char *unixudp_tryconnect(p_unix un, const char *path) | |||
335 | 335 | ||
336 | static int meth_connect(lua_State *L) | 336 | static int meth_connect(lua_State *L) |
337 | { | 337 | { |
338 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | 338 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
339 | const char *path = luaL_checkstring(L, 2); | 339 | const char *path = luaL_checkstring(L, 2); |
340 | const char *err = unixudp_tryconnect(un, path); | 340 | const char *err = unixdgram_tryconnect(un, path); |
341 | if (err) { | 341 | if (err) { |
342 | lua_pushnil(L); | 342 | lua_pushnil(L); |
343 | lua_pushstring(L, err); | 343 | lua_pushstring(L, err); |
344 | return 2; | 344 | return 2; |
345 | } | 345 | } |
346 | /* turn unconnected object into a connected object */ | 346 | /* turn unconnected object into a connected object */ |
347 | auxiliar_setclass(L, "unixudp{connected}", 1); | 347 | auxiliar_setclass(L, "unixdgram{connected}", 1); |
348 | lua_pushnumber(L, 1); | 348 | lua_pushnumber(L, 1); |
349 | return 1; | 349 | return 1; |
350 | } | 350 | } |
@@ -354,7 +354,7 @@ static int meth_connect(lua_State *L) | |||
354 | \*-------------------------------------------------------------------------*/ | 354 | \*-------------------------------------------------------------------------*/ |
355 | static int meth_close(lua_State *L) | 355 | static int meth_close(lua_State *L) |
356 | { | 356 | { |
357 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | 357 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
358 | socket_destroy(&un->sock); | 358 | socket_destroy(&un->sock); |
359 | lua_pushnumber(L, 1); | 359 | lua_pushnumber(L, 1); |
360 | return 1; | 360 | return 1; |
@@ -365,13 +365,13 @@ static int meth_close(lua_State *L) | |||
365 | \*-------------------------------------------------------------------------*/ | 365 | \*-------------------------------------------------------------------------*/ |
366 | static int meth_settimeout(lua_State *L) | 366 | static int meth_settimeout(lua_State *L) |
367 | { | 367 | { |
368 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | 368 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
369 | return timeout_meth_settimeout(L, &un->tm); | 369 | return timeout_meth_settimeout(L, &un->tm); |
370 | } | 370 | } |
371 | 371 | ||
372 | static int meth_gettimeout(lua_State *L) | 372 | static int meth_gettimeout(lua_State *L) |
373 | { | 373 | { |
374 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | 374 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
375 | return timeout_meth_gettimeout(L, &un->tm); | 375 | return timeout_meth_gettimeout(L, &un->tm); |
376 | } | 376 | } |
377 | 377 | ||
@@ -379,7 +379,7 @@ static int meth_gettimeout(lua_State *L) | |||
379 | * Library functions | 379 | * Library functions |
380 | \*=========================================================================*/ | 380 | \*=========================================================================*/ |
381 | /*-------------------------------------------------------------------------*\ | 381 | /*-------------------------------------------------------------------------*\ |
382 | * Creates a master unixudp object | 382 | * Creates a master unixdgram object |
383 | \*-------------------------------------------------------------------------*/ | 383 | \*-------------------------------------------------------------------------*/ |
384 | static int global_create(lua_State *L) | 384 | static int global_create(lua_State *L) |
385 | { | 385 | { |
@@ -387,10 +387,10 @@ static int global_create(lua_State *L) | |||
387 | int err = socket_create(&sock, AF_UNIX, SOCK_DGRAM, 0); | 387 | int err = socket_create(&sock, AF_UNIX, SOCK_DGRAM, 0); |
388 | /* try to allocate a system socket */ | 388 | /* try to allocate a system socket */ |
389 | if (err == IO_DONE) { | 389 | if (err == IO_DONE) { |
390 | /* allocate unixudp object */ | 390 | /* allocate unixdgram object */ |
391 | p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); | 391 | p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); |
392 | /* set its type as master object */ | 392 | /* set its type as master object */ |
393 | auxiliar_setclass(L, "unixudp{unconnected}", -1); | 393 | auxiliar_setclass(L, "unixdgram{unconnected}", -1); |
394 | /* initialize remaining structure fields */ | 394 | /* initialize remaining structure fields */ |
395 | socket_setnonblocking(&sock); | 395 | socket_setnonblocking(&sock); |
396 | un->sock = sock; | 396 | un->sock = sock; |
diff --git a/src/unixudp.h b/src/unixdgram.h index ccfdc07..7187966 100644 --- a/src/unixudp.h +++ b/src/unixdgram.h | |||
@@ -1,13 +1,13 @@ | |||
1 | #ifndef UNIXUDP_H | 1 | #ifndef UNIXDGRAM_H |
2 | #define UNIXUDP_H | 2 | #define UNIXDGRAM_H |
3 | /*=========================================================================*\ | 3 | /*=========================================================================*\ |
4 | * UDP object | 4 | * DGRAM object |
5 | * LuaSocket toolkit | 5 | * LuaSocket toolkit |
6 | * | 6 | * |
7 | * The udp.h module provides LuaSocket with support for UDP protocol | 7 | * The dgram.h module provides LuaSocket with support for DGRAM protocol |
8 | * (AF_INET, SOCK_DGRAM). | 8 | * (AF_INET, SOCK_DGRAM). |
9 | * | 9 | * |
10 | * Two classes are defined: connected and unconnected. UDP objects are | 10 | * Two classes are defined: connected and unconnected. DGRAM objects are |
11 | * originally unconnected. They can be "connected" to a given address | 11 | * originally unconnected. They can be "connected" to a given address |
12 | * with a call to the setpeername function. The same function can be used to | 12 | * with a call to the setpeername function. The same function can be used to |
13 | * break the connection. | 13 | * break the connection. |
@@ -15,6 +15,6 @@ | |||
15 | 15 | ||
16 | #include "unix.h" | 16 | #include "unix.h" |
17 | 17 | ||
18 | int unixudp_open(lua_State *L); | 18 | int unixdgram_open(lua_State *L); |
19 | 19 | ||
20 | #endif /* UNIXUDP_H */ | 20 | #endif /* UNIXDGRAM_H */ |
diff --git a/src/unixtcp.c b/src/unixstream.c index 747ef5f..0b9055c 100644 --- a/src/unixtcp.c +++ b/src/unixstream.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Unix domain socket tcp sub module | 2 | * Unix domain socket stream sub module |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
5 | #include <string.h> | 5 | #include <string.h> |
@@ -11,7 +11,7 @@ | |||
11 | #include "auxiliar.h" | 11 | #include "auxiliar.h" |
12 | #include "socket.h" | 12 | #include "socket.h" |
13 | #include "options.h" | 13 | #include "options.h" |
14 | #include "unixtcp.h" | 14 | #include "unixstream.h" |
15 | #include <sys/un.h> | 15 | #include <sys/un.h> |
16 | 16 | ||
17 | /*=========================================================================*\ | 17 | /*=========================================================================*\ |
@@ -35,11 +35,11 @@ static int meth_getstats(lua_State *L); | |||
35 | static int meth_setstats(lua_State *L); | 35 | static int meth_setstats(lua_State *L); |
36 | static int meth_getsockname(lua_State *L); | 36 | static int meth_getsockname(lua_State *L); |
37 | 37 | ||
38 | static const char *unixtcp_tryconnect(p_unix un, const char *path); | 38 | static const char *unixstream_tryconnect(p_unix un, const char *path); |
39 | static const char *unixtcp_trybind(p_unix un, const char *path); | 39 | static const char *unixstream_trybind(p_unix un, const char *path); |
40 | 40 | ||
41 | /* unixtcp object methods */ | 41 | /* unixstream object methods */ |
42 | static luaL_Reg unixtcp_methods[] = { | 42 | static luaL_Reg unixstream_methods[] = { |
43 | {"__gc", meth_close}, | 43 | {"__gc", meth_close}, |
44 | {"__tostring", auxiliar_tostring}, | 44 | {"__tostring", auxiliar_tostring}, |
45 | {"accept", meth_accept}, | 45 | {"accept", meth_accept}, |
@@ -73,24 +73,24 @@ static t_opt optset[] = { | |||
73 | 73 | ||
74 | /* functions in library namespace */ | 74 | /* functions in library namespace */ |
75 | static luaL_Reg func[] = { | 75 | static luaL_Reg func[] = { |
76 | {"tcp", global_create}, | 76 | {"stream", global_create}, |
77 | {NULL, NULL} | 77 | {NULL, NULL} |
78 | }; | 78 | }; |
79 | 79 | ||
80 | /*-------------------------------------------------------------------------*\ | 80 | /*-------------------------------------------------------------------------*\ |
81 | * Initializes module | 81 | * Initializes module |
82 | \*-------------------------------------------------------------------------*/ | 82 | \*-------------------------------------------------------------------------*/ |
83 | int unixtcp_open(lua_State *L) | 83 | int unixstream_open(lua_State *L) |
84 | { | 84 | { |
85 | /* create classes */ | 85 | /* create classes */ |
86 | auxiliar_newclass(L, "unixtcp{master}", unixtcp_methods); | 86 | auxiliar_newclass(L, "unixstream{master}", unixstream_methods); |
87 | auxiliar_newclass(L, "unixtcp{client}", unixtcp_methods); | 87 | auxiliar_newclass(L, "unixstream{client}", unixstream_methods); |
88 | auxiliar_newclass(L, "unixtcp{server}", unixtcp_methods); | 88 | auxiliar_newclass(L, "unixstream{server}", unixstream_methods); |
89 | 89 | ||
90 | /* create class groups */ | 90 | /* create class groups */ |
91 | auxiliar_add2group(L, "unixtcp{master}", "unixtcp{any}"); | 91 | auxiliar_add2group(L, "unixstream{master}", "unixstream{any}"); |
92 | auxiliar_add2group(L, "unixtcp{client}", "unixtcp{any}"); | 92 | auxiliar_add2group(L, "unixstream{client}", "unixstream{any}"); |
93 | auxiliar_add2group(L, "unixtcp{server}", "unixtcp{any}"); | 93 | auxiliar_add2group(L, "unixstream{server}", "unixstream{any}"); |
94 | 94 | ||
95 | luaL_setfuncs(L, func, 0); | 95 | luaL_setfuncs(L, func, 0); |
96 | return 0; | 96 | return 0; |
@@ -103,22 +103,22 @@ int unixtcp_open(lua_State *L) | |||
103 | * Just call buffered IO methods | 103 | * Just call buffered IO methods |
104 | \*-------------------------------------------------------------------------*/ | 104 | \*-------------------------------------------------------------------------*/ |
105 | static int meth_send(lua_State *L) { | 105 | static int meth_send(lua_State *L) { |
106 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); | 106 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); |
107 | return buffer_meth_send(L, &un->buf); | 107 | return buffer_meth_send(L, &un->buf); |
108 | } | 108 | } |
109 | 109 | ||
110 | static int meth_receive(lua_State *L) { | 110 | static int meth_receive(lua_State *L) { |
111 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); | 111 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); |
112 | return buffer_meth_receive(L, &un->buf); | 112 | return buffer_meth_receive(L, &un->buf); |
113 | } | 113 | } |
114 | 114 | ||
115 | static int meth_getstats(lua_State *L) { | 115 | static int meth_getstats(lua_State *L) { |
116 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); | 116 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); |
117 | return buffer_meth_getstats(L, &un->buf); | 117 | return buffer_meth_getstats(L, &un->buf); |
118 | } | 118 | } |
119 | 119 | ||
120 | static int meth_setstats(lua_State *L) { | 120 | static int meth_setstats(lua_State *L) { |
121 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); | 121 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); |
122 | return buffer_meth_setstats(L, &un->buf); | 122 | return buffer_meth_setstats(L, &un->buf); |
123 | } | 123 | } |
124 | 124 | ||
@@ -126,7 +126,7 @@ static int meth_setstats(lua_State *L) { | |||
126 | * Just call option handler | 126 | * Just call option handler |
127 | \*-------------------------------------------------------------------------*/ | 127 | \*-------------------------------------------------------------------------*/ |
128 | static int meth_setoption(lua_State *L) { | 128 | static int meth_setoption(lua_State *L) { |
129 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); | 129 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); |
130 | return opt_meth_setoption(L, optset, &un->sock); | 130 | return opt_meth_setoption(L, optset, &un->sock); |
131 | } | 131 | } |
132 | 132 | ||
@@ -134,20 +134,20 @@ static int meth_setoption(lua_State *L) { | |||
134 | * Select support methods | 134 | * Select support methods |
135 | \*-------------------------------------------------------------------------*/ | 135 | \*-------------------------------------------------------------------------*/ |
136 | static int meth_getfd(lua_State *L) { | 136 | static int meth_getfd(lua_State *L) { |
137 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); | 137 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); |
138 | lua_pushnumber(L, (int) un->sock); | 138 | lua_pushnumber(L, (int) un->sock); |
139 | return 1; | 139 | return 1; |
140 | } | 140 | } |
141 | 141 | ||
142 | /* this is very dangerous, but can be handy for those that are brave enough */ | 142 | /* this is very dangerous, but can be handy for those that are brave enough */ |
143 | static int meth_setfd(lua_State *L) { | 143 | static int meth_setfd(lua_State *L) { |
144 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); | 144 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); |
145 | un->sock = (t_socket) luaL_checknumber(L, 2); | 145 | un->sock = (t_socket) luaL_checknumber(L, 2); |
146 | return 0; | 146 | return 0; |
147 | } | 147 | } |
148 | 148 | ||
149 | static int meth_dirty(lua_State *L) { | 149 | static int meth_dirty(lua_State *L) { |
150 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); | 150 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); |
151 | lua_pushboolean(L, !buffer_isempty(&un->buf)); | 151 | lua_pushboolean(L, !buffer_isempty(&un->buf)); |
152 | return 1; | 152 | return 1; |
153 | } | 153 | } |
@@ -157,14 +157,14 @@ static int meth_dirty(lua_State *L) { | |||
157 | * server object | 157 | * server object |
158 | \*-------------------------------------------------------------------------*/ | 158 | \*-------------------------------------------------------------------------*/ |
159 | static int meth_accept(lua_State *L) { | 159 | static int meth_accept(lua_State *L) { |
160 | p_unix server = (p_unix) auxiliar_checkclass(L, "unixtcp{server}", 1); | 160 | p_unix server = (p_unix) auxiliar_checkclass(L, "unixstream{server}", 1); |
161 | p_timeout tm = timeout_markstart(&server->tm); | 161 | p_timeout tm = timeout_markstart(&server->tm); |
162 | t_socket sock; | 162 | t_socket sock; |
163 | int err = socket_accept(&server->sock, &sock, NULL, NULL, tm); | 163 | int err = socket_accept(&server->sock, &sock, NULL, NULL, tm); |
164 | /* if successful, push client socket */ | 164 | /* if successful, push client socket */ |
165 | if (err == IO_DONE) { | 165 | if (err == IO_DONE) { |
166 | p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix)); | 166 | p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix)); |
167 | auxiliar_setclass(L, "unixtcp{client}", -1); | 167 | auxiliar_setclass(L, "unixstream{client}", -1); |
168 | /* initialize structure fields */ | 168 | /* initialize structure fields */ |
169 | socket_setnonblocking(&sock); | 169 | socket_setnonblocking(&sock); |
170 | clnt->sock = sock; | 170 | clnt->sock = sock; |
@@ -183,7 +183,7 @@ static int meth_accept(lua_State *L) { | |||
183 | /*-------------------------------------------------------------------------*\ | 183 | /*-------------------------------------------------------------------------*\ |
184 | * Binds an object to an address | 184 | * Binds an object to an address |
185 | \*-------------------------------------------------------------------------*/ | 185 | \*-------------------------------------------------------------------------*/ |
186 | static const char *unixtcp_trybind(p_unix un, const char *path) { | 186 | static const char *unixstream_trybind(p_unix un, const char *path) { |
187 | struct sockaddr_un local; | 187 | struct sockaddr_un local; |
188 | size_t len = strlen(path); | 188 | size_t len = strlen(path); |
189 | int err; | 189 | int err; |
@@ -205,9 +205,9 @@ static const char *unixtcp_trybind(p_unix un, const char *path) { | |||
205 | } | 205 | } |
206 | 206 | ||
207 | static int meth_bind(lua_State *L) { | 207 | static int meth_bind(lua_State *L) { |
208 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); | 208 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); |
209 | const char *path = luaL_checkstring(L, 2); | 209 | const char *path = luaL_checkstring(L, 2); |
210 | const char *err = unixtcp_trybind(un, path); | 210 | const char *err = unixstream_trybind(un, path); |
211 | if (err) { | 211 | if (err) { |
212 | lua_pushnil(L); | 212 | lua_pushnil(L); |
213 | lua_pushstring(L, err); | 213 | lua_pushstring(L, err); |
@@ -219,7 +219,7 @@ static int meth_bind(lua_State *L) { | |||
219 | 219 | ||
220 | static int meth_getsockname(lua_State *L) | 220 | static int meth_getsockname(lua_State *L) |
221 | { | 221 | { |
222 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); | 222 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); |
223 | struct sockaddr_un peer = {0}; | 223 | struct sockaddr_un peer = {0}; |
224 | socklen_t peer_len = sizeof(peer); | 224 | socklen_t peer_len = sizeof(peer); |
225 | 225 | ||
@@ -234,9 +234,9 @@ static int meth_getsockname(lua_State *L) | |||
234 | } | 234 | } |
235 | 235 | ||
236 | /*-------------------------------------------------------------------------*\ | 236 | /*-------------------------------------------------------------------------*\ |
237 | * Turns a master unixtcp object into a client object. | 237 | * Turns a master unixstream object into a client object. |
238 | \*-------------------------------------------------------------------------*/ | 238 | \*-------------------------------------------------------------------------*/ |
239 | static const char *unixtcp_tryconnect(p_unix un, const char *path) | 239 | static const char *unixstream_tryconnect(p_unix un, const char *path) |
240 | { | 240 | { |
241 | struct sockaddr_un remote; | 241 | struct sockaddr_un remote; |
242 | int err; | 242 | int err; |
@@ -260,16 +260,16 @@ static const char *unixtcp_tryconnect(p_unix un, const char *path) | |||
260 | 260 | ||
261 | static int meth_connect(lua_State *L) | 261 | static int meth_connect(lua_State *L) |
262 | { | 262 | { |
263 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); | 263 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); |
264 | const char *path = luaL_checkstring(L, 2); | 264 | const char *path = luaL_checkstring(L, 2); |
265 | const char *err = unixtcp_tryconnect(un, path); | 265 | const char *err = unixstream_tryconnect(un, path); |
266 | if (err) { | 266 | if (err) { |
267 | lua_pushnil(L); | 267 | lua_pushnil(L); |
268 | lua_pushstring(L, err); | 268 | lua_pushstring(L, err); |
269 | return 2; | 269 | return 2; |
270 | } | 270 | } |
271 | /* turn master object into a client object */ | 271 | /* turn master object into a client object */ |
272 | auxiliar_setclass(L, "unixtcp{client}", 1); | 272 | auxiliar_setclass(L, "unixstream{client}", 1); |
273 | lua_pushnumber(L, 1); | 273 | lua_pushnumber(L, 1); |
274 | return 1; | 274 | return 1; |
275 | } | 275 | } |
@@ -279,7 +279,7 @@ static int meth_connect(lua_State *L) | |||
279 | \*-------------------------------------------------------------------------*/ | 279 | \*-------------------------------------------------------------------------*/ |
280 | static int meth_close(lua_State *L) | 280 | static int meth_close(lua_State *L) |
281 | { | 281 | { |
282 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); | 282 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); |
283 | socket_destroy(&un->sock); | 283 | socket_destroy(&un->sock); |
284 | lua_pushnumber(L, 1); | 284 | lua_pushnumber(L, 1); |
285 | return 1; | 285 | return 1; |
@@ -290,7 +290,7 @@ static int meth_close(lua_State *L) | |||
290 | \*-------------------------------------------------------------------------*/ | 290 | \*-------------------------------------------------------------------------*/ |
291 | static int meth_listen(lua_State *L) | 291 | static int meth_listen(lua_State *L) |
292 | { | 292 | { |
293 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); | 293 | p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); |
294 | int backlog = (int) luaL_optnumber(L, 2, 32); | 294 | int backlog = (int) luaL_optnumber(L, 2, 32); |
295 | int err = socket_listen(&un->sock, backlog); | 295 | int err = socket_listen(&un->sock, backlog); |
296 | if (err != IO_DONE) { | 296 | if (err != IO_DONE) { |
@@ -299,7 +299,7 @@ static int meth_listen(lua_State *L) | |||
299 | return 2; | 299 | return 2; |
300 | } | 300 | } |
301 | /* turn master object into a server object */ | 301 | /* turn master object into a server object */ |
302 | auxiliar_setclass(L, "unixtcp{server}", 1); | 302 | auxiliar_setclass(L, "unixstream{server}", 1); |
303 | lua_pushnumber(L, 1); | 303 | lua_pushnumber(L, 1); |
304 | return 1; | 304 | return 1; |
305 | } | 305 | } |
@@ -311,9 +311,9 @@ static int meth_shutdown(lua_State *L) | |||
311 | { | 311 | { |
312 | /* SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2, so we can use method index directly */ | 312 | /* SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2, so we can use method index directly */ |
313 | static const char* methods[] = { "receive", "send", "both", NULL }; | 313 | static const char* methods[] = { "receive", "send", "both", NULL }; |
314 | p_unix tcp = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); | 314 | p_unix stream = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); |
315 | int how = luaL_checkoption(L, 2, "both", methods); | 315 | int how = luaL_checkoption(L, 2, "both", methods); |
316 | socket_shutdown(&tcp->sock, how); | 316 | socket_shutdown(&stream->sock, how); |
317 | lua_pushnumber(L, 1); | 317 | lua_pushnumber(L, 1); |
318 | return 1; | 318 | return 1; |
319 | } | 319 | } |
@@ -322,7 +322,7 @@ static int meth_shutdown(lua_State *L) | |||
322 | * Just call tm methods | 322 | * Just call tm methods |
323 | \*-------------------------------------------------------------------------*/ | 323 | \*-------------------------------------------------------------------------*/ |
324 | static int meth_settimeout(lua_State *L) { | 324 | static int meth_settimeout(lua_State *L) { |
325 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); | 325 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); |
326 | return timeout_meth_settimeout(L, &un->tm); | 326 | return timeout_meth_settimeout(L, &un->tm); |
327 | } | 327 | } |
328 | 328 | ||
@@ -330,17 +330,17 @@ static int meth_settimeout(lua_State *L) { | |||
330 | * Library functions | 330 | * Library functions |
331 | \*=========================================================================*/ | 331 | \*=========================================================================*/ |
332 | /*-------------------------------------------------------------------------*\ | 332 | /*-------------------------------------------------------------------------*\ |
333 | * Creates a master unixtcp object | 333 | * Creates a master unixstream object |
334 | \*-------------------------------------------------------------------------*/ | 334 | \*-------------------------------------------------------------------------*/ |
335 | static int global_create(lua_State *L) { | 335 | static int global_create(lua_State *L) { |
336 | t_socket sock; | 336 | t_socket sock; |
337 | int err = socket_create(&sock, AF_UNIX, SOCK_STREAM, 0); | 337 | int err = socket_create(&sock, AF_UNIX, SOCK_STREAM, 0); |
338 | /* try to allocate a system socket */ | 338 | /* try to allocate a system socket */ |
339 | if (err == IO_DONE) { | 339 | if (err == IO_DONE) { |
340 | /* allocate unixtcp object */ | 340 | /* allocate unixstream object */ |
341 | p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); | 341 | p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); |
342 | /* set its type as master object */ | 342 | /* set its type as master object */ |
343 | auxiliar_setclass(L, "unixtcp{master}", -1); | 343 | auxiliar_setclass(L, "unixstream{master}", -1); |
344 | /* initialize remaining structure fields */ | 344 | /* initialize remaining structure fields */ |
345 | socket_setnonblocking(&sock); | 345 | socket_setnonblocking(&sock); |
346 | un->sock = sock; | 346 | un->sock = sock; |
diff --git a/src/unixstream.h b/src/unixstream.h new file mode 100644 index 0000000..ef1d071 --- /dev/null +++ b/src/unixstream.h | |||
@@ -0,0 +1,21 @@ | |||
1 | #ifndef UNIXSTREAM_H | ||
2 | #define UNIXSTREAM_H | ||
3 | /*=========================================================================*\ | ||
4 | * UNIX STREAM object | ||
5 | * LuaSocket toolkit | ||
6 | * | ||
7 | * The unixstream.h module is basicly a glue that puts together modules buffer.h, | ||
8 | * timeout.h socket.h and inet.h to provide the LuaSocket UNIX STREAM (AF_UNIX, | ||
9 | * SOCK_STREAM) support. | ||
10 | * | ||
11 | * Three classes are defined: master, client and server. The master class is | ||
12 | * a newly created unixstream object, that has not been bound or connected. Server | ||
13 | * objects are unixstream objects bound to some local address. Client objects are | ||
14 | * unixstream objects either connected to some address or returned by the accept | ||
15 | * method of a server object. | ||
16 | \*=========================================================================*/ | ||
17 | #include "unix.h" | ||
18 | |||
19 | int unixstream_open(lua_State *L); | ||
20 | |||
21 | #endif /* UNIXSTREAM_H */ | ||
diff --git a/src/unixtcp.h b/src/unixtcp.h deleted file mode 100644 index 0eababc..0000000 --- a/src/unixtcp.h +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | #ifndef UNIXTCP_H | ||
2 | #define UNIXTCP_H | ||
3 | /*=========================================================================*\ | ||
4 | * UNIX TCP object | ||
5 | * LuaSocket toolkit | ||
6 | * | ||
7 | * The unixtcp.h module is basicly a glue that puts together modules buffer.h, | ||
8 | * timeout.h socket.h and inet.h to provide the LuaSocket UNIX TCP (AF_UNIX, | ||
9 | * SOCK_STREAM) support. | ||
10 | * | ||
11 | * Three classes are defined: master, client and server. The master class is | ||
12 | * a newly created unixtcp object, that has not been bound or connected. Server | ||
13 | * objects are unixtcp objects bound to some local address. Client objects are | ||
14 | * unixtcp objects either connected to some address or returned by the accept | ||
15 | * method of a server object. | ||
16 | \*=========================================================================*/ | ||
17 | #include "unix.h" | ||
18 | |||
19 | int unixtcp_open(lua_State *L); | ||
20 | |||
21 | #endif /* UNIXTCP_H */ | ||
diff --git a/test/unixudpclnt.lua b/test/unixdgramclnt.lua index bbbff7f..9bd60f7 100644 --- a/test/unixudpclnt.lua +++ b/test/unixdgramclnt.lua | |||
@@ -1,7 +1,7 @@ | |||
1 | socket = require"socket" | 1 | socket = require"socket" |
2 | socket.unix = require"socket.unix" | 2 | socket.unix = require"socket.unix" |
3 | c = assert(socket.unix.udp()) | 3 | c = assert(socket.unix.dgram()) |
4 | c:bind("/tmp/bar") | 4 | print(c:bind("/tmp/bar")) |
5 | while 1 do | 5 | while 1 do |
6 | local l = io.read("*l") | 6 | local l = io.read("*l") |
7 | assert(c:sendto(l, "/tmp/foo")) | 7 | assert(c:sendto(l, "/tmp/foo")) |
diff --git a/test/unixudpsrvr.lua b/test/unixdgramsrvr.lua index 5ed71dc..4c11f55 100644 --- a/test/unixudpsrvr.lua +++ b/test/unixdgramsrvr.lua | |||
@@ -1,6 +1,6 @@ | |||
1 | socket = require"socket" | 1 | socket = require"socket" |
2 | socket.unix = require"socket.unix" | 2 | socket.unix = require"socket.unix" |
3 | u = assert(socket.unix.udp()) | 3 | u = assert(socket.unix.dgram()) |
4 | assert(u:bind("/tmp/foo")) | 4 | assert(u:bind("/tmp/foo")) |
5 | while 1 do | 5 | while 1 do |
6 | x, r = assert(u:receivefrom()) | 6 | x, r = assert(u:receivefrom()) |
diff --git a/test/unixtcpclnt.lua b/test/unixstreamclnt.lua index 652a680..4f2e1e3 100644 --- a/test/unixtcpclnt.lua +++ b/test/unixstreamclnt.lua | |||
@@ -1,6 +1,6 @@ | |||
1 | socket = require"socket" | 1 | socket = require"socket" |
2 | socket.unix = require"socket.unix" | 2 | socket.unix = require"socket.unix" |
3 | c = assert(socket.unix.tcp()) | 3 | c = assert(socket.unix.stream()) |
4 | assert(c:connect("/tmp/foo")) | 4 | assert(c:connect("/tmp/foo")) |
5 | while 1 do | 5 | while 1 do |
6 | local l = io.read() | 6 | local l = io.read() |
diff --git a/test/unixtcpsrvr.lua b/test/unixstreamsrvr.lua index 2a2b065..0a5c644 100644 --- a/test/unixtcpsrvr.lua +++ b/test/unixstreamsrvr.lua | |||
@@ -1,6 +1,6 @@ | |||
1 | socket = require"socket" | 1 | socket = require"socket" |
2 | socket.unix = require"socket.unix" | 2 | socket.unix = require"socket.unix" |
3 | u = assert(socket.unix.tcp()) | 3 | u = assert(socket.unix.stream()) |
4 | assert(u:bind("/tmp/foo")) | 4 | assert(u:bind("/tmp/foo")) |
5 | assert(u:listen()) | 5 | assert(u:listen()) |
6 | c = assert(u:accept()) | 6 | c = assert(u:accept()) |