diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/auxiliar.c | 2 | ||||
-rw-r--r-- | src/buffer.c | 2 | ||||
-rw-r--r-- | src/except.c | 2 | ||||
-rw-r--r-- | src/ftp.lua | 1 | ||||
-rw-r--r-- | src/headers.lua | 1 | ||||
-rw-r--r-- | src/http.lua | 1 | ||||
-rw-r--r-- | src/inet.c | 6 | ||||
-rw-r--r-- | src/io.c | 2 | ||||
-rw-r--r-- | src/ltn12.lua | 1 | ||||
-rw-r--r-- | src/luasocket.h | 2 | ||||
-rw-r--r-- | src/makefile | 2 | ||||
-rw-r--r-- | src/mime.c | 2 | ||||
-rw-r--r-- | src/mime.lua | 1 | ||||
-rw-r--r-- | src/options.c | 2 | ||||
-rw-r--r-- | src/select.c | 2 | ||||
-rw-r--r-- | src/smtp.lua | 1 | ||||
-rw-r--r-- | src/socket.lua | 1 | ||||
-rw-r--r-- | src/tcp.c | 31 | ||||
-rw-r--r-- | src/tcp.h | 2 | ||||
-rw-r--r-- | src/timeout.c | 2 | ||||
-rw-r--r-- | src/tp.lua | 1 | ||||
-rw-r--r-- | src/udp.c | 31 | ||||
-rw-r--r-- | src/udp.h | 2 | ||||
-rw-r--r-- | src/unix.c | 2 | ||||
-rw-r--r-- | src/url.lua | 15 | ||||
-rw-r--r-- | src/usocket.c | 2 | ||||
-rw-r--r-- | src/wsocket.c | 2 |
27 files changed, 62 insertions, 59 deletions
diff --git a/src/auxiliar.c b/src/auxiliar.c index c4e5260..de625e9 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c | |||
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Auxiliar routines for class hierarchy manipulation | 2 | * Auxiliar routines for class hierarchy manipulation |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: auxiliar.c,v 1.14 2005/10/07 04:40:59 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include <string.h> | 5 | #include <string.h> |
8 | #include <stdio.h> | 6 | #include <stdio.h> |
diff --git a/src/buffer.c b/src/buffer.c index 452a579..d8facd2 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Input/Output interface for Lua programs | 2 | * Input/Output interface for Lua programs |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: buffer.c,v 1.29 2009/05/27 09:31:35 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include "lua.h" | 5 | #include "lua.h" |
8 | #include "lauxlib.h" | 6 | #include "lauxlib.h" |
diff --git a/src/except.c b/src/except.c index 97c00a3..1d1ade0 100644 --- a/src/except.c +++ b/src/except.c | |||
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Simple exception support | 2 | * Simple exception support |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: except.c,v 1.8 2005/09/29 06:11:41 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include <stdio.h> | 5 | #include <stdio.h> |
8 | 6 | ||
diff --git a/src/ftp.lua b/src/ftp.lua index 1d5ff77..5aa646b 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 toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id: ftp.lua,v 1.45 2007/07/11 19:25:47 diego Exp $ | ||
6 | ----------------------------------------------------------------------------- | 5 | ----------------------------------------------------------------------------- |
7 | 6 | ||
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
diff --git a/src/headers.lua b/src/headers.lua index f92ee7a..41794ba 100644 --- a/src/headers.lua +++ b/src/headers.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- Canonic header field capitalization | 2 | -- Canonic header field capitalization |
3 | -- LuaSocket toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id$ | ||
6 | ----------------------------------------------------------------------------- | 5 | ----------------------------------------------------------------------------- |
7 | module("socket.headers") | 6 | module("socket.headers") |
8 | 7 | ||
diff --git a/src/http.lua b/src/http.lua index 029a367..4c7e7d8 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 toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id: http.lua,v 1.72 2009/05/27 09:31:35 diego Exp $ | ||
6 | ----------------------------------------------------------------------------- | 5 | ----------------------------------------------------------------------------- |
7 | 6 | ||
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Internet domain functions | 2 | * Internet domain functions |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: inet.c,v 1.28 2005/10/07 04:40:59 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include <stdio.h> | 5 | #include <stdio.h> |
8 | #include <string.h> | 6 | #include <string.h> |
@@ -270,8 +268,8 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp) | |||
270 | /*-------------------------------------------------------------------------*\ | 268 | /*-------------------------------------------------------------------------*\ |
271 | * Tries to create a new inet socket | 269 | * Tries to create a new inet socket |
272 | \*-------------------------------------------------------------------------*/ | 270 | \*-------------------------------------------------------------------------*/ |
273 | const char *inet_trycreate(p_socket ps, int domain, int type) { | 271 | const char *inet_trycreate(p_socket ps, int family, int type) { |
274 | return socket_strerror(socket_create(ps, domain, type, 0)); | 272 | return socket_strerror(socket_create(ps, family, type, 0)); |
275 | } | 273 | } |
276 | 274 | ||
277 | /*-------------------------------------------------------------------------*\ | 275 | /*-------------------------------------------------------------------------*\ |
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Input/Output abstraction | 2 | * Input/Output abstraction |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: io.c,v 1.6 2005/09/29 06:11:41 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include "io.h" | 5 | #include "io.h" |
8 | 6 | ||
diff --git a/src/ltn12.lua b/src/ltn12.lua index b42689a..b7f9a21 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- LTN12 - Filters, sources, sinks and pumps. | 2 | -- LTN12 - Filters, sources, sinks and pumps. |
3 | -- LuaSocket toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id: ltn12.lua,v 1.31 2006/04/03 04:45:42 diego Exp $ | ||
6 | ----------------------------------------------------------------------------- | 5 | ----------------------------------------------------------------------------- |
7 | 6 | ||
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
diff --git a/src/luasocket.h b/src/luasocket.h index 09e758d..f2ca3c1 100644 --- a/src/luasocket.h +++ b/src/luasocket.h | |||
@@ -11,7 +11,7 @@ | |||
11 | /*-------------------------------------------------------------------------*\ | 11 | /*-------------------------------------------------------------------------*\ |
12 | * Current socket library version | 12 | * Current socket library version |
13 | \*-------------------------------------------------------------------------*/ | 13 | \*-------------------------------------------------------------------------*/ |
14 | #define LUASOCKET_VERSION "LuaSocket 2.1.1-rc1" | 14 | #define LUASOCKET_VERSION "LuaSocket 2.1-rc1" |
15 | #define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2012 Diego Nehab" | 15 | #define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2012 Diego Nehab" |
16 | #define LUASOCKET_AUTHORS "Diego Nehab" | 16 | #define LUASOCKET_AUTHORS "Diego Nehab" |
17 | 17 | ||
diff --git a/src/makefile b/src/makefile index 0665c14..6225ce4 100644 --- a/src/makefile +++ b/src/makefile | |||
@@ -98,7 +98,7 @@ SOCKET_win32=wsocket.obj | |||
98 | # | 98 | # |
99 | SO=$(SO_$(PLAT)) | 99 | SO=$(SO_$(PLAT)) |
100 | O=$(O_$(PLAT)) | 100 | O=$(O_$(PLAT)) |
101 | SOCKET_V=2.1.1 | 101 | SOCKET_V=2.1 |
102 | MIME_V=1.0.3 | 102 | MIME_V=1.0.3 |
103 | SOCKET_SO=socket.$(SO).$(SOCKET_V) | 103 | SOCKET_SO=socket.$(SO).$(SOCKET_V) |
104 | MIME_SO=mime.$(SO).$(MIME_V) | 104 | MIME_SO=mime.$(SO).$(MIME_V) |
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * MIME support functions | 2 | * MIME support functions |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: mime.c,v 1.29 2009/05/27 09:31:35 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include <string.h> | 5 | #include <string.h> |
8 | 6 | ||
diff --git a/src/mime.lua b/src/mime.lua index 218b38a..4aaccc8 100644 --- a/src/mime.lua +++ b/src/mime.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- MIME support for the Lua language. | 2 | -- MIME support for the Lua language. |
3 | -- Author: Diego Nehab | 3 | -- Author: Diego Nehab |
4 | -- Conforming to RFCs 2045-2049 | 4 | -- Conforming to RFCs 2045-2049 |
5 | -- RCS ID: $Id: mime.lua,v 1.29 2007/06/11 23:44:54 diego Exp $ | ||
6 | ----------------------------------------------------------------------------- | 5 | ----------------------------------------------------------------------------- |
7 | 6 | ||
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
diff --git a/src/options.c b/src/options.c index c122ead..6cae7ee 100644 --- a/src/options.c +++ b/src/options.c | |||
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Common option interface | 2 | * Common option interface |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: options.c,v 1.7 2009/05/27 09:31:35 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include <string.h> | 5 | #include <string.h> |
8 | 6 | ||
diff --git a/src/select.c b/src/select.c index 87b5dc2..b870545 100644 --- a/src/select.c +++ b/src/select.c | |||
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Select implementation | 2 | * Select implementation |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: select.c,v 1.23 2009/05/27 09:31:35 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include <string.h> | 5 | #include <string.h> |
8 | 6 | ||
diff --git a/src/smtp.lua b/src/smtp.lua index e258d62..26808f5 100644 --- a/src/smtp.lua +++ b/src/smtp.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- SMTP client support for the Lua language. | 2 | -- SMTP client support for the Lua language. |
3 | -- LuaSocket toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id: smtp.lua,v 1.47 2009/05/27 09:31:35 diego Exp $ | ||
6 | ----------------------------------------------------------------------------- | 5 | ----------------------------------------------------------------------------- |
7 | 6 | ||
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
diff --git a/src/socket.lua b/src/socket.lua index 734da3c..a9219b0 100644 --- a/src/socket.lua +++ b/src/socket.lua | |||
@@ -1,7 +1,6 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- LuaSocket helper module | 2 | -- LuaSocket helper module |
3 | -- Author: Diego Nehab | 3 | -- Author: Diego Nehab |
4 | -- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $ | ||
5 | ----------------------------------------------------------------------------- | 4 | ----------------------------------------------------------------------------- |
6 | 5 | ||
7 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * TCP object | 2 | * TCP object |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: tcp.c,v 1.42 2009/05/27 09:31:35 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include <string.h> | 5 | #include <string.h> |
8 | 6 | ||
@@ -23,6 +21,7 @@ static int global_create6(lua_State *L); | |||
23 | static int global_connect6(lua_State *L); | 21 | static int global_connect6(lua_State *L); |
24 | static int meth_connect(lua_State *L); | 22 | static int meth_connect(lua_State *L); |
25 | static int meth_listen(lua_State *L); | 23 | static int meth_listen(lua_State *L); |
24 | static int meth_getfamily(lua_State *L); | ||
26 | static int meth_bind(lua_State *L); | 25 | static int meth_bind(lua_State *L); |
27 | static int meth_send(lua_State *L); | 26 | static int meth_send(lua_State *L); |
28 | static int meth_getstats(lua_State *L); | 27 | static int meth_getstats(lua_State *L); |
@@ -49,6 +48,7 @@ static luaL_Reg tcp_methods[] = { | |||
49 | {"close", meth_close}, | 48 | {"close", meth_close}, |
50 | {"connect", meth_connect}, | 49 | {"connect", meth_connect}, |
51 | {"dirty", meth_dirty}, | 50 | {"dirty", meth_dirty}, |
51 | {"getfamily", meth_getfamily}, | ||
52 | {"getfd", meth_getfd}, | 52 | {"getfd", meth_getfd}, |
53 | {"getoption", meth_getoption}, | 53 | {"getoption", meth_getoption}, |
54 | {"getpeername", meth_getpeername}, | 54 | {"getpeername", meth_getpeername}, |
@@ -218,7 +218,7 @@ static int meth_bind(lua_State *L) | |||
218 | struct addrinfo bindhints; | 218 | struct addrinfo bindhints; |
219 | memset(&bindhints, 0, sizeof(bindhints)); | 219 | memset(&bindhints, 0, sizeof(bindhints)); |
220 | bindhints.ai_socktype = SOCK_STREAM; | 220 | bindhints.ai_socktype = SOCK_STREAM; |
221 | bindhints.ai_family = tcp->domain; | 221 | bindhints.ai_family = tcp->family; |
222 | bindhints.ai_flags = AI_PASSIVE; | 222 | bindhints.ai_flags = AI_PASSIVE; |
223 | err = inet_trybind(&tcp->sock, address, port, &bindhints); | 223 | err = inet_trybind(&tcp->sock, address, port, &bindhints); |
224 | if (err) { | 224 | if (err) { |
@@ -243,7 +243,7 @@ static int meth_connect(lua_State *L) | |||
243 | memset(&connecthints, 0, sizeof(connecthints)); | 243 | memset(&connecthints, 0, sizeof(connecthints)); |
244 | connecthints.ai_socktype = SOCK_STREAM; | 244 | connecthints.ai_socktype = SOCK_STREAM; |
245 | /* make sure we try to connect only to the same family */ | 245 | /* make sure we try to connect only to the same family */ |
246 | connecthints.ai_family = tcp->domain; | 246 | connecthints.ai_family = tcp->family; |
247 | timeout_markstart(&tcp->tm); | 247 | timeout_markstart(&tcp->tm); |
248 | err = inet_tryconnect(&tcp->sock, address, port, | 248 | err = inet_tryconnect(&tcp->sock, address, port, |
249 | &tcp->tm, &connecthints); | 249 | &tcp->tm, &connecthints); |
@@ -270,6 +270,21 @@ static int meth_close(lua_State *L) | |||
270 | } | 270 | } |
271 | 271 | ||
272 | /*-------------------------------------------------------------------------*\ | 272 | /*-------------------------------------------------------------------------*\ |
273 | * Returns family as string | ||
274 | \*-------------------------------------------------------------------------*/ | ||
275 | static int meth_getfamily(lua_State *L) | ||
276 | { | ||
277 | p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, "tcp{any}", 1); | ||
278 | if (tcp->family == PF_INET6) { | ||
279 | lua_pushliteral(L, "inet6"); | ||
280 | return 1; | ||
281 | } else { | ||
282 | lua_pushliteral(L, "inet4"); | ||
283 | return 1; | ||
284 | } | ||
285 | } | ||
286 | |||
287 | /*-------------------------------------------------------------------------*\ | ||
273 | * Puts the sockt in listen mode | 288 | * Puts the sockt in listen mode |
274 | \*-------------------------------------------------------------------------*/ | 289 | \*-------------------------------------------------------------------------*/ |
275 | static int meth_listen(lua_State *L) | 290 | static int meth_listen(lua_State *L) |
@@ -346,9 +361,9 @@ static int meth_settimeout(lua_State *L) | |||
346 | /*-------------------------------------------------------------------------*\ | 361 | /*-------------------------------------------------------------------------*\ |
347 | * Creates a master tcp object | 362 | * Creates a master tcp object |
348 | \*-------------------------------------------------------------------------*/ | 363 | \*-------------------------------------------------------------------------*/ |
349 | static int tcp_create(lua_State *L, int domain) { | 364 | static int tcp_create(lua_State *L, int family) { |
350 | t_socket sock; | 365 | t_socket sock; |
351 | const char *err = inet_trycreate(&sock, domain, SOCK_STREAM); | 366 | const char *err = inet_trycreate(&sock, family, SOCK_STREAM); |
352 | /* try to allocate a system socket */ | 367 | /* try to allocate a system socket */ |
353 | if (!err) { | 368 | if (!err) { |
354 | /* allocate tcp object */ | 369 | /* allocate tcp object */ |
@@ -357,7 +372,7 @@ static int tcp_create(lua_State *L, int domain) { | |||
357 | auxiliar_setclass(L, "tcp{master}", -1); | 372 | auxiliar_setclass(L, "tcp{master}", -1); |
358 | /* initialize remaining structure fields */ | 373 | /* initialize remaining structure fields */ |
359 | socket_setnonblocking(&sock); | 374 | socket_setnonblocking(&sock); |
360 | if (domain == PF_INET6) { | 375 | if (family == PF_INET6) { |
361 | int yes = 1; | 376 | int yes = 1; |
362 | setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, | 377 | setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, |
363 | (void *)&yes, sizeof(yes)); | 378 | (void *)&yes, sizeof(yes)); |
@@ -367,7 +382,7 @@ static int tcp_create(lua_State *L, int domain) { | |||
367 | (p_error) socket_ioerror, &tcp->sock); | 382 | (p_error) socket_ioerror, &tcp->sock); |
368 | timeout_init(&tcp->tm, -1, -1); | 383 | timeout_init(&tcp->tm, -1, -1); |
369 | buffer_init(&tcp->buf, &tcp->io, &tcp->tm); | 384 | buffer_init(&tcp->buf, &tcp->io, &tcp->tm); |
370 | tcp->domain = domain; | 385 | tcp->family = family; |
371 | return 1; | 386 | return 1; |
372 | } else { | 387 | } else { |
373 | lua_pushnil(L); | 388 | lua_pushnil(L); |
@@ -25,7 +25,7 @@ typedef struct t_tcp_ { | |||
25 | t_io io; | 25 | t_io io; |
26 | t_buffer buf; | 26 | t_buffer buf; |
27 | t_timeout tm; | 27 | t_timeout tm; |
28 | int domain; | 28 | int family; |
29 | } t_tcp; | 29 | } t_tcp; |
30 | 30 | ||
31 | typedef t_tcp *p_tcp; | 31 | typedef t_tcp *p_tcp; |
diff --git a/src/timeout.c b/src/timeout.c index a3f1318..c7354b5 100644 --- a/src/timeout.c +++ b/src/timeout.c | |||
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Timeout management functions | 2 | * Timeout management functions |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: timeout.c,v 1.31 2009/05/27 09:31:35 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include <stdio.h> | 5 | #include <stdio.h> |
8 | #include <limits.h> | 6 | #include <limits.h> |
@@ -2,7 +2,6 @@ | |||
2 | -- Unified SMTP/FTP subsystem | 2 | -- Unified SMTP/FTP subsystem |
3 | -- LuaSocket toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id: tp.lua,v 1.23 2009/05/27 09:31:35 diego Exp $ | ||
6 | ----------------------------------------------------------------------------- | 5 | ----------------------------------------------------------------------------- |
7 | 6 | ||
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * UDP object | 2 | * UDP object |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: udp.c,v 1.30 2009/05/27 09:31:35 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include <string.h> | 5 | #include <string.h> |
8 | 6 | ||
@@ -32,6 +30,7 @@ static int meth_send(lua_State *L); | |||
32 | static int meth_sendto(lua_State *L); | 30 | static int meth_sendto(lua_State *L); |
33 | static int meth_receive(lua_State *L); | 31 | static int meth_receive(lua_State *L); |
34 | static int meth_receivefrom(lua_State *L); | 32 | static int meth_receivefrom(lua_State *L); |
33 | static int meth_getfamily(lua_State *L); | ||
35 | static int meth_getsockname(lua_State *L); | 34 | static int meth_getsockname(lua_State *L); |
36 | static int meth_getpeername(lua_State *L); | 35 | static int meth_getpeername(lua_State *L); |
37 | static int meth_setsockname(lua_State *L); | 36 | static int meth_setsockname(lua_State *L); |
@@ -50,6 +49,7 @@ static luaL_Reg udp_methods[] = { | |||
50 | {"__tostring", auxiliar_tostring}, | 49 | {"__tostring", auxiliar_tostring}, |
51 | {"close", meth_close}, | 50 | {"close", meth_close}, |
52 | {"dirty", meth_dirty}, | 51 | {"dirty", meth_dirty}, |
52 | {"getfamily", meth_getfamily}, | ||
53 | {"getfd", meth_getfd}, | 53 | {"getfd", meth_getfd}, |
54 | {"getpeername", meth_getpeername}, | 54 | {"getpeername", meth_getpeername}, |
55 | {"getsockname", meth_getsockname}, | 55 | {"getsockname", meth_getsockname}, |
@@ -227,6 +227,21 @@ static int meth_receivefrom(lua_State *L) { | |||
227 | } | 227 | } |
228 | 228 | ||
229 | /*-------------------------------------------------------------------------*\ | 229 | /*-------------------------------------------------------------------------*\ |
230 | * Returns family as string | ||
231 | \*-------------------------------------------------------------------------*/ | ||
232 | static int meth_getfamily(lua_State *L) | ||
233 | { | ||
234 | p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1); | ||
235 | if (udp->family == PF_INET6) { | ||
236 | lua_pushliteral(L, "inet6"); | ||
237 | return 1; | ||
238 | } else { | ||
239 | lua_pushliteral(L, "inet4"); | ||
240 | return 1; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | /*-------------------------------------------------------------------------*\ | ||
230 | * Select support methods | 245 | * Select support methods |
231 | \*-------------------------------------------------------------------------*/ | 246 | \*-------------------------------------------------------------------------*/ |
232 | static int meth_getfd(lua_State *L) { | 247 | static int meth_getfd(lua_State *L) { |
@@ -302,7 +317,7 @@ static int meth_setpeername(lua_State *L) { | |||
302 | memset(&connecthints, 0, sizeof(connecthints)); | 317 | memset(&connecthints, 0, sizeof(connecthints)); |
303 | connecthints.ai_socktype = SOCK_DGRAM; | 318 | connecthints.ai_socktype = SOCK_DGRAM; |
304 | /* make sure we try to connect only to the same family */ | 319 | /* make sure we try to connect only to the same family */ |
305 | connecthints.ai_family = udp->domain; | 320 | connecthints.ai_family = udp->family; |
306 | err = inet_tryconnect(&udp->sock, address, port, | 321 | err = inet_tryconnect(&udp->sock, address, port, |
307 | tm, &connecthints); | 322 | tm, &connecthints); |
308 | if (err) { | 323 | if (err) { |
@@ -338,7 +353,7 @@ static int meth_setsockname(lua_State *L) { | |||
338 | struct addrinfo bindhints; | 353 | struct addrinfo bindhints; |
339 | memset(&bindhints, 0, sizeof(bindhints)); | 354 | memset(&bindhints, 0, sizeof(bindhints)); |
340 | bindhints.ai_socktype = SOCK_DGRAM; | 355 | bindhints.ai_socktype = SOCK_DGRAM; |
341 | bindhints.ai_family = udp->domain; | 356 | bindhints.ai_family = udp->family; |
342 | bindhints.ai_flags = AI_PASSIVE; | 357 | bindhints.ai_flags = AI_PASSIVE; |
343 | err = inet_trybind(&udp->sock, address, port, &bindhints); | 358 | err = inet_trybind(&udp->sock, address, port, &bindhints); |
344 | if (err) { | 359 | if (err) { |
@@ -356,9 +371,9 @@ static int meth_setsockname(lua_State *L) { | |||
356 | /*-------------------------------------------------------------------------*\ | 371 | /*-------------------------------------------------------------------------*\ |
357 | * Creates a master udp object | 372 | * Creates a master udp object |
358 | \*-------------------------------------------------------------------------*/ | 373 | \*-------------------------------------------------------------------------*/ |
359 | static int udp_create(lua_State *L, int domain) { | 374 | static int udp_create(lua_State *L, int family) { |
360 | t_socket sock; | 375 | t_socket sock; |
361 | const char *err = inet_trycreate(&sock, domain, SOCK_DGRAM); | 376 | const char *err = inet_trycreate(&sock, family, SOCK_DGRAM); |
362 | /* try to allocate a system socket */ | 377 | /* try to allocate a system socket */ |
363 | if (!err) { | 378 | if (!err) { |
364 | /* allocate udp object */ | 379 | /* allocate udp object */ |
@@ -366,14 +381,14 @@ static int udp_create(lua_State *L, int domain) { | |||
366 | auxiliar_setclass(L, "udp{unconnected}", -1); | 381 | auxiliar_setclass(L, "udp{unconnected}", -1); |
367 | /* initialize remaining structure fields */ | 382 | /* initialize remaining structure fields */ |
368 | socket_setnonblocking(&sock); | 383 | socket_setnonblocking(&sock); |
369 | if (domain == PF_INET6) { | 384 | if (family == PF_INET6) { |
370 | int yes = 1; | 385 | int yes = 1; |
371 | setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, | 386 | setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, |
372 | (void *)&yes, sizeof(yes)); | 387 | (void *)&yes, sizeof(yes)); |
373 | } | 388 | } |
374 | udp->sock = sock; | 389 | udp->sock = sock; |
375 | timeout_init(&udp->tm, -1, -1); | 390 | timeout_init(&udp->tm, -1, -1); |
376 | udp->domain = domain; | 391 | udp->family = family; |
377 | return 1; | 392 | return 1; |
378 | } else { | 393 | } else { |
379 | lua_pushnil(L); | 394 | lua_pushnil(L); |
@@ -23,7 +23,7 @@ | |||
23 | typedef struct t_udp_ { | 23 | typedef struct t_udp_ { |
24 | t_socket sock; | 24 | t_socket sock; |
25 | t_timeout tm; | 25 | t_timeout tm; |
26 | int domain; | 26 | int family; |
27 | } t_udp; | 27 | } t_udp; |
28 | typedef t_udp *p_udp; | 28 | typedef t_udp *p_udp; |
29 | 29 | ||
@@ -1,8 +1,6 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Unix domain socket | 2 | * Unix domain socket |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | ||
5 | * RCS ID: $Id: unix.c,v 1.14 2009/05/27 09:31:35 diego Exp $ | ||
6 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
7 | #include <string.h> | 5 | #include <string.h> |
8 | 6 | ||
diff --git a/src/url.lua b/src/url.lua index 1e59771..1bfecad 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 toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id: url.lua,v 1.38 2006/04/03 04:45:42 diego Exp $ | ||
6 | ----------------------------------------------------------------------------- | 5 | ----------------------------------------------------------------------------- |
7 | 6 | ||
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
@@ -16,7 +15,7 @@ module("socket.url") | |||
16 | ----------------------------------------------------------------------------- | 15 | ----------------------------------------------------------------------------- |
17 | -- Module version | 16 | -- Module version |
18 | ----------------------------------------------------------------------------- | 17 | ----------------------------------------------------------------------------- |
19 | _VERSION = "URL 1.0.1" | 18 | _VERSION = "URL 1.0.2" |
20 | 19 | ||
21 | ----------------------------------------------------------------------------- | 20 | ----------------------------------------------------------------------------- |
22 | -- Encodes a string into its escaped hexadecimal representation | 21 | -- Encodes a string into its escaped hexadecimal representation |
@@ -142,7 +141,7 @@ function parse(url, default) | |||
142 | parsed.authority = n | 141 | parsed.authority = n |
143 | return "" | 142 | return "" |
144 | end) | 143 | end) |
145 | -- get query stringing | 144 | -- get query string |
146 | url = string.gsub(url, "%?(.*)", function(q) | 145 | url = string.gsub(url, "%?(.*)", function(q) |
147 | parsed.query = q | 146 | parsed.query = q |
148 | return "" | 147 | return "" |
@@ -158,9 +157,12 @@ function parse(url, default) | |||
158 | if not authority then return parsed end | 157 | if not authority then return parsed end |
159 | authority = string.gsub(authority,"^([^@]*)@", | 158 | authority = string.gsub(authority,"^([^@]*)@", |
160 | function(u) parsed.userinfo = u; return "" end) | 159 | function(u) parsed.userinfo = u; return "" end) |
161 | authority = string.gsub(authority, ":([^:]*)$", | 160 | authority = string.gsub(authority, ":([^:%]]*)$", |
162 | function(p) parsed.port = p; return "" end) | 161 | function(p) parsed.port = p; return "" end) |
163 | if authority ~= "" then parsed.host = authority end | 162 | if authority ~= "" then |
163 | -- IPv6? | ||
164 | parsed.host = string.match(authority, "^%[(.+)%]$") or authority | ||
165 | end | ||
164 | local userinfo = parsed.userinfo | 166 | local userinfo = parsed.userinfo |
165 | if not userinfo then return parsed end | 167 | if not userinfo then return parsed end |
166 | userinfo = string.gsub(userinfo, ":([^:]*)$", | 168 | userinfo = string.gsub(userinfo, ":([^:]*)$", |
@@ -185,6 +187,9 @@ function build(parsed) | |||
185 | local authority = parsed.authority | 187 | local authority = parsed.authority |
186 | if parsed.host then | 188 | if parsed.host then |
187 | authority = parsed.host | 189 | authority = parsed.host |
190 | if string.find(authority, ":") then -- IPv6? | ||
191 | authority = "[" .. authority .. "]" | ||
192 | end | ||
188 | if parsed.port then authority = authority .. ":" .. parsed.port end | 193 | if parsed.port then authority = authority .. ":" .. parsed.port end |
189 | local userinfo = parsed.userinfo | 194 | local userinfo = parsed.userinfo |
190 | if parsed.user then | 195 | if parsed.user then |
diff --git a/src/usocket.c b/src/usocket.c index bf2d19c..80d4d70 100644 --- a/src/usocket.c +++ b/src/usocket.c | |||
@@ -5,8 +5,6 @@ | |||
5 | * The code is now interrupt-safe. | 5 | * The code is now interrupt-safe. |
6 | * The penalty of calling select to avoid busy-wait is only paid when | 6 | * The penalty of calling select to avoid busy-wait is only paid when |
7 | * the I/O call fail in the first place. | 7 | * the I/O call fail in the first place. |
8 | * | ||
9 | * RCS ID: $Id: usocket.c,v 1.38 2007/10/13 23:55:20 diego Exp $ | ||
10 | \*=========================================================================*/ | 8 | \*=========================================================================*/ |
11 | #include <string.h> | 9 | #include <string.h> |
12 | #include <signal.h> | 10 | #include <signal.h> |
diff --git a/src/wsocket.c b/src/wsocket.c index c82882a..12e6352 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
@@ -4,8 +4,6 @@ | |||
4 | * | 4 | * |
5 | * The penalty of calling select to avoid busy-wait is only paid when | 5 | * The penalty of calling select to avoid busy-wait is only paid when |
6 | * the I/O call fail in the first place. | 6 | * the I/O call fail in the first place. |
7 | * | ||
8 | * RCS ID: $Id: wsocket.c,v 1.36 2007/06/11 23:44:54 diego Exp $ | ||
9 | \*=========================================================================*/ | 7 | \*=========================================================================*/ |
10 | #include <string.h> | 8 | #include <string.h> |
11 | 9 | ||