diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/http.lua | 2 | ||||
-rw-r--r-- | src/luasocket.h | 3 | ||||
-rw-r--r-- | src/mime.h | 3 | ||||
-rw-r--r-- | src/mime.lua | 32 | ||||
-rw-r--r-- | src/socket.lua | 3 | ||||
-rw-r--r-- | src/tcp.c | 6 | ||||
-rw-r--r-- | src/udp.c | 6 | ||||
-rw-r--r-- | src/usocket.c | 6 | ||||
-rw-r--r-- | src/wsocket.c | 6 |
9 files changed, 32 insertions, 35 deletions
diff --git a/src/http.lua b/src/http.lua index 9c568bc..cdb435d 100644 --- a/src/http.lua +++ b/src/http.lua | |||
@@ -22,8 +22,6 @@ TIMEOUT = 60 | |||
22 | PORT = 80 | 22 | PORT = 80 |
23 | -- user agent field sent in request | 23 | -- user agent field sent in request |
24 | USERAGENT = socket.VERSION | 24 | USERAGENT = socket.VERSION |
25 | -- block size used in transfers | ||
26 | BLOCKSIZE = 2048 | ||
27 | 25 | ||
28 | ----------------------------------------------------------------------------- | 26 | ----------------------------------------------------------------------------- |
29 | -- Low level HTTP API | 27 | -- Low level HTTP API |
diff --git a/src/luasocket.h b/src/luasocket.h index 6d30605..35dc3d9 100644 --- a/src/luasocket.h +++ b/src/luasocket.h | |||
@@ -25,7 +25,10 @@ | |||
25 | /*-------------------------------------------------------------------------*\ | 25 | /*-------------------------------------------------------------------------*\ |
26 | * Initializes the library. | 26 | * Initializes the library. |
27 | \*-------------------------------------------------------------------------*/ | 27 | \*-------------------------------------------------------------------------*/ |
28 | #ifndef LUASOCKET_LIBNAME | ||
28 | #define LUASOCKET_LIBNAME "socket" | 29 | #define LUASOCKET_LIBNAME "socket" |
30 | #endif | ||
31 | |||
29 | LUASOCKET_API int luaopen_socket(lua_State *L); | 32 | LUASOCKET_API int luaopen_socket(lua_State *L); |
30 | 33 | ||
31 | #endif /* LUASOCKET_H */ | 34 | #endif /* LUASOCKET_H */ |
@@ -19,7 +19,10 @@ | |||
19 | #define MIME_API extern | 19 | #define MIME_API extern |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | #ifndef MIME_LIBNAME | ||
22 | #define MIME_LIBNAME "mime" | 23 | #define MIME_LIBNAME "mime" |
24 | #endif | ||
25 | |||
23 | MIME_API int luaopen_mime(lua_State *L); | 26 | MIME_API int luaopen_mime(lua_State *L); |
24 | 27 | ||
25 | #endif /* MIME_H */ | 28 | #endif /* MIME_H */ |
diff --git a/src/mime.lua b/src/mime.lua index 345bd25..fcdc358 100644 --- a/src/mime.lua +++ b/src/mime.lua | |||
@@ -12,9 +12,9 @@ local mime = requirelib("mime", "luaopen_mime", getfenv(1)) | |||
12 | local ltn12 = require("ltn12") | 12 | local ltn12 = require("ltn12") |
13 | 13 | ||
14 | -- encode, decode and wrap algorithm tables | 14 | -- encode, decode and wrap algorithm tables |
15 | encodet = {} | 15 | mime.encodet = {} |
16 | decodet = {} | 16 | mime.decodet = {} |
17 | wrapt = {} | 17 | mime.wrapt = {} |
18 | 18 | ||
19 | -- creates a function that chooses a filter by name from a given table | 19 | -- creates a function that chooses a filter by name from a given table |
20 | local function choose(table) | 20 | local function choose(table) |
@@ -29,47 +29,47 @@ local function choose(table) | |||
29 | end | 29 | end |
30 | 30 | ||
31 | -- define the encoding filters | 31 | -- define the encoding filters |
32 | encodet['base64'] = function() | 32 | mime.encodet['base64'] = function() |
33 | return ltn12.filter.cycle(b64, "") | 33 | return ltn12.filter.cycle(b64, "") |
34 | end | 34 | end |
35 | 35 | ||
36 | encodet['quoted-printable'] = function(mode) | 36 | mime.encodet['quoted-printable'] = function(mode) |
37 | return ltn12.filter.cycle(qp, "", | 37 | return ltn12.filter.cycle(qp, "", |
38 | (mode == "binary") and "=0D=0A" or "\r\n") | 38 | (mode == "binary") and "=0D=0A" or "\r\n") |
39 | end | 39 | end |
40 | 40 | ||
41 | -- define the decoding filters | 41 | -- define the decoding filters |
42 | decodet['base64'] = function() | 42 | mime.decodet['base64'] = function() |
43 | return ltn12.filter.cycle(unb64, "") | 43 | return ltn12.filter.cycle(unb64, "") |
44 | end | 44 | end |
45 | 45 | ||
46 | decodet['quoted-printable'] = function() | 46 | mime.decodet['quoted-printable'] = function() |
47 | return ltn12.filter.cycle(unqp, "") | 47 | return ltn12.filter.cycle(unqp, "") |
48 | end | 48 | end |
49 | 49 | ||
50 | -- define the line-wrap filters | 50 | -- define the line-wrap filters |
51 | wrapt['text'] = function(length) | 51 | mime.wrapt['text'] = function(length) |
52 | length = length or 76 | 52 | length = length or 76 |
53 | return ltn12.filter.cycle(wrp, length, length) | 53 | return ltn12.filter.cycle(wrp, length, length) |
54 | end | 54 | end |
55 | wrapt['base64'] = wrapt['text'] | 55 | mime.wrapt['base64'] = wrapt['text'] |
56 | wrapt['default'] = wrapt['text'] | 56 | mime.wrapt['default'] = wrapt['text'] |
57 | 57 | ||
58 | wrapt['quoted-printable'] = function() | 58 | mime.wrapt['quoted-printable'] = function() |
59 | return ltn12.filter.cycle(qpwrp, 76, 76) | 59 | return ltn12.filter.cycle(qpwrp, 76, 76) |
60 | end | 60 | end |
61 | 61 | ||
62 | -- function that choose the encoding, decoding or wrap algorithm | 62 | -- function that choose the encoding, decoding or wrap algorithm |
63 | encode = choose(encodet) | 63 | mime.encode = choose(encodet) |
64 | decode = choose(decodet) | 64 | mime.decode = choose(decodet) |
65 | wrap = choose(wrapt) | 65 | mime.wrap = choose(wrapt) |
66 | 66 | ||
67 | -- define the end-of-line normalization filter | 67 | -- define the end-of-line normalization filter |
68 | function normalize(marker) | 68 | function mime.normalize(marker) |
69 | return ltn12.filter.cycle(eol, 0, marker) | 69 | return ltn12.filter.cycle(eol, 0, marker) |
70 | end | 70 | end |
71 | 71 | ||
72 | -- high level stuffing filter | 72 | -- high level stuffing filter |
73 | function stuff() | 73 | function mime.stuff() |
74 | return ltn12.filter.cycle(dot, 2) | 74 | return ltn12.filter.cycle(dot, 2) |
75 | end | 75 | end |
diff --git a/src/socket.lua b/src/socket.lua index 4d64651..b3889d7 100644 --- a/src/socket.lua +++ b/src/socket.lua | |||
@@ -8,7 +8,6 @@ | |||
8 | -- Load LuaSocket from dynamic library | 8 | -- Load LuaSocket from dynamic library |
9 | ----------------------------------------------------------------------------- | 9 | ----------------------------------------------------------------------------- |
10 | local socket = requirelib("luasocket", "luaopen_socket", getfenv(1)) | 10 | local socket = requirelib("luasocket", "luaopen_socket", getfenv(1)) |
11 | _LOADED["socket"] = socket | ||
12 | 11 | ||
13 | ----------------------------------------------------------------------------- | 12 | ----------------------------------------------------------------------------- |
14 | -- Auxiliar functions | 13 | -- Auxiliar functions |
@@ -31,7 +30,7 @@ function socket.bind(host, port, backlog) | |||
31 | sock:setoption("reuseaddr", true) | 30 | sock:setoption("reuseaddr", true) |
32 | local res, err = sock:bind(host, port) | 31 | local res, err = sock:bind(host, port) |
33 | if not res then return nil, err end | 32 | if not res then return nil, err end |
34 | backlog = backlog or 1 | 33 | backlog = backlog or 32 |
35 | res, err = sock:listen(backlog) | 34 | res, err = sock:listen(backlog) |
36 | if not res then return nil, err end | 35 | if not res then return nil, err end |
37 | return sock | 36 | return sock |
@@ -130,7 +130,7 @@ static int meth_setoption(lua_State *L) | |||
130 | static int meth_getfd(lua_State *L) | 130 | static int meth_getfd(lua_State *L) |
131 | { | 131 | { |
132 | p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1); | 132 | p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1); |
133 | lua_pushnumber(L, tcp->sock); | 133 | lua_pushnumber(L, (int) tcp->sock); |
134 | return 1; | 134 | return 1; |
135 | } | 135 | } |
136 | 136 | ||
@@ -164,6 +164,7 @@ static int meth_accept(lua_State *L) | |||
164 | p_tcp clnt = lua_newuserdata(L, sizeof(t_tcp)); | 164 | p_tcp clnt = lua_newuserdata(L, sizeof(t_tcp)); |
165 | aux_setclass(L, "tcp{client}", -1); | 165 | aux_setclass(L, "tcp{client}", -1); |
166 | /* initialize structure fields */ | 166 | /* initialize structure fields */ |
167 | sock_setnonblocking(&sock); | ||
167 | clnt->sock = sock; | 168 | clnt->sock = sock; |
168 | io_init(&clnt->io, (p_send)sock_send, (p_recv)sock_recv, &clnt->sock); | 169 | io_init(&clnt->io, (p_send)sock_send, (p_recv)sock_recv, &clnt->sock); |
169 | tm_init(&clnt->tm, -1, -1); | 170 | tm_init(&clnt->tm, -1, -1); |
@@ -310,10 +311,11 @@ static int global_create(lua_State *L) | |||
310 | if (!err) { | 311 | if (!err) { |
311 | /* allocate tcp object */ | 312 | /* allocate tcp object */ |
312 | p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); | 313 | p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); |
313 | tcp->sock = sock; | ||
314 | /* set its type as master object */ | 314 | /* set its type as master object */ |
315 | aux_setclass(L, "tcp{master}", -1); | 315 | aux_setclass(L, "tcp{master}", -1); |
316 | /* initialize remaining structure fields */ | 316 | /* initialize remaining structure fields */ |
317 | sock_setnonblocking(&sock); | ||
318 | tcp->sock = sock; | ||
317 | io_init(&tcp->io, (p_send) sock_send, (p_recv) sock_recv, &tcp->sock); | 319 | io_init(&tcp->io, (p_send) sock_send, (p_recv) sock_recv, &tcp->sock); |
318 | tm_init(&tcp->tm, -1, -1); | 320 | tm_init(&tcp->tm, -1, -1); |
319 | buf_init(&tcp->buf, &tcp->io, &tcp->tm); | 321 | buf_init(&tcp->buf, &tcp->io, &tcp->tm); |
@@ -208,7 +208,7 @@ static int meth_receivefrom(lua_State *L) | |||
208 | static int meth_getfd(lua_State *L) | 208 | static int meth_getfd(lua_State *L) |
209 | { | 209 | { |
210 | p_udp udp = (p_udp) aux_checkgroup(L, "udp{any}", 1); | 210 | p_udp udp = (p_udp) aux_checkgroup(L, "udp{any}", 1); |
211 | lua_pushnumber(L, udp->sock); | 211 | lua_pushnumber(L, (int) udp->sock); |
212 | return 1; | 212 | return 1; |
213 | } | 213 | } |
214 | 214 | ||
@@ -328,10 +328,10 @@ static int global_create(lua_State *L) | |||
328 | if (!err) { | 328 | if (!err) { |
329 | /* allocate tcp object */ | 329 | /* allocate tcp object */ |
330 | p_udp udp = (p_udp) lua_newuserdata(L, sizeof(t_udp)); | 330 | p_udp udp = (p_udp) lua_newuserdata(L, sizeof(t_udp)); |
331 | udp->sock = sock; | ||
332 | /* set its type as master object */ | ||
333 | aux_setclass(L, "udp{unconnected}", -1); | 331 | aux_setclass(L, "udp{unconnected}", -1); |
334 | /* initialize remaining structure fields */ | 332 | /* initialize remaining structure fields */ |
333 | sock_setnonblocking(&sock); | ||
334 | udp->sock = sock; | ||
335 | tm_init(&udp->tm, -1, -1); | 335 | tm_init(&udp->tm, -1, -1); |
336 | return 1; | 336 | return 1; |
337 | } else { | 337 | } else { |
diff --git a/src/usocket.c b/src/usocket.c index ea0f172..617b1ea 100644 --- a/src/usocket.c +++ b/src/usocket.c | |||
@@ -81,7 +81,6 @@ const char *sock_create(p_sock ps, int domain, int type, int protocol) | |||
81 | t_sock sock = socket(domain, type, protocol); | 81 | t_sock sock = socket(domain, type, protocol); |
82 | if (sock == SOCK_INVALID) return sock_createstrerror(errno); | 82 | if (sock == SOCK_INVALID) return sock_createstrerror(errno); |
83 | *ps = sock; | 83 | *ps = sock; |
84 | sock_setnonblocking(ps); | ||
85 | return NULL; | 84 | return NULL; |
86 | } | 85 | } |
87 | 86 | ||
@@ -178,10 +177,7 @@ const char *sock_accept(p_sock ps, p_sock pa, SA *addr, | |||
178 | do *pa = accept(sock, addr, addr_len); | 177 | do *pa = accept(sock, addr, addr_len); |
179 | while (*pa < 0 && errno == EINTR); | 178 | while (*pa < 0 && errno == EINTR); |
180 | /* if result is valid, we are done */ | 179 | /* if result is valid, we are done */ |
181 | if (*pa != SOCK_INVALID) { | 180 | if (*pa != SOCK_INVALID) return NULL; |
182 | sock_setnonblocking(pa); | ||
183 | return NULL; | ||
184 | } | ||
185 | /* find out if we failed for a fatal reason */ | 181 | /* find out if we failed for a fatal reason */ |
186 | if (errno != EWOULDBLOCK && errno != ECONNABORTED) | 182 | if (errno != EWOULDBLOCK && errno != ECONNABORTED) |
187 | return sock_acceptstrerror(errno); | 183 | return sock_acceptstrerror(errno); |
diff --git a/src/wsocket.c b/src/wsocket.c index 84a49dc..e276fe0 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
@@ -88,7 +88,6 @@ const char *sock_create(p_sock ps, int domain, int type, int protocol) | |||
88 | if (sock == SOCK_INVALID) | 88 | if (sock == SOCK_INVALID) |
89 | return sock_createstrerror(WSAGetLastError()); | 89 | return sock_createstrerror(WSAGetLastError()); |
90 | *ps = sock; | 90 | *ps = sock; |
91 | sock_setnonblocking(ps); | ||
92 | return NULL; | 91 | return NULL; |
93 | } | 92 | } |
94 | 93 | ||
@@ -177,10 +176,7 @@ const char *sock_accept(p_sock ps, p_sock pa, SA *addr, | |||
177 | /* try to get client socket */ | 176 | /* try to get client socket */ |
178 | *pa = accept(sock, addr, addr_len); | 177 | *pa = accept(sock, addr, addr_len); |
179 | /* if return is valid, we are done */ | 178 | /* if return is valid, we are done */ |
180 | if (*pa != SOCK_INVALID) { | 179 | if (*pa != SOCK_INVALID) return NULL; |
181 | sock_setnonblocking(pa); | ||
182 | return NULL; | ||
183 | } | ||
184 | /* optimization */ | 180 | /* optimization */ |
185 | if (timeout == 0) return io_strerror(IO_TIMEOUT); | 181 | if (timeout == 0) return io_strerror(IO_TIMEOUT); |
186 | /* otherwise find out why we failed */ | 182 | /* otherwise find out why we failed */ |