aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-17 21:46:22 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-17 21:46:22 +0000
commit597a062b1bc38488df1363995eece8a9f19c7111 (patch)
treeba4ccaa8be98d1100aed63abb9c42c099f2c41bb
parenteac26d2c8dafab604ef2e97e504326cfaf1033cf (diff)
downloadluasocket-597a062b1bc38488df1363995eece8a9f19c7111.tar.gz
luasocket-597a062b1bc38488df1363995eece8a9f19c7111.tar.bz2
luasocket-597a062b1bc38488df1363995eece8a9f19c7111.zip
Almost ready for distribution...
-rw-r--r--NEW101
-rw-r--r--README12
-rw-r--r--etc/README30
-rw-r--r--etc/dict.lua182
-rw-r--r--etc/qp.lua10
-rw-r--r--makefile.dist83
-rw-r--r--samples/README27
-rw-r--r--src/auxiliar.c1
-rw-r--r--src/ftp.lua4
-rw-r--r--src/luasocket.c1
-rw-r--r--test/README13
-rw-r--r--test/ltn12test.lua5
-rw-r--r--test/stufftest.lua6
-rw-r--r--test/testmesg.lua7
14 files changed, 322 insertions, 160 deletions
diff --git a/NEW b/NEW
index 34eac97..035aab7 100644
--- a/NEW
+++ b/NEW
@@ -1,29 +1,86 @@
1Major C code rewrite. Code is modular and extensible. Hopefully, next 1What's New
2versions will include code for local domain sockets, file descriptors,
3pipes (on unix) and named pipes (on windows) as a bonus.
4 2
5All functions provided by the library are in the namespace "socket". 3Everything is new! Many changes for 2.0 happened in the C layer,
6Functions such as send/receive/timeout/close etc do not exist anymore as 4which has been almost completely rewritten. The code has been ported to
7stand alone functions. They are now only available as methods of the 5Lua 5.0 and greatly improved. There have also been some API changes
8appropriate objects. 6that made the interface simpler and more consistent. Here are some of
7the changes that made it into version 2.0:
9 8
10TCP has been changed to become more uniform. First create an object, then 9<> Major C code rewrite. Code is modular and extensible. Hopefully, other
11connect or bind if needed. Then use IO functions. The "socket.connect" and 10 developers will be motivated to provide code for SSL, local domain
12"socket.bind" functions are provided for simplicity, but they just call 11 sockets, file descriptors, pipes (on Unix) and named pipes etc;
13"socket.tcp" followed by the ":connect" or ":bind" methods.
14 12
15All functions return a non-nil value as first return value if successful. 13<> Everything that is exported by the library is exported inside
16All functions return whatever could be retrieved followed by error message 14 namespaces. These should be obtained with calls to the
17in case of error. The best way to check for errors is to check for the 15 'require' function;
18presence of an error message. WARNING: The send function was affected.
19 16
20Better error messages and parameter checking. 17<> Functions such as
18 send/receive/timeout/close etc do not exist anymore as stand-alone
19 functions. They are now only available as methods of the appropriate
20 objects;
21 21
22UDP connected udp sockets can break association with peer by calling 22<> All functions return a non-nil value as first return value if successful.
23setpeername with address "*". 23 All functions return 'nil' followed by error message
24 in case of error. This made the library much easier to use;
24 25
25socket.sleep and socket.time are now part of the library and are 26<> Greatly reduced the number of times the C select is called
26supported. 27 during data transfers, by calling only on failure. This might
28 improve a lot the maximum throughput;
29
30<> TCP has been changed to become more uniform. It's possible to first
31 create a TCP object,
32 then connect or bind if needed, and finally use I/O functions.
33 'socket.connect' and 'socket.bind' functions are still
34 provided for simplicity;
35
36<> This allows for setting a timeout value before connecting;
37
38<> And also allows binding to a local address before connecting;
39
40<> New 'socket.dns.gethostname' function and 'shutdown'
41 method;
42
43<> Better error messages and parameter checking;
44
45<> Should be interrupt safe;
46
47<> UDP connected sockets can break association with peer by calling
48 'setpeername' with address ''*'';
49
50<> Sets returned by 'socket.select' are associative;
51
52<> Select checks if sockets have buffered data and returns immediately;
53
54<> 'socket.sleep' and 'socket.time' are now part of the
55 library and are supported. They used to be available only when
56 LUASOCKET_DEBUG was defined, but it turns out they might be useful for
57 applications;
58
59<> 'socket.try' and 'socket.protect' provide a simple
60 interface to exceptions that proved very in the implementation of
61 high-level modules;
62
63<> Socket options interface has been improved. TCP objects also
64 support socket options and many new options were added.
65
66
67Lots of changes in the Lua modules, too!
68
69<> Every module loads only the modules that it needs. There is no waste
70 of memory. LuaSocket core takes only 20k of memory;
71
72<> New MIME and LTN12 modules make all other modules much more powerful;
73
74<> Support for multipart messages in the SMTP module;
75
76<> The old callback mechanism of FTP and HTTP has been replaced with LTN12
77 sources and sinks, with advantage;
78
79<> Common implementation for low-level FTP and SMTP;
80
81<> FTP, HTTP, and SMTP are implemented in multiple levels in such a way
82 that users will have no problems extending the functionality to satisfy
83 personal needs;
84
85<> SMTP knows how to perform LOGIN and PLAIN authentication.
27 86
28Socket options interface has been improved and TCP now also supports socket
29options.
diff --git a/README b/README
index 611d2a2..b072084 100644
--- a/README
+++ b/README
@@ -1,9 +1,11 @@
1This release is work in progress. It has been tested on WinXP, Mac OS X, 1This release is a "beta" version. It has been tested on WinXP, Mac OS X,
2SunOS and Linux. 2SunOS and Linux. Although no major API changes should happen before the
3final version is released, please look for and report any bugs (or
4"features") you encounter.
3 5
4In this version, all Lua code should be built into the binary. For that, you 6For this version, all modules should be loaded with the provided "require"
5will need a working versions of luac and bin2c, both available with your 7function, and the binaries should be compliled as shared libraries. Check
6Lua distribution. Check the makefile for details. 8the makefiles in the distribution and the readme in the 'etc' directory.
7 9
8Have fun, 10Have fun,
9Diego Nehab. 11Diego Nehab.
diff --git a/etc/README b/etc/README
index eacb262..d650843 100644
--- a/etc/README
+++ b/etc/README
@@ -4,34 +4,42 @@ This directory contains code that is more useful than the examples. This code
4 lua.lua 4 lua.lua
5 5
6These are modules to suport dynamic loading of LuaSocket by the stand alone 6These are modules to suport dynamic loading of LuaSocket by the stand alone
7Lua Interpreter with the use of the "require" function. For my Mac OS X 7Lua Interpreter with the use of new "require" and "requirelib" functions.
8system, I place all files in /Users/diego/tec/luasocket 8For my Mac OS X box, for instance, I place all files in
9and set the following environment variables: 9/Users/diego/tec/luasocket and set the following environment variables:
10 10
11 LUA_PATH=/Users/diego/tec/luasocket/?.lua
12 LUA_INIT=@/Users/diego/tec/luasocket/lua.lua 11 LUA_INIT=@/Users/diego/tec/luasocket/lua.lua
13 LUA_FUNCNAME=? 12 LUA_PATH=/Users/diego/tec/luasocket/?.lua;?.lua
14 LUA_LIBNAME=/Users/diego/tec/luasocket/?.dylib 13 LUA_PATHLIB=/Users/diego/tec/luasocket/?.dylib;?.dylib
15 14
16With that, I can run any luasocket application with the command line: 15With that, I can run any luasocket application with the command line:
17 16
18 lua -l socket <script> 17 lua <script>
19 18
19as long as the script uses "require" to load the needed namespaces.
20Much nicer than having to build a new executable just to initialize 20Much nicer than having to build a new executable just to initialize
21LuaSocket! 21LuaSocket!
22 22
23
24 tftp.lua -- Trivial FTP client 23 tftp.lua -- Trivial FTP client
25 24
26This module implements file retrieval by the TFTP protocol. Its main use 25This module implements file retrieval by the TFTP protocol. Its main use
27is to test the UDP code, but someone might find it usefull. 26was to test the UDP code, but since someone found it usefull, I turned it
27into a module that is almost official (no uploads, yet).
28
29 dict.lua -- Dict client
30
31The dict.lua module started with a cool simple client for the DICT
32protocol, written by Luiz Henrique Figueiredo. This new version has been
33converted into a library, similar to the HTTP and FTP libraries, that can
34be used from within any luasocket application. Take a look on the source
35code and you will be able to figure out how to use it.
28 36
29 get.lua -- file retriever 37 get.lua -- file retriever
30 38
31This little program is a client that uses the FTP and HTTP code to 39This little program is a client that uses the FTP and HTTP code to
32implement a command line file graber. Just run 40implement a command line file graber. Just run
33 41
34 lua -l socket get.lua <remote-file> [<local-file>] 42 lua get.lua <remote-file> [<local-file>]
35 43
36to download a remote file (either ftp:// or http://) to the specified 44to download a remote file (either ftp:// or http://) to the specified
37local file. The program also prints the download throughput, elapsed 45local file. The program also prints the download throughput, elapsed
@@ -44,7 +52,7 @@ similar to check-links.pl by Jamie Zawinski, but uses all facilities of
44the LuaSocket library and the Lua language. It has not been thoroughly 52the LuaSocket library and the Lua language. It has not been thoroughly
45tested, but it should work. Just run 53tested, but it should work. Just run
46 54
47 lua -l socket check-links.lua {<url>} > output 55 lua check-links.lua {<url>} > output
48 56
49and open the result to see a list of broken links. 57and open the result to see a list of broken links.
50 58
diff --git a/etc/dict.lua b/etc/dict.lua
index dd001cf..b9247dc 100644
--- a/etc/dict.lua
+++ b/etc/dict.lua
@@ -4,78 +4,144 @@
4-- Author: Diego Nehab 4-- Author: Diego Nehab
5-- RCS ID: $Id$ 5-- RCS ID: $Id$
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7
8-----------------------------------------------------------------------------
9-- Load required modules
10-----------------------------------------------------------------------------
7local socket = require("socket") 11local socket = require("socket")
12local url = require("url")
13local tp = require("tp")
8 14
9function get_status(sock, valid) 15-----------------------------------------------------------------------------
10 local line, err = sock:receive() 16-- Globals
11 local code, par 17-----------------------------------------------------------------------------
12 if not line then sock:close() return err end 18HOST = "dict.org"
13 code = socket.skip(2, string.find(line, "^(%d%d%d)")) 19PORT = 2628
14 code = tonumber(code) 20TIMEOUT = 10
15 if code ~= valid then return code end 21
16 if code == 150 then 22-----------------------------------------------------------------------------
17 par = tonumber(socket.skip(2, string.find(line, "^%d%d%d (%d*)"))) 23-- Low-level dict API
18 end 24-----------------------------------------------------------------------------
19 return nil, par 25local metat = { __index = {} }
26
27function open(host, port)
28 local tp = socket.try(tp.connect(host or HOST, port or PORT, TIMEOUT))
29 return setmetatable({tp = tp}, metat)
20end 30end
21 31
22function get_def(sock) 32function metat.__index:greet()
23 local line, err = sock:receive() 33 return socket.try(self.tp:check(220))
24 local def = "" 34end
25 while (not err) and line ~= "." do 35
26 def = def .. line .. "\n" 36function metat.__index:check(ok)
27 line, err = sock:receive() 37 local code, status = socket.try(self.tp:check(ok))
38 return code, tonumber(socket.skip(2, string.find(status, "^%d%d%d (%d*)")))
39end
40
41function metat.__index:getdef()
42 local line = socket.try(self.tp:receive())
43 local def = {}
44 while line ~= "." do
45 table.insert(def, line)
46 line = socket.try(self.tp:receive())
28 end 47 end
29 if err then sock:close() return nil, err 48 return table.concat(def, "\n")
30 else return def end
31end 49end
32 50
33function dict_open() 51function metat.__index:define(database, word)
34 local sock, err = socket.connect("dict.org", 2628) 52 database = database or "!"
35 if not sock then return nil, err end 53 socket.try(self.tp:command("DEFINE", database .. " " .. word))
36 sock:settimeout(10) 54 local code, count = self:check(150)
37 local code, par = get_status(sock, 220) 55 local defs = {}
38 if code then return nil, code end 56 for i = 1, count do
39 return sock 57 self:check(151)
58 table.insert(defs, self:getdef())
59 end
60 self:check(250)
61 return defs
40end 62end
41 63
42function dict_define(sock, word, dict) 64function metat.__index:match(database, strat, word)
43 dict = dict or "web1913" 65 database = database or "!"
44 sock:send("DEFINE " .. dict .. " " .. word .. "\r\n") 66 strat = strat or "."
45 local code, par = get_status(sock, 150) 67 socket.try(self.tp:command("MATCH", database .." ".. strat .." ".. word))
46 if code or not par then return nil, code end 68 self:check(152)
47 local defs = "" 69 local mat = {}
48 for i = 1, par do 70 local line = socket.try(self.tp:receive())
49 local def 71 while line ~= '.' do
50 code, par = get_status(sock, 151) 72 database, word = socket.skip(2, string.find(line, "(%S+) (.*)"))
51 if code then return nil, code end 73 if not mat[database] then mat[database] = {} end
52 def, err = get_def(sock) 74 table.insert(mat[database], word)
53 if not def then return nil, err end 75 line = socket.try(self.tp:receive())
54 defs = defs .. def .. "\n"
55 end 76 end
56 code, par = get_status(sock, 250) 77 self:check(250)
57 if code then return nil, code end 78 return mat
58 return string.gsub(defs, "%s%s$", "") 79end
80
81function metat.__index:quit()
82 self.tp:command("QUIT")
83 return self:check(221)
84end
85
86function metat.__index:close()
87 return self.tp:close()
59end 88end
60 89
61function dict_close(sock) 90-----------------------------------------------------------------------------
62 sock:send("QUIT\r\n") 91-- High-level dict API
63 local code, par = get_status(sock, 221) 92-----------------------------------------------------------------------------
64 sock:close() 93local default = {
65 return code 94 scheme = "dict",
95 host = "dict.org"
96}
97
98local function there(f)
99 if f == "" then return nil
100 else return f end
66end 101end
67 102
68function dict_get(word, dict) 103local function parse(u)
69 local sock, err = dict_open() 104 local t = socket.try(url.parse(u, default))
70 if not sock then return nil, err end 105 socket.try(t.scheme == "dict", "invalid scheme '" .. t.scheme .. "'")
71 local defs, err = dict_define(sock, word, dict) 106 socket.try(t.path, "invalid path in url")
72 dict_close(sock) 107 local cmd, arg = socket.skip(2, string.find(t.path, "^/(.)(.*)$"))
73 return defs, err 108 socket.try(cmd == "d" or cmd == "m", "<command> should be 'm' or 'd'")
109 socket.try(arg and arg ~= "", "need at least <word> in URL")
110 t.command, t.argument = cmd, arg
111 arg = string.gsub(arg, "^:([^:]+)", function(f) t.word = f end)
112 socket.try(t.word, "need at least <word> in URL")
113 arg = string.gsub(arg, "^:([^:]*)", function(f) t.database = there(f) end)
114 if cmd == "m" then
115 arg = string.gsub(arg, "^:([^:]*)", function(f) t.strat = there(f) end)
116 end
117 string.gsub(arg, ":([^:]*)$", function(f) t.n = tonumber(f) end)
118 return t
74end 119end
75 120
76if arg and arg[1] then 121local function tget(gett)
77 defs, err = dict_get(arg[1], arg[2]) 122 local con = open(gett.host, gett.port)
78 print(defs or err) 123 con:greet()
79else 124 if gett.command == "d" then
80 io.write("Usage:\n lua dict.lua <word> [<dictionary>]\n") 125 local def = con:define(gett.database, gett.word)
126 con:quit()
127 con:close()
128 if gett.n then return def[gett.n]
129 else return def end
130 elseif gett.command == "m" then
131 local mat = con:match(gett.database, gett.strat, gett.word)
132 con:quit()
133 con:close()
134 return mat
135 else return nil, "invalid command" end
81end 136end
137
138local function sget(u)
139 local gett = parse(u)
140 return tget(gett)
141end
142
143--function socket.protect(f) return f end
144get = socket.protect(function(gett)
145 if type(gett) == "string" then return sget(gett)
146 else return tget(gett) end
147end)
diff --git a/etc/qp.lua b/etc/qp.lua
index 5a00c4d..31a572b 100644
--- a/etc/qp.lua
+++ b/etc/qp.lua
@@ -1,5 +1,11 @@
1require("ltn12") 1-----------------------------------------------------------------------------
2require("mime") 2-- Little program to convert to and from Quoted-Printable
3-- LuaSocket sample files
4-- Author: Diego Nehab
5-- RCS ID: $Id$
6-----------------------------------------------------------------------------
7local ltn12 = require("ltn12")
8local mime = require("mime")
3local convert 9local convert
4arg = arg or {} 10arg = arg or {}
5local mode = arg and arg[1] or "-et" 11local mode = arg and arg[1] or "-et"
diff --git a/makefile.dist b/makefile.dist
index 353467b..19c85b5 100644
--- a/makefile.dist
+++ b/makefile.dist
@@ -2,62 +2,60 @@
2# Distribution makefile 2# Distribution makefile
3#-------------------------------------------------------------------------- 3#--------------------------------------------------------------------------
4 4
5DIST = luasocket-2.0-alpha 5DIST = luasocket-2.0-beta
6 6
7LUA = \ 7LUA = \
8 auxiliar.lua \
9 code.lua \
10 concat.lua \
11 ftp.lua \ 8 ftp.lua \
12 http.lua \ 9 http.lua \
13 select.lua \ 10 ltn12.lua \
11 mime.lua \
14 smtp.lua \ 12 smtp.lua \
13 socket.lua \
14 tp.lua \
15 url.lua 15 url.lua
16 16
17TESTS = \ 17TESTS = \
18 codetest.lua \
19 concattest.lua \
20 ftptest.lua \
21 mbox.lua \
22 httptest.lua \
23 noglobals.lua \
24 smtptest.lua \
25 testclnt.lua \ 18 testclnt.lua \
26 testsrvr.lua \ 19 testsrvr.lua \
27 udptest.lua \ 20 testsupport.lua
28 urltest.lua
29 21
30EXAMPLES = \ 22EXAMPLES = \
23 check-memory.lua \
24 b64.lua \
25 cddb.lua \
31 daytimeclnt.lua \ 26 daytimeclnt.lua \
32 echoclnt.lua \ 27 echoclnt.lua \
33 echosrvr.lua \ 28 echosrvr.lua \
34 dict.lua \ 29 eol.lua \
35 listener.lua \ 30 listener.lua \
31 qp.lua \
36 talker.lua \ 32 talker.lua \
37 tinyirc.lua 33 tinyirc.lua
38 34
39ETC = \ 35ETC = \
40 check-links.lua \ 36 check-links.lua \
41 cl-compat.lua \ 37 dict.lua \
42 get.lua \ 38 get.lua \
43 lua.lua \ 39 lua.lua \
44 luasocket.lua \ 40 tftp.lua
45 tftp.lua \
46
47 41
48MAIN = \ 42CORE = \
49 auxiliar.c \ 43 auxiliar.c \
50 auxiliar.h \ 44 auxiliar.h \
51 buffer.c \ 45 buffer.c \
52 buffer.h \ 46 buffer.h \
53 error.c \ 47 except.c \
54 error.h \ 48 except.h \
55 inet.c \ 49 inet.c \
56 inet.h \ 50 inet.h \
57 io.c \ 51 io.c \
58 io.h \ 52 io.h \
59 luasocket.c \ 53 luasocket.c \
60 luasocket.h \ 54 luasocket.h \
55 mime.c \
56 mime.h \
57 options.c \
58 options.h \
61 select.c \ 59 select.c \
62 select.h \ 60 select.h \
63 socket.h \ 61 socket.h \
@@ -72,25 +70,56 @@ MAIN = \
72 wsocket.c \ 70 wsocket.c \
73 wsocket.h 71 wsocket.h
74 72
73MAKE = \
74 makefile.Darwin \
75 makefile.Linux \
76 luasocket.export \
77 mime.export \
78 luasocket.sln \
79 luasocket.vcproj \
80 mime.vcproj
81
82MANUAL = \
83 manual/dns.html \
84 manual/ftp.html \
85 manual/home.html \
86 manual/http.html \
87 manual/introduction.html \
88 manual/ltn12.html \
89 manual/luasocket.png \
90 manual/mime.html \
91 manual/reference.css \
92 manual/reference.html \
93 manual/smtp.html \
94 manual/socket.html \
95 manual/tcp.html \
96 manual/udp.html \
97 manual/url.html
98
75dist: 99dist:
76 mkdir -p $(DIST)/examples 100 mkdir -p $(DIST)/examples
77 mkdir -p $(DIST)/tests 101 mkdir -p $(DIST)/tests
78 mkdir -p $(DIST)/etc 102 mkdir -p $(DIST)/etc
79 cp -vf $(MAIN) $(DIST) 103 mkdir -p $(DIST)/lua
80 cp -vf $(LUA) $(DIST) 104 mkdir -p $(DIST)/make
81 cp -vf makefile $(DIST) 105 mkdir -p $(DIST)/manual
106 cp -vf $(CORE) $(DIST)
82 cp -vf README $(DIST) 107 cp -vf README $(DIST)
83 cp -vf lua.README $(DIST)
84 cp -vf NEW $(DIST) 108 cp -vf NEW $(DIST)
109 cp -vf LICENSE $(DIST)
110 cp -vf $(MAKE) $(DIST)/make
111 cp -vf make.README $(DIST)/make/README
112 cp -vf $(LUA) $(DIST)/lua
113 cp -vf lua.README $(DIST)/lua/README
85 cp -vf $(EXAMPLES) $(DIST)/examples 114 cp -vf $(EXAMPLES) $(DIST)/examples
86 cp -vf examples.README $(DIST)/examples/README 115 cp -vf examples.README $(DIST)/examples/README
87 cp -vf $(TESTS) $(DIST)/tests 116 cp -vf $(TESTS) $(DIST)/tests
88 cp -vf tests.README $(DIST)/tests/README 117 cp -vf tests.README $(DIST)/tests/README
89 cp -vf $(ETC) $(DIST)/etc 118 cp -vf $(ETC) $(DIST)/etc
90 cp -vf etc.README $(DIST)/etc/README 119 cp -vf etc.README $(DIST)/etc/README
120 cp -vf $(MANUAL) $(DIST)/manual
91 tar -zcvf $(DIST).tar.gz $(DIST) 121 tar -zcvf $(DIST).tar.gz $(DIST)
92 zip -r $(DIST).zip $(DIST) 122 zip -r $(DIST).zip $(DIST)
93 123
94
95clean: 124clean:
96 \rm -rf $(DIST) $(DIST).tar.gz $(DIST).zip 125 \rm -rf $(DIST) $(DIST).tar.gz $(DIST).zip
diff --git a/samples/README b/samples/README
index 9369277..b5802e5 100644
--- a/samples/README
+++ b/samples/README
@@ -1,4 +1,4 @@
1This directory contains some sample programs using LuaSocket. This code 1This directory contains some sample programs using LuaSocket. This code
2is not supported. 2is not supported.
3 3
4 listener.lua -- socket to stdout 4 listener.lua -- socket to stdout
@@ -7,21 +7,26 @@ is not supported.
7listener.lua and talker.lua are about the simplest applications you can 7listener.lua and talker.lua are about the simplest applications you can
8write using LuaSocket. Run 8write using LuaSocket. Run
9 9
10 'lua -l luasocket listen.lua' and 'lua -l luasocket talk.lua' 10 'lua listen.lua' and 'lua talk.lua'
11 11
12on different terminals. Whatever you type on talk.lua will be 12on different terminals. Whatever you type on talk.lua will be
13printed by listen.lua. 13printed by listen.lua.
14 14
15 dict.lua -- dict client 15 b64.lua
16 qp.lua
17 eol.lua
16 18
17The dict.lua module was a cool simple client for the DICT protocol, 19These are tiny programs that perform Base64, Quoted-Printable and
18written by Luiz Henrique Figueiredo. This new version has been converted 20end-of-line marker conversions.
19into a library, similar to the HTTP and FTP libraries, that can be used 21
20from within any luasocket application. Take a look on the source code 22 cddb.lua -- CDDB client
21and you will be able to figure out how to use it. 23
24This is the first try on a simple CDDB client. Not really useful, but one
25day it might become a module.
22 26
23 daytimeclnt.lua -- day time client 27 daytimeclnt.lua -- day time client
24 28
29
25Just run the program to retrieve the hour and date in readable form from 30Just run the program to retrieve the hour and date in readable form from
26any server running an UDP daytime daemon. 31any server running an UDP daytime daemon.
27 32
@@ -40,5 +45,9 @@ function and shows how to create a simple server whith LuaSocket. Just
40run tinyirc.lua and then open as many telnet connections as you want 45run tinyirc.lua and then open as many telnet connections as you want
41to ports 8080 and 8081. 46to ports 8080 and 8081.
42 47
48 check-memory.lua -- checks memory consumption
49
50This is just to see how much memory each module uses.
51
43Good luck, 52Good luck,
44Diego. 53Diego.
diff --git a/src/auxiliar.c b/src/auxiliar.c
index 9a37e10..2ebcdd6 100644
--- a/src/auxiliar.c
+++ b/src/auxiliar.c
@@ -16,6 +16,7 @@
16* Initializes the module 16* Initializes the module
17\*-------------------------------------------------------------------------*/ 17\*-------------------------------------------------------------------------*/
18int aux_open(lua_State *L) { 18int aux_open(lua_State *L) {
19 (void) L;
19 return 0; 20 return 0;
20} 21}
21 22
diff --git a/src/ftp.lua b/src/ftp.lua
index f3b8a5e..3868158 100644
--- a/src/ftp.lua
+++ b/src/ftp.lua
@@ -176,7 +176,7 @@ end
176-- High level FTP API 176-- High level FTP API
177----------------------------------------------------------------------------- 177-----------------------------------------------------------------------------
178local function tput(putt) 178local function tput(putt)
179 local con = ftp.open(putt.host, putt.port) 179 local con = open(putt.host, putt.port)
180 con:greet() 180 con:greet()
181 con:login(putt.user, putt.password) 181 con:login(putt.user, putt.password)
182 if putt.type then con:type(putt.type) end 182 if putt.type then con:type(putt.type) end
@@ -216,7 +216,7 @@ put = socket.protect(function(putt, body)
216end) 216end)
217 217
218local function tget(gett) 218local function tget(gett)
219 local con = ftp.open(gett.host, gett.port) 219 local con = open(gett.host, gett.port)
220 con:greet() 220 con:greet()
221 con:login(gett.user, gett.password) 221 con:login(gett.user, gett.password)
222 if gett.type then con:type(gett.type) end 222 if gett.type then con:type(gett.type) end
diff --git a/src/luasocket.c b/src/luasocket.c
index 6f7debe..735235a 100644
--- a/src/luasocket.c
+++ b/src/luasocket.c
@@ -75,6 +75,7 @@ static int global_skip(lua_State *L) {
75* Unloads the library 75* Unloads the library
76\*-------------------------------------------------------------------------*/ 76\*-------------------------------------------------------------------------*/
77static int global_unload(lua_State *L) { 77static int global_unload(lua_State *L) {
78 (void) L;
78 sock_close(); 79 sock_close();
79 return 0; 80 return 0;
80} 81}
diff --git a/test/README b/test/README
index 2502e20..180fa27 100644
--- a/test/README
+++ b/test/README
@@ -5,19 +5,8 @@ The files provided are:
5 5
6 testsrvr.lua -- test server 6 testsrvr.lua -- test server
7 testclnt.lua -- test client 7 testclnt.lua -- test client
8 testcmd.lua -- test command definitions
9 8
10To run the automatic tests on your system, make sure to compile the 9To run these tests, just run lua on the server and then on the client.
11library with _DEBUG defined (check makefile) and then open two
12terminals. Run 'luasocket testsrvr.lua' on one of them and 'luasocket
13testclnt.lua' on the other. The programs should start talking to each
14other and report any failure. The tests can also be used as a benchmark.
15
16 urltest.lua -- url.lua test module
17 codetest.lua -- code.lua test module
18 concattest.lua -- concat.lua test module
19
20To run these tests, just run luasocket on them and see the results.
21 10
22Good luck, 11Good luck,
23Diego. 12Diego.
diff --git a/test/ltn12test.lua b/test/ltn12test.lua
deleted file mode 100644
index 04749a5..0000000
--- a/test/ltn12test.lua
+++ /dev/null
@@ -1,5 +0,0 @@
1a = ltn12.source.file(io.open("luasocket.lua"))
2b = ltn12.source.file(io.open("auxiliar.lua"))
3c = ltn12.source.cat(a, b)
4d = ltn12.sink.file(io.stdout)
5socket.try(ltn12.pump.all(c, d))
diff --git a/test/stufftest.lua b/test/stufftest.lua
index 6bd1f91..eddf636 100644
--- a/test/stufftest.lua
+++ b/test/stufftest.lua
@@ -1,13 +1,13 @@
1smtp = require("smtp") 1mime = require("mime")
2 2
3function test_dot(original, right) 3function test_dot(original, right)
4 local result, n = smtp.dot(2, original) 4 local result, n = mime.dot(2, original)
5 assert(result == right, "->" .. result .. "<-") 5 assert(result == right, "->" .. result .. "<-")
6 print("ok") 6 print("ok")
7end 7end
8 8
9function test_stuff(original, right) 9function test_stuff(original, right)
10 local result, n = smtp.dot(2, original) 10 local result, n = mime.dot(2, original)
11 assert(result == right, "->" .. result .. "<-") 11 assert(result == right, "->" .. result .. "<-")
12 print("ok") 12 print("ok")
13end 13end
diff --git a/test/testmesg.lua b/test/testmesg.lua
index d43c189..3555031 100644
--- a/test/testmesg.lua
+++ b/test/testmesg.lua
@@ -50,10 +50,9 @@ source = smtp.message{
50 50
51-- finally send it 51-- finally send it
52r, e = smtp.send{ 52r, e = smtp.send{
53 rcpt = "<diego@cs.princeton.edu>", 53 rcpt = "<fulano@tecgraf.puc-rio.br>",
54 from = "<diego@cs.princeton.edu>", 54 from = "<sicrano@tecgraf.puc-rio.br>",
55 source = source, 55 source = source
56 server = "mail.cs.princeton.edu"
57} 56}
58 57
59print(r, e) 58print(r, e)