aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-05-30 21:36:22 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-05-30 21:36:22 +0000
commit5ca1049ab47f3f9ff9157f71af9072f04a637500 (patch)
tree24fcb14f2890900a4a709312ab25bfc2c14a3939
parentc23240726e3044e3eaa32a82a999b754c08bc183 (diff)
downloadluasocket-5ca1049ab47f3f9ff9157f71af9072f04a637500.tar.gz
luasocket-5ca1049ab47f3f9ff9157f71af9072f04a637500.tar.bz2
luasocket-5ca1049ab47f3f9ff9157f71af9072f04a637500.zip
Fine tuning the "require" business.
-rw-r--r--TODO118
-rw-r--r--etc/get.lua5
-rw-r--r--samples/listener.lua15
-rw-r--r--samples/talker.lua13
-rw-r--r--samples/tinyirc.lua19
-rw-r--r--src/ftp.lua11
-rw-r--r--src/http.lua2
-rw-r--r--src/luasocket.c17
-rw-r--r--src/mime.c3
-rw-r--r--src/select.h8
-rw-r--r--src/smtp.lua5
-rw-r--r--src/socket.h1
-rw-r--r--src/tp.lua6
-rw-r--r--src/url.lua3
-rw-r--r--src/usocket.c8
-rw-r--r--src/wsocket.c9
-rw-r--r--test/mimetest.lua6
17 files changed, 133 insertions, 116 deletions
diff --git a/TODO b/TODO
index 838be3d..bc307d5 100644
--- a/TODO
+++ b/TODO
@@ -1,54 +1,14 @@
1* should be interrupt-safe 1ajeitar os README.*
2* notice the change in callback conventions 2ajeitar 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
39get.lua precisa de ftp.get com url e sink
40make sure filter.chain fails gracefully. 3make sure filter.chain fails gracefully.
41ajeitar o manual sobre select, mais liberal agora 4ajeitar o manual sobre select, mais liberal agora
42conjunto associativo
43 5
44falar sobre encodet/wrapt/decodet no manual sobre mime 6falar sobre encodet/wrapt/decodet no manual sobre mime
45 7
46
47RECEIVE MUDOU!!! (partial stuff) COLOCAR NO MANUAL. 8RECEIVE MUDOU!!! (partial stuff) COLOCAR NO MANUAL.
48HTTP.lua mudou bastante também. 9HTTP.lua mudou bastante também.
49pump.step usado em todo mundo que recebe source ou sink 10pump.step usado em todo mundo que recebe source ou sink
50 11
51colocar um userdata com gc metamethod pra chamar sock_close (WSAClose);
52sources ans sinks are always simple in http and ftp and smtp 12sources ans sinks are always simple in http and ftp and smtp
53expose encode/decode tables to provide extensibility for mime module 13expose encode/decode tables to provide extensibility for mime module
54use coroutines instead of fancy filters 14use coroutines instead of fancy filters
@@ -60,6 +20,7 @@ pop3???
60add socket.TIMEOUT to be default timeout? 20add socket.TIMEOUT to be default timeout?
61 21
62manual 22manual
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
89wrp can't break lines in the middle of a line break. 50wrp can't break lines in the middle of a line break.
90call select before accept, not after, dumbass!
91get rid of setnonblocking/setblocking in the bind function
92close has to block...
93fmt is not a good name
94change wrap() to accept a number and default to "character"
95move gethostname to dns table
96get rid of _cb in name of functions?
97trust character constants in mime.c? noooooo.
98smtp.lua needs stuff filter
99 51
100add comments into each C module. 52add comments into each C module.
101new option.c module to put all options (TCP and UDP share...)?
102testar os options! 53testar os options!
103add _tostring methods!
104change all modules to use the new namespace scheme
105
106write some utilities that use the code.lua module and put them
107in etc, modify the README.etc file and makefile.dist (eol.lua is done)
108 54
109use gethostname it in SMTP 55use 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--------------
101these 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
111end 114end
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-----------------------------------------------------------------------------
7require("socket")
7host = host or "*" 8host = host or "*"
8port = port or 8080 9port = port or 8080
9if arg then 10if arg then
@@ -11,18 +12,10 @@ if arg then
11 port = arg[2] or port 12 port = arg[2] or port
12end 13end
13print("Binding to host '" ..host.. "' and port " ..port.. "...") 14print("Binding to host '" ..host.. "' and port " ..port.. "...")
14s, e = socket.bind(host, port) 15s = socket.try(socket.bind(host, port))
15if not s then 16i, p = socket.try(s:getsockname())
16 print(e)
17 exit()
18end
19i, p = s:getsockname()
20print("Waiting connection from talker on " .. i .. ":" .. p .. "...") 17print("Waiting connection from talker on " .. i .. ":" .. p .. "...")
21c, e = s:accept() 18c = socket.try(s:accept())
22if not c then
23 print(e)
24 exit()
25end
26print("Connected. Here is the stuff:") 19print("Connected. Here is the stuff:")
27l, e = c:receive() 20l, e = c:receive()
28while not e do 21while 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-----------------------------------------------------------------------------
7require("socket")
7host = host or "localhost" 8host = host or "localhost"
8port = port or 8080 9port = port or 8080
9if arg then 10if arg then
@@ -11,18 +12,10 @@ if arg then
11 port = arg[2] or port 12 port = arg[2] or port
12end 13end
13print("Attempting connection to host '" ..host.. "' and port " ..port.. "...") 14print("Attempting connection to host '" ..host.. "' and port " ..port.. "...")
14c, e = socket.connect(host, port) 15c = socket.try(socket.connect(host, port))
15if not c then
16 print(e)
17 os.exit()
18end
19print("Connected! Please type stuff (empty line to stop):") 16print("Connected! Please type stuff (empty line to stop):")
20l = io.read() 17l = io.read()
21while l and l ~= "" and not e do 18while 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()
28end 21end
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-----------------------------------------------------------------------------
7require("socket")
7host = host or "*" 8host = host or "*"
8port1 = port1 or 8080 9port1 = port1 or 8080
9port2 = port2 or 8181 10port2 = port2 or 8181
@@ -13,12 +14,10 @@ if arg then
13 port2 = arg[3] or port2 14 port2 = arg[3] or port2
14end 15end
15 16
16server1, error = socket.bind(host, port1) 17server1 = socket.try(socket.bind(host, port1))
17assert(server1, error) 18server2 = socket.try(socket.bind(host, port2))
18server1:settimeout(1) -- make sure we don't block in accept 19server1:settimeout(1) -- make sure we don't block in accept
19server2, error = socket.bind(host, port2) 20server2:settimeout(1)
20assert(server2, error)
21server2:settimeout(1) -- make sure we don't block in accept
22 21
23io.write("Servers bound\n") 22io.write("Servers bound\n")
24 23
@@ -49,7 +48,7 @@ set:insert(server2)
49 48
50while 1 do 49while 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
14require("ltn12") 14require("ltn12")
15require("url") 15require("url")
16require("tp")
16 17
17-- create namespace inside LuaSocket namespace 18-- create namespace inside LuaSocket namespace
18socket.ftp = socket.ftp or {} 19socket.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
206end 209end
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
14require("ltn12") 14require("ltn12")
15require("mime") 15require("mime")
16-- get MIME namespace
17local mime = _G[MIME_LIBNAME]
16require("url") 18require("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\*-------------------------------------------------------------------------*/
42static const luaL_reg mod[] = { 41static 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\*-------------------------------------------------------------------------*/
58LUASOCKET_API int luaopen_socket(lua_State *L) 57LUASOCKET_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;
diff --git a/src/mime.c b/src/mime.c
index 7a2baae..8cfcd26 100644
--- a/src/mime.c
+++ b/src/mime.c
@@ -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
9require"socket" 9require("socket")
10-- get LuaSocket namespace 10-- get LuaSocket namespace
11local socket = _G[LUASOCKET_LIBNAME] 11local socket = _G[LUASOCKET_LIBNAME]
12 12
13require"ltn12" 13require("ltn12")
14require("tp")
14 15
15-- create smtp namespace inside LuaSocket namespace 16-- create smtp namespace inside LuaSocket namespace
16local smtp = socket.smtp or {} 17local 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\*=========================================================================*/
40int sock_open(void); 40int sock_open(void);
41int sock_close(void);
41void sock_destroy(p_sock ps); 42void sock_destroy(p_sock ps);
42void sock_shutdown(p_sock ps, int how); 43void sock_shutdown(p_sock ps, int how);
43int sock_send(p_sock ps, const char *data, size_t count, 44int sock_send(p_sock ps, const char *data, size_t count,
diff --git a/src/tp.lua b/src/tp.lua
index b671e58..f510226 100644
--- a/src/tp.lua
+++ b/src/tp.lua
@@ -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
9if not LUASOCKET_LIBNAME then error('module requires LuaSocket') end 9require("socket")
10-- get LuaSocket namespace 10-- get LuaSocket namespace
11local socket = _G[LUASOCKET_LIBNAME] 11local socket = _G[LUASOCKET_LIBNAME]
12if not socket then error('module requires LuaSocket') end 12
13-- create namespace inside LuaSocket namespace 13-- create namespace inside LuaSocket namespace
14socket.tp = socket.tp or {} 14socket.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
38print(reply)
38 return code, reply 39 return code, reply
39end 40end
40 41
@@ -58,6 +59,7 @@ function metat.__index:check(ok)
58end 59end
59 60
60function metat.__index:command(cmd, arg) 61function metat.__index:command(cmd, arg)
62print(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
63end 65end
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 @@
9require("socket") 9require("socket")
10-- get LuaSocket namespace 10-- get LuaSocket namespace
11local socket = _G[LUASOCKET_LIBNAME] 11local socket = _G[LUASOCKET_LIBNAME]
12
12-- create url namespace inside LuaSocket namespace 13-- create url namespace inside LuaSocket namespace
13local url = socket.url or {} 14local url = socket.url or {}
14socket.url = url 15socket.url = url
15-- make all module globals fall into smtp namespace 16-- make all module globals fall into url namespace
16setmetatable(url, { __index = _G }) 17setmetatable(url, { __index = _G })
17setfenv(1, url) 18setfenv(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\*-------------------------------------------------------------------------*/
48int sock_close(void)
49{
50 return 1;
51}
52
53/*-------------------------------------------------------------------------*\
46* Close and inutilize socket 54* Close and inutilize socket
47\*-------------------------------------------------------------------------*/ 55\*-------------------------------------------------------------------------*/
48void sock_destroy(p_sock ps) 56void 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\*-------------------------------------------------------------------------*/
43int 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\*-------------------------------------------------------------------------*/
43int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, int timeout) 52int 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"
8local eqptest = "qptest.bin2" 8local eqptest = "qptest.bin2"
9local dqptest = "qptest.bin3" 9local dqptest = "qptest.bin3"
10 10
11local b64test = "luasocket" 11local b64test = "libluasocket.dylib"
12local eb64test = "b64test.bin" 12local eb64test = "b64test.bin"
13local db64test = "b64test.bin2" 13local db64test = "b64test.bin2"
14 14
15-- make sure test file exists
16local f = assert(io.open(b64test, "r"))
17f:close()
18
15-- from Machado de Assis, "A Mão e a Rosa" 19-- from Machado de Assis, "A Mão e a Rosa"
16local mao = [[ 20local 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