diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-05-30 21:36:22 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-05-30 21:36:22 +0000 |
commit | 5ca1049ab47f3f9ff9157f71af9072f04a637500 (patch) | |
tree | 24fcb14f2890900a4a709312ab25bfc2c14a3939 | |
parent | c23240726e3044e3eaa32a82a999b754c08bc183 (diff) | |
download | luasocket-5ca1049ab47f3f9ff9157f71af9072f04a637500.tar.gz luasocket-5ca1049ab47f3f9ff9157f71af9072f04a637500.tar.bz2 luasocket-5ca1049ab47f3f9ff9157f71af9072f04a637500.zip |
Fine tuning the "require" business.
-rw-r--r-- | TODO | 118 | ||||
-rw-r--r-- | etc/get.lua | 5 | ||||
-rw-r--r-- | samples/listener.lua | 15 | ||||
-rw-r--r-- | samples/talker.lua | 13 | ||||
-rw-r--r-- | samples/tinyirc.lua | 19 | ||||
-rw-r--r-- | src/ftp.lua | 11 | ||||
-rw-r--r-- | src/http.lua | 2 | ||||
-rw-r--r-- | src/luasocket.c | 17 | ||||
-rw-r--r-- | src/mime.c | 3 | ||||
-rw-r--r-- | src/select.h | 8 | ||||
-rw-r--r-- | src/smtp.lua | 5 | ||||
-rw-r--r-- | src/socket.h | 1 | ||||
-rw-r--r-- | src/tp.lua | 6 | ||||
-rw-r--r-- | src/url.lua | 3 | ||||
-rw-r--r-- | src/usocket.c | 8 | ||||
-rw-r--r-- | src/wsocket.c | 9 | ||||
-rw-r--r-- | test/mimetest.lua | 6 |
17 files changed, 133 insertions, 116 deletions
@@ -1,54 +1,14 @@ | |||
1 | * should be interrupt-safe | 1 | ajeitar os README.* |
2 | * notice the change in callback conventions | 2 | ajeitar select. upvalue nao tem nada a ver... |
3 | * new mime module replacing old code module (faster, more functionality) | ||
4 | * new socket options (many) | ||
5 | * only allocate in case of success | ||
6 | * optimize for success (only call select if fails) | ||
7 | * add proxy support to http | ||
8 | * add gethostname | ||
9 | * local connect | ||
10 | * connect with timeout | ||
11 | * change code to mime | ||
12 | * change stay to redirect | ||
13 | * add shutdown | ||
14 | * change send/recv to avoid using select | ||
15 | * O location do "redirect" pode ser relativo ao servidor atual (não pode, | ||
16 | mas os servidores fazem merda...) | ||
17 | * Ajeitar para Lua 5.0 | ||
18 | * Padronizar os retornos de funccao | ||
19 | * Separar as classes em arquivos | ||
20 | * Retorno de sendto em datagram sockets pode ser refused | ||
21 | * select sets are now associative | ||
22 | * colocar pump.all, pump.step | ||
23 | * mudar ltn12.html e usar o exemplo source.cat que está muito melhor. | ||
24 | * break smtp.send into c = smtp.open, c:send() c:close() | ||
25 | * fazer com que a socket.source e socket.sink sejam "selectable". | ||
26 | * change mime.eol to output marker on detection of first candidate, instead | ||
27 | of on the second. that way it works in one pass for strings that end with | ||
28 | one candidate. | ||
29 | * unify backbone of smtp and ftp | ||
30 | * unify filter and send/receive callback. new sink/source/pump idea. | ||
31 | * get rid of aux_optlstring | ||
32 | * get rid of unpack in mime.lua | ||
33 | * create socket.(sink|source).simplify | ||
34 | * break chain into a simpler binary chain and a complex (recursive) one. | ||
35 | * Create a passive mode option for the FTP (good for firewall). | ||
36 | * Modules should return their namespace table in the end of the chunk. | ||
37 | |||
38 | |||
39 | get.lua precisa de ftp.get com url e sink | ||
40 | make sure filter.chain fails gracefully. | 3 | make sure filter.chain fails gracefully. |
41 | ajeitar o manual sobre select, mais liberal agora | 4 | ajeitar o manual sobre select, mais liberal agora |
42 | conjunto associativo | ||
43 | 5 | ||
44 | falar sobre encodet/wrapt/decodet no manual sobre mime | 6 | falar sobre encodet/wrapt/decodet no manual sobre mime |
45 | 7 | ||
46 | |||
47 | RECEIVE MUDOU!!! (partial stuff) COLOCAR NO MANUAL. | 8 | RECEIVE MUDOU!!! (partial stuff) COLOCAR NO MANUAL. |
48 | HTTP.lua mudou bastante também. | 9 | HTTP.lua mudou bastante também. |
49 | pump.step usado em todo mundo que recebe source ou sink | 10 | pump.step usado em todo mundo que recebe source ou sink |
50 | 11 | ||
51 | colocar um userdata com gc metamethod pra chamar sock_close (WSAClose); | ||
52 | sources ans sinks are always simple in http and ftp and smtp | 12 | sources ans sinks are always simple in http and ftp and smtp |
53 | expose encode/decode tables to provide extensibility for mime module | 13 | expose encode/decode tables to provide extensibility for mime module |
54 | use coroutines instead of fancy filters | 14 | use coroutines instead of fancy filters |
@@ -60,6 +20,7 @@ pop3??? | |||
60 | add socket.TIMEOUT to be default timeout? | 20 | add socket.TIMEOUT to be default timeout? |
61 | 21 | ||
62 | manual | 22 | manual |
23 | compatibility: select sets are associative | ||
63 | add socket.connect and socket.bind to the manual | 24 | add socket.connect and socket.bind to the manual |
64 | say what a nil callback does for http | 25 | say what a nil callback does for http |
65 | check all occurences of it's | 26 | check all occurences of it's |
@@ -87,24 +48,9 @@ tests | |||
87 | check for interrupts | 48 | check for interrupts |
88 | 49 | ||
89 | wrp can't break lines in the middle of a line break. | 50 | wrp can't break lines in the middle of a line break. |
90 | call select before accept, not after, dumbass! | ||
91 | get rid of setnonblocking/setblocking in the bind function | ||
92 | close has to block... | ||
93 | fmt is not a good name | ||
94 | change wrap() to accept a number and default to "character" | ||
95 | move gethostname to dns table | ||
96 | get rid of _cb in name of functions? | ||
97 | trust character constants in mime.c? noooooo. | ||
98 | smtp.lua needs stuff filter | ||
99 | 51 | ||
100 | add comments into each C module. | 52 | add comments into each C module. |
101 | new option.c module to put all options (TCP and UDP share...)? | ||
102 | testar os options! | 53 | testar os options! |
103 | add _tostring methods! | ||
104 | change all modules to use the new namespace scheme | ||
105 | |||
106 | write some utilities that use the code.lua module and put them | ||
107 | in etc, modify the README.etc file and makefile.dist (eol.lua is done) | ||
108 | 54 | ||
109 | use gethostname it in SMTP | 55 | use gethostname it in SMTP |
110 | 56 | ||
@@ -150,3 +96,61 @@ Ajeitar o protocolo da luaopen_socket()... sei lá qual é. | |||
150 | 96 | ||
151 | - unix 92 bytes maximo no endereço, incluindo o zero | 97 | - unix 92 bytes maximo no endereço, incluindo o zero |
152 | - unix 9216 maximo de datagram size | 98 | - unix 9216 maximo de datagram size |
99 | |||
100 | -------------- | ||
101 | these are done | ||
102 | -------------- | ||
103 | |||
104 | * should be interrupt-safe | ||
105 | * notice the change in callback conventions | ||
106 | * new mime module replacing old code module (faster, more functionality) | ||
107 | * new socket options (many) | ||
108 | * only allocate in case of success | ||
109 | * optimize for success (only call select if fails) | ||
110 | * add proxy support to http | ||
111 | * add gethostname | ||
112 | * local connect | ||
113 | * connect with timeout | ||
114 | * change code to mime | ||
115 | * change stay to redirect | ||
116 | * add shutdown | ||
117 | * change send/recv to avoid using select | ||
118 | * O location do "redirect" pode ser relativo ao servidor atual (não pode, | ||
119 | mas os servidores fazem merda...) | ||
120 | * Ajeitar para Lua 5.0 | ||
121 | * Padronizar os retornos de funccao | ||
122 | * Separar as classes em arquivos | ||
123 | * Retorno de sendto em datagram sockets pode ser refused | ||
124 | * select sets are now associative | ||
125 | * colocar pump.all, pump.step | ||
126 | * mudar ltn12.html e usar o exemplo source.cat que está muito melhor. | ||
127 | * break smtp.send into c = smtp.open, c:send() c:close() | ||
128 | * fazer com que a socket.source e socket.sink sejam "selectable". | ||
129 | * change mime.eol to output marker on detection of first candidate, instead | ||
130 | of on the second. that way it works in one pass for strings that end with | ||
131 | one candidate. | ||
132 | * unify backbone of smtp and ftp | ||
133 | * unify filter and send/receive callback. new sink/source/pump idea. | ||
134 | * get rid of aux_optlstring | ||
135 | * get rid of unpack in mime.lua | ||
136 | * create socket.(sink|source).simplify | ||
137 | * break chain into a simpler binary chain and a complex (recursive) one. | ||
138 | * Create a passive mode option for the FTP (good for firewall). | ||
139 | * Modules should return their namespace table in the end of the chunk. | ||
140 | * get.lua precisa de ftp.get com url e sink | ||
141 | * conjunto associativo | ||
142 | * colocar um userdata com gc metamethod pra chamar sock_close (WSAClose); | ||
143 | * call select before accept, not after, dumbass! | ||
144 | * get rid of setnonblocking/setblocking in the bind function | ||
145 | * close has to block... | ||
146 | * fmt is not a good name | ||
147 | * change wrap() to accept a number and default to "character" | ||
148 | * move gethostname to dns table | ||
149 | * get rid of _cb in name of functions? | ||
150 | * trust character constants in mime.c? yup. | ||
151 | * smtp.lua needs stuff filter | ||
152 | * new option.c module to put all options (TCP and UDP share...)? | ||
153 | * add _tostring methods! | ||
154 | * change all modules to use the new namespace scheme | ||
155 | * write some utilities that use the code.lua module and put them | ||
156 | * in etc, modify the README.etc file and makefile.dist (eol.lua is done) | ||
diff --git a/etc/get.lua b/etc/get.lua index cc270e8..35de7d7 100644 --- a/etc/get.lua +++ b/etc/get.lua | |||
@@ -106,7 +106,10 @@ function getbyftp(url, file) | |||
106 | -- only print feedback if output is not stdout | 106 | -- only print feedback if output is not stdout |
107 | -- and we don't know how big the file is | 107 | -- and we don't know how big the file is |
108 | if file then save = ltn12.sink.chain(stats(), save) end | 108 | if file then save = ltn12.sink.chain(stats(), save) end |
109 | local ret, err = socket.ftp.get {url = url, sink = save, type = "i"} | 109 | local gett = socket.url.parse(url) |
110 | gett.sink = save | ||
111 | gett.type = "i" | ||
112 | local ret, err = socket.ftp.get(gett) | ||
110 | if err then print(err) end | 113 | if err then print(err) end |
111 | end | 114 | end |
112 | 115 | ||
diff --git a/samples/listener.lua b/samples/listener.lua index dff4d25..bedbde5 100644 --- a/samples/listener.lua +++ b/samples/listener.lua | |||
@@ -4,6 +4,7 @@ | |||
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
7 | require("socket") | ||
7 | host = host or "*" | 8 | host = host or "*" |
8 | port = port or 8080 | 9 | port = port or 8080 |
9 | if arg then | 10 | if arg then |
@@ -11,18 +12,10 @@ if arg then | |||
11 | port = arg[2] or port | 12 | port = arg[2] or port |
12 | end | 13 | end |
13 | print("Binding to host '" ..host.. "' and port " ..port.. "...") | 14 | print("Binding to host '" ..host.. "' and port " ..port.. "...") |
14 | s, e = socket.bind(host, port) | 15 | s = socket.try(socket.bind(host, port)) |
15 | if not s then | 16 | i, p = socket.try(s:getsockname()) |
16 | print(e) | ||
17 | exit() | ||
18 | end | ||
19 | i, p = s:getsockname() | ||
20 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") | 17 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") |
21 | c, e = s:accept() | 18 | c = socket.try(s:accept()) |
22 | if not c then | ||
23 | print(e) | ||
24 | exit() | ||
25 | end | ||
26 | print("Connected. Here is the stuff:") | 19 | print("Connected. Here is the stuff:") |
27 | l, e = c:receive() | 20 | l, e = c:receive() |
28 | while not e do | 21 | while not e do |
diff --git a/samples/talker.lua b/samples/talker.lua index 1b0652f..94d2133 100644 --- a/samples/talker.lua +++ b/samples/talker.lua | |||
@@ -4,6 +4,7 @@ | |||
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
7 | require("socket") | ||
7 | host = host or "localhost" | 8 | host = host or "localhost" |
8 | port = port or 8080 | 9 | port = port or 8080 |
9 | if arg then | 10 | if arg then |
@@ -11,18 +12,10 @@ if arg then | |||
11 | port = arg[2] or port | 12 | port = arg[2] or port |
12 | end | 13 | end |
13 | print("Attempting connection to host '" ..host.. "' and port " ..port.. "...") | 14 | print("Attempting connection to host '" ..host.. "' and port " ..port.. "...") |
14 | c, e = socket.connect(host, port) | 15 | c = socket.try(socket.connect(host, port)) |
15 | if not c then | ||
16 | print(e) | ||
17 | os.exit() | ||
18 | end | ||
19 | print("Connected! Please type stuff (empty line to stop):") | 16 | print("Connected! Please type stuff (empty line to stop):") |
20 | l = io.read() | 17 | l = io.read() |
21 | while l and l ~= "" and not e do | 18 | while l and l ~= "" and not e do |
22 | t, e = c:send(l, "\n") | 19 | socket.try(c:send(l, "\n")) |
23 | if e then | ||
24 | print(e) | ||
25 | os.exit() | ||
26 | end | ||
27 | l = io.read() | 20 | l = io.read() |
28 | end | 21 | end |
diff --git a/samples/tinyirc.lua b/samples/tinyirc.lua index b48b90a..eac979d 100644 --- a/samples/tinyirc.lua +++ b/samples/tinyirc.lua | |||
@@ -4,6 +4,7 @@ | |||
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
7 | require("socket") | ||
7 | host = host or "*" | 8 | host = host or "*" |
8 | port1 = port1 or 8080 | 9 | port1 = port1 or 8080 |
9 | port2 = port2 or 8181 | 10 | port2 = port2 or 8181 |
@@ -13,12 +14,10 @@ if arg then | |||
13 | port2 = arg[3] or port2 | 14 | port2 = arg[3] or port2 |
14 | end | 15 | end |
15 | 16 | ||
16 | server1, error = socket.bind(host, port1) | 17 | server1 = socket.try(socket.bind(host, port1)) |
17 | assert(server1, error) | 18 | server2 = socket.try(socket.bind(host, port2)) |
18 | server1:settimeout(1) -- make sure we don't block in accept | 19 | server1:settimeout(1) -- make sure we don't block in accept |
19 | server2, error = socket.bind(host, port2) | 20 | server2:settimeout(1) |
20 | assert(server2, error) | ||
21 | server2:settimeout(1) -- make sure we don't block in accept | ||
22 | 21 | ||
23 | io.write("Servers bound\n") | 22 | io.write("Servers bound\n") |
24 | 23 | ||
@@ -49,7 +48,7 @@ set:insert(server2) | |||
49 | 48 | ||
50 | while 1 do | 49 | while 1 do |
51 | local readable, _, error = socket.select(set, nil) | 50 | local readable, _, error = socket.select(set, nil) |
52 | for _, input in readable do | 51 | for _, input in ipairs(readable) do |
53 | -- is it a server socket? | 52 | -- is it a server socket? |
54 | if input == server1 or input == server2 then | 53 | if input == server1 or input == server2 then |
55 | io.write("Waiting for clients\n") | 54 | io.write("Waiting for clients\n") |
@@ -68,10 +67,12 @@ while 1 do | |||
68 | set:remove(input) | 67 | set:remove(input) |
69 | else | 68 | else |
70 | io.write("Broadcasting line '", line, "'\n") | 69 | io.write("Broadcasting line '", line, "'\n") |
71 | __, writable, error = socket.select(nil, set, 1) | 70 | writable, error = socket.skip(1, socket.select(nil, set, 1)) |
72 | if not error then | 71 | if not error then |
73 | for ___, output in writable do | 72 | for __, output in ipairs(writable) do |
74 | output:send(line .. "\n") | 73 | if output ~= input then |
74 | output:send(line .. "\n") | ||
75 | end | ||
75 | end | 76 | end |
76 | else io.write("No client ready to receive!!!\n") end | 77 | else io.write("No client ready to receive!!!\n") end |
77 | end | 78 | end |
diff --git a/src/ftp.lua b/src/ftp.lua index 72be695..842fdbb 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
@@ -13,6 +13,7 @@ local socket = _G[LUASOCKET_LIBNAME] | |||
13 | -- require other modules | 13 | -- require other modules |
14 | require("ltn12") | 14 | require("ltn12") |
15 | require("url") | 15 | require("url") |
16 | require("tp") | ||
16 | 17 | ||
17 | -- create namespace inside LuaSocket namespace | 18 | -- create namespace inside LuaSocket namespace |
18 | socket.ftp = socket.ftp or {} | 19 | socket.ftp = socket.ftp or {} |
@@ -101,7 +102,9 @@ function metat.__index:send(sendt) | |||
101 | local data | 102 | local data |
102 | socket.try(self.pasvt or self.portt, "need port or pasv first") | 103 | socket.try(self.pasvt or self.portt, "need port or pasv first") |
103 | if self.pasvt then data = socket.try(pasv(self.pasvt)) end | 104 | if self.pasvt then data = socket.try(pasv(self.pasvt)) end |
104 | socket.try(self.tp:command(sendt.command or "stor", sendt.argument)) | 105 | local argument = sendt.argument or string.gsub(sendt.path, "^/", "") |
106 | local command = sendt.command or "stor" | ||
107 | socket.try(self.tp:command(command, argument)) | ||
105 | local code, reply = socket.try(self.tp:check{"2..", "1.."}) | 108 | local code, reply = socket.try(self.tp:check{"2..", "1.."}) |
106 | if self.portt then data = socket.try(port(self.portt)) end | 109 | if self.portt then data = socket.try(port(self.portt)) end |
107 | local step = sendt.step or ltn12.pump.step | 110 | local step = sendt.step or ltn12.pump.step |
@@ -128,7 +131,9 @@ function metat.__index:receive(recvt) | |||
128 | local data | 131 | local data |
129 | socket.try(self.pasvt or self.portt, "need port or pasv first") | 132 | socket.try(self.pasvt or self.portt, "need port or pasv first") |
130 | if self.pasvt then data = socket.try(pasv(self.pasvt)) end | 133 | if self.pasvt then data = socket.try(pasv(self.pasvt)) end |
131 | socket.try(self.tp:command(recvt.command or "retr", recvt.argument)) | 134 | local argument = recvt.argument or string.gsub(recvt.path, "^/", "") |
135 | local command = recvt.command or "retr" | ||
136 | socket.try(self.tp:command(command, argument)) | ||
132 | local code = socket.try(self.tp:check{"1..", "2.."}) | 137 | local code = socket.try(self.tp:check{"1..", "2.."}) |
133 | if self.portt then data = socket.try(port(self.portt)) end | 138 | if self.portt then data = socket.try(port(self.portt)) end |
134 | local source = socket.source("until-closed", data) | 139 | local source = socket.source("until-closed", data) |
@@ -200,8 +205,6 @@ local function parse(url) | |||
200 | putt.type = socket.skip(2, string.find(putt.params, pat)) | 205 | putt.type = socket.skip(2, string.find(putt.params, pat)) |
201 | socket.try(putt.type == "a" or putt.type == "i") | 206 | socket.try(putt.type == "a" or putt.type == "i") |
202 | end | 207 | end |
203 | -- skip first backslash in path | ||
204 | putt.argument = string.sub(putt.path, 2) | ||
205 | return putt | 208 | return putt |
206 | end | 209 | end |
207 | 210 | ||
diff --git a/src/http.lua b/src/http.lua index b372a2e..66a236d 100644 --- a/src/http.lua +++ b/src/http.lua | |||
@@ -13,6 +13,8 @@ local socket = _G[LUASOCKET_LIBNAME] | |||
13 | -- require other modules | 13 | -- require other modules |
14 | require("ltn12") | 14 | require("ltn12") |
15 | require("mime") | 15 | require("mime") |
16 | -- get MIME namespace | ||
17 | local mime = _G[MIME_LIBNAME] | ||
16 | require("url") | 18 | require("url") |
17 | 19 | ||
18 | -- create namespace inside LuaSocket namespace | 20 | -- create namespace inside LuaSocket namespace |
diff --git a/src/luasocket.c b/src/luasocket.c index 8d49be5..a5b6cb0 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
@@ -25,11 +25,10 @@ | |||
25 | \*=========================================================================*/ | 25 | \*=========================================================================*/ |
26 | #include "luasocket.h" | 26 | #include "luasocket.h" |
27 | 27 | ||
28 | #include "base.h" | ||
29 | #include "auxiliar.h" | 28 | #include "auxiliar.h" |
29 | #include "base.h" | ||
30 | #include "timeout.h" | 30 | #include "timeout.h" |
31 | #include "buffer.h" | 31 | #include "buffer.h" |
32 | #include "socket.h" | ||
33 | #include "inet.h" | 32 | #include "inet.h" |
34 | #include "tcp.h" | 33 | #include "tcp.h" |
35 | #include "udp.h" | 34 | #include "udp.h" |
@@ -40,10 +39,10 @@ | |||
40 | * Modules | 39 | * Modules |
41 | \*-------------------------------------------------------------------------*/ | 40 | \*-------------------------------------------------------------------------*/ |
42 | static const luaL_reg mod[] = { | 41 | static const luaL_reg mod[] = { |
42 | {"auxiliar", aux_open}, | ||
43 | {"base", base_open}, | 43 | {"base", base_open}, |
44 | {"aux", aux_open}, | 44 | {"timeout", tm_open}, |
45 | {"tm", tm_open}, | 45 | {"buffer", buf_open}, |
46 | {"buf", buf_open}, | ||
47 | {"inet", inet_open}, | 46 | {"inet", inet_open}, |
48 | {"tcp", tcp_open}, | 47 | {"tcp", tcp_open}, |
49 | {"udp", udp_open}, | 48 | {"udp", udp_open}, |
@@ -55,14 +54,8 @@ static const luaL_reg mod[] = { | |||
55 | /*-------------------------------------------------------------------------*\ | 54 | /*-------------------------------------------------------------------------*\ |
56 | * Initializes all library modules. | 55 | * Initializes all library modules. |
57 | \*-------------------------------------------------------------------------*/ | 56 | \*-------------------------------------------------------------------------*/ |
58 | LUASOCKET_API int luaopen_socket(lua_State *L) | 57 | LUASOCKET_API int luaopen_socket(lua_State *L) { |
59 | { | ||
60 | int i; | 58 | int i; |
61 | if (!sock_open()) { | ||
62 | lua_pushnil(L); | ||
63 | lua_pushstring(L, "unable to initialize library"); | ||
64 | return 2; | ||
65 | } | ||
66 | for (i = 0; mod[i].name; i++) | 59 | for (i = 0; mod[i].name; i++) |
67 | mod[i].func(L); | 60 | mod[i].func(L); |
68 | return 1; | 61 | return 1; |
@@ -82,8 +82,7 @@ int luaopen_mime(lua_State *L) | |||
82 | /* initialize lookup tables */ | 82 | /* initialize lookup tables */ |
83 | qpsetup(qpclass, qpunbase); | 83 | qpsetup(qpclass, qpunbase); |
84 | b64setup(b64unbase); | 84 | b64setup(b64unbase); |
85 | lua_pop(L, 1); | 85 | return 1; |
86 | return 0; | ||
87 | } | 86 | } |
88 | 87 | ||
89 | /*=========================================================================*\ | 88 | /*=========================================================================*\ |
diff --git a/src/select.h b/src/select.h index de10ea4..b58f082 100644 --- a/src/select.h +++ b/src/select.h | |||
@@ -7,10 +7,10 @@ | |||
7 | * To make the code as simple as possible, the select function is | 7 | * To make the code as simple as possible, the select function is |
8 | * implemented int Lua, with a few helper functions written in C. | 8 | * implemented int Lua, with a few helper functions written in C. |
9 | * | 9 | * |
10 | * Each object that can be passed to the select function has to be in the | 10 | * Each object that can be passed to the select function has to export two |
11 | * group select{able} and export two methods: fd() and dirty(). Fd returns | 11 | * methods: fd() and dirty(). Fd returns the descriptor to be passed to the |
12 | * the descriptor to be passed to the select function. Dirty() should return | 12 | * select function. Dirty() should return true if there is data ready for |
13 | * true if there is data ready for reading (required for buffered input). | 13 | * reading (required for buffered input). |
14 | * | 14 | * |
15 | * RCS ID: $Id$ | 15 | * RCS ID: $Id$ |
16 | \*=========================================================================*/ | 16 | \*=========================================================================*/ |
diff --git a/src/smtp.lua b/src/smtp.lua index 01babbe..3108395 100644 --- a/src/smtp.lua +++ b/src/smtp.lua | |||
@@ -6,11 +6,12 @@ | |||
6 | -- RCS ID: $Id$ | 6 | -- RCS ID: $Id$ |
7 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
8 | -- make sure LuaSocket is loaded | 8 | -- make sure LuaSocket is loaded |
9 | require"socket" | 9 | require("socket") |
10 | -- get LuaSocket namespace | 10 | -- get LuaSocket namespace |
11 | local socket = _G[LUASOCKET_LIBNAME] | 11 | local socket = _G[LUASOCKET_LIBNAME] |
12 | 12 | ||
13 | require"ltn12" | 13 | require("ltn12") |
14 | require("tp") | ||
14 | 15 | ||
15 | -- create smtp namespace inside LuaSocket namespace | 16 | -- create smtp namespace inside LuaSocket namespace |
16 | local smtp = socket.smtp or {} | 17 | local smtp = socket.smtp or {} |
diff --git a/src/socket.h b/src/socket.h index 2e7b6f9..85e8848 100644 --- a/src/socket.h +++ b/src/socket.h | |||
@@ -38,6 +38,7 @@ typedef struct sockaddr SA; | |||
38 | * interface to sockets | 38 | * interface to sockets |
39 | \*=========================================================================*/ | 39 | \*=========================================================================*/ |
40 | int sock_open(void); | 40 | int sock_open(void); |
41 | int sock_close(void); | ||
41 | void sock_destroy(p_sock ps); | 42 | void sock_destroy(p_sock ps); |
42 | void sock_shutdown(p_sock ps, int how); | 43 | void sock_shutdown(p_sock ps, int how); |
43 | int sock_send(p_sock ps, const char *data, size_t count, | 44 | int sock_send(p_sock ps, const char *data, size_t count, |
@@ -6,10 +6,10 @@ | |||
6 | -- RCS ID: $Id$ | 6 | -- RCS ID: $Id$ |
7 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
8 | -- make sure LuaSocket is loaded | 8 | -- make sure LuaSocket is loaded |
9 | if not LUASOCKET_LIBNAME then error('module requires LuaSocket') end | 9 | require("socket") |
10 | -- get LuaSocket namespace | 10 | -- get LuaSocket namespace |
11 | local socket = _G[LUASOCKET_LIBNAME] | 11 | local socket = _G[LUASOCKET_LIBNAME] |
12 | if not socket then error('module requires LuaSocket') end | 12 | |
13 | -- create namespace inside LuaSocket namespace | 13 | -- create namespace inside LuaSocket namespace |
14 | socket.tp = socket.tp or {} | 14 | socket.tp = socket.tp or {} |
15 | -- make all module globals fall into namespace | 15 | -- make all module globals fall into namespace |
@@ -35,6 +35,7 @@ local function get_reply(control) | |||
35 | -- reply ends with same code | 35 | -- reply ends with same code |
36 | until code == current and sep == " " | 36 | until code == current and sep == " " |
37 | end | 37 | end |
38 | print(reply) | ||
38 | return code, reply | 39 | return code, reply |
39 | end | 40 | end |
40 | 41 | ||
@@ -58,6 +59,7 @@ function metat.__index:check(ok) | |||
58 | end | 59 | end |
59 | 60 | ||
60 | function metat.__index:command(cmd, arg) | 61 | function metat.__index:command(cmd, arg) |
62 | print(cmd, arg) | ||
61 | if arg then return self.control:send(cmd .. " " .. arg.. "\r\n") | 63 | if arg then return self.control:send(cmd .. " " .. arg.. "\r\n") |
62 | else return self.control:send(cmd .. "\r\n") end | 64 | else return self.control:send(cmd .. "\r\n") end |
63 | end | 65 | end |
diff --git a/src/url.lua b/src/url.lua index 16b19e0..8c591c0 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -9,10 +9,11 @@ | |||
9 | require("socket") | 9 | require("socket") |
10 | -- get LuaSocket namespace | 10 | -- get LuaSocket namespace |
11 | local socket = _G[LUASOCKET_LIBNAME] | 11 | local socket = _G[LUASOCKET_LIBNAME] |
12 | |||
12 | -- create url namespace inside LuaSocket namespace | 13 | -- create url namespace inside LuaSocket namespace |
13 | local url = socket.url or {} | 14 | local url = socket.url or {} |
14 | socket.url = url | 15 | socket.url = url |
15 | -- make all module globals fall into smtp namespace | 16 | -- make all module globals fall into url namespace |
16 | setmetatable(url, { __index = _G }) | 17 | setmetatable(url, { __index = _G }) |
17 | setfenv(1, url) | 18 | setfenv(1, url) |
18 | 19 | ||
diff --git a/src/usocket.c b/src/usocket.c index 9e6efd3..6b4182b 100644 --- a/src/usocket.c +++ b/src/usocket.c | |||
@@ -43,6 +43,14 @@ int sock_open(void) | |||
43 | } | 43 | } |
44 | 44 | ||
45 | /*-------------------------------------------------------------------------*\ | 45 | /*-------------------------------------------------------------------------*\ |
46 | * Close module | ||
47 | \*-------------------------------------------------------------------------*/ | ||
48 | int sock_close(void) | ||
49 | { | ||
50 | return 1; | ||
51 | } | ||
52 | |||
53 | /*-------------------------------------------------------------------------*\ | ||
46 | * Close and inutilize socket | 54 | * Close and inutilize socket |
47 | \*-------------------------------------------------------------------------*/ | 55 | \*-------------------------------------------------------------------------*/ |
48 | void sock_destroy(p_sock ps) | 56 | void sock_destroy(p_sock ps) |
diff --git a/src/wsocket.c b/src/wsocket.c index 023f470..08c1046 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
@@ -38,6 +38,15 @@ int sock_open(void) | |||
38 | } | 38 | } |
39 | 39 | ||
40 | /*-------------------------------------------------------------------------*\ | 40 | /*-------------------------------------------------------------------------*\ |
41 | * Close module | ||
42 | \*-------------------------------------------------------------------------*/ | ||
43 | int sock_close(void) | ||
44 | { | ||
45 | WSACleanup(); | ||
46 | return 1; | ||
47 | } | ||
48 | |||
49 | /*-------------------------------------------------------------------------*\ | ||
41 | * Select with int timeout in ms | 50 | * Select with int timeout in ms |
42 | \*-------------------------------------------------------------------------*/ | 51 | \*-------------------------------------------------------------------------*/ |
43 | int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, int timeout) | 52 | int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, int timeout) |
diff --git a/test/mimetest.lua b/test/mimetest.lua index 8433786..d092175 100644 --- a/test/mimetest.lua +++ b/test/mimetest.lua | |||
@@ -8,10 +8,14 @@ local qptest = "qptest.bin" | |||
8 | local eqptest = "qptest.bin2" | 8 | local eqptest = "qptest.bin2" |
9 | local dqptest = "qptest.bin3" | 9 | local dqptest = "qptest.bin3" |
10 | 10 | ||
11 | local b64test = "luasocket" | 11 | local b64test = "libluasocket.dylib" |
12 | local eb64test = "b64test.bin" | 12 | local eb64test = "b64test.bin" |
13 | local db64test = "b64test.bin2" | 13 | local db64test = "b64test.bin2" |
14 | 14 | ||
15 | -- make sure test file exists | ||
16 | local f = assert(io.open(b64test, "r")) | ||
17 | f:close() | ||
18 | |||
15 | -- from Machado de Assis, "A Mão e a Rosa" | 19 | -- from Machado de Assis, "A Mão e a Rosa" |
16 | local mao = [[ | 20 | local mao = [[ |
17 | Cursavam estes dois moços a academia de S. Paulo, estando | 21 | Cursavam estes dois moços a academia de S. Paulo, estando |