diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-17 21:46:22 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-17 21:46:22 +0000 |
commit | 597a062b1bc38488df1363995eece8a9f19c7111 (patch) | |
tree | ba4ccaa8be98d1100aed63abb9c42c099f2c41bb | |
parent | eac26d2c8dafab604ef2e97e504326cfaf1033cf (diff) | |
download | luasocket-597a062b1bc38488df1363995eece8a9f19c7111.tar.gz luasocket-597a062b1bc38488df1363995eece8a9f19c7111.tar.bz2 luasocket-597a062b1bc38488df1363995eece8a9f19c7111.zip |
Almost ready for distribution...
-rw-r--r-- | NEW | 101 | ||||
-rw-r--r-- | README | 12 | ||||
-rw-r--r-- | etc/README | 30 | ||||
-rw-r--r-- | etc/dict.lua | 182 | ||||
-rw-r--r-- | etc/qp.lua | 10 | ||||
-rw-r--r-- | makefile.dist | 83 | ||||
-rw-r--r-- | samples/README | 27 | ||||
-rw-r--r-- | src/auxiliar.c | 1 | ||||
-rw-r--r-- | src/ftp.lua | 4 | ||||
-rw-r--r-- | src/luasocket.c | 1 | ||||
-rw-r--r-- | test/README | 13 | ||||
-rw-r--r-- | test/ltn12test.lua | 5 | ||||
-rw-r--r-- | test/stufftest.lua | 6 | ||||
-rw-r--r-- | test/testmesg.lua | 7 |
14 files changed, 322 insertions, 160 deletions
@@ -1,29 +1,86 @@ | |||
1 | Major C code rewrite. Code is modular and extensible. Hopefully, next | 1 | What's New |
2 | versions will include code for local domain sockets, file descriptors, | ||
3 | pipes (on unix) and named pipes (on windows) as a bonus. | ||
4 | 2 | ||
5 | All functions provided by the library are in the namespace "socket". | 3 | Everything is new! Many changes for 2.0 happened in the C layer, |
6 | Functions such as send/receive/timeout/close etc do not exist anymore as | 4 | which has been almost completely rewritten. The code has been ported to |
7 | stand alone functions. They are now only available as methods of the | 5 | Lua 5.0 and greatly improved. There have also been some API changes |
8 | appropriate objects. | 6 | that made the interface simpler and more consistent. Here are some of |
7 | the changes that made it into version 2.0: | ||
9 | 8 | ||
10 | TCP has been changed to become more uniform. First create an object, then | 9 | <> Major C code rewrite. Code is modular and extensible. Hopefully, other |
11 | connect 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 | ||
15 | All functions return a non-nil value as first return value if successful. | 13 | <> Everything that is exported by the library is exported inside |
16 | All functions return whatever could be retrieved followed by error message | 14 | namespaces. These should be obtained with calls to the |
17 | in case of error. The best way to check for errors is to check for the | 15 | 'require' function; |
18 | presence of an error message. WARNING: The send function was affected. | ||
19 | 16 | ||
20 | Better 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 | ||
22 | UDP connected udp sockets can break association with peer by calling | 22 | <> All functions return a non-nil value as first return value if successful. |
23 | setpeername 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 | ||
25 | socket.sleep and socket.time are now part of the library and are | 26 | <> Greatly reduced the number of times the C select is called |
26 | supported. | 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 | |||
67 | Lots 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 | ||
28 | Socket options interface has been improved and TCP now also supports socket | ||
29 | options. | ||
@@ -1,9 +1,11 @@ | |||
1 | This release is work in progress. It has been tested on WinXP, Mac OS X, | 1 | This release is a "beta" version. It has been tested on WinXP, Mac OS X, |
2 | SunOS and Linux. | 2 | SunOS and Linux. Although no major API changes should happen before the |
3 | final version is released, please look for and report any bugs (or | ||
4 | "features") you encounter. | ||
3 | 5 | ||
4 | In this version, all Lua code should be built into the binary. For that, you | 6 | For this version, all modules should be loaded with the provided "require" |
5 | will need a working versions of luac and bin2c, both available with your | 7 | function, and the binaries should be compliled as shared libraries. Check |
6 | Lua distribution. Check the makefile for details. | 8 | the makefiles in the distribution and the readme in the 'etc' directory. |
7 | 9 | ||
8 | Have fun, | 10 | Have fun, |
9 | Diego Nehab. | 11 | Diego Nehab. |
@@ -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 | ||
6 | These are modules to suport dynamic loading of LuaSocket by the stand alone | 6 | These are modules to suport dynamic loading of LuaSocket by the stand alone |
7 | Lua Interpreter with the use of the "require" function. For my Mac OS X | 7 | Lua Interpreter with the use of new "require" and "requirelib" functions. |
8 | system, I place all files in /Users/diego/tec/luasocket | 8 | For my Mac OS X box, for instance, I place all files in |
9 | and 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 | ||
16 | With that, I can run any luasocket application with the command line: | 15 | With that, I can run any luasocket application with the command line: |
17 | 16 | ||
18 | lua -l socket <script> | 17 | lua <script> |
19 | 18 | ||
19 | as long as the script uses "require" to load the needed namespaces. | ||
20 | Much nicer than having to build a new executable just to initialize | 20 | Much nicer than having to build a new executable just to initialize |
21 | LuaSocket! | 21 | LuaSocket! |
22 | 22 | ||
23 | |||
24 | tftp.lua -- Trivial FTP client | 23 | tftp.lua -- Trivial FTP client |
25 | 24 | ||
26 | This module implements file retrieval by the TFTP protocol. Its main use | 25 | This module implements file retrieval by the TFTP protocol. Its main use |
27 | is to test the UDP code, but someone might find it usefull. | 26 | was to test the UDP code, but since someone found it usefull, I turned it |
27 | into a module that is almost official (no uploads, yet). | ||
28 | |||
29 | dict.lua -- Dict client | ||
30 | |||
31 | The dict.lua module started with a cool simple client for the DICT | ||
32 | protocol, written by Luiz Henrique Figueiredo. This new version has been | ||
33 | converted into a library, similar to the HTTP and FTP libraries, that can | ||
34 | be used from within any luasocket application. Take a look on the source | ||
35 | code 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 | ||
31 | This little program is a client that uses the FTP and HTTP code to | 39 | This little program is a client that uses the FTP and HTTP code to |
32 | implement a command line file graber. Just run | 40 | implement 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 | ||
36 | to download a remote file (either ftp:// or http://) to the specified | 44 | to download a remote file (either ftp:// or http://) to the specified |
37 | local file. The program also prints the download throughput, elapsed | 45 | local 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 | |||
44 | the LuaSocket library and the Lua language. It has not been thoroughly | 52 | the LuaSocket library and the Lua language. It has not been thoroughly |
45 | tested, but it should work. Just run | 53 | tested, 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 | ||
49 | and open the result to see a list of broken links. | 57 | and 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 | ----------------------------------------------------------------------------- | ||
7 | local socket = require("socket") | 11 | local socket = require("socket") |
12 | local url = require("url") | ||
13 | local tp = require("tp") | ||
8 | 14 | ||
9 | function 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 | 18 | HOST = "dict.org" |
13 | code = socket.skip(2, string.find(line, "^(%d%d%d)")) | 19 | PORT = 2628 |
14 | code = tonumber(code) | 20 | TIMEOUT = 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 | 25 | local metat = { __index = {} } |
26 | |||
27 | function open(host, port) | ||
28 | local tp = socket.try(tp.connect(host or HOST, port or PORT, TIMEOUT)) | ||
29 | return setmetatable({tp = tp}, metat) | ||
20 | end | 30 | end |
21 | 31 | ||
22 | function get_def(sock) | 32 | function metat.__index:greet() |
23 | local line, err = sock:receive() | 33 | return socket.try(self.tp:check(220)) |
24 | local def = "" | 34 | end |
25 | while (not err) and line ~= "." do | 35 | |
26 | def = def .. line .. "\n" | 36 | function 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*)"))) | ||
39 | end | ||
40 | |||
41 | function 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 | ||
31 | end | 49 | end |
32 | 50 | ||
33 | function dict_open() | 51 | function 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 | ||
40 | end | 62 | end |
41 | 63 | ||
42 | function dict_define(sock, word, dict) | 64 | function 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$", "") | 79 | end |
80 | |||
81 | function metat.__index:quit() | ||
82 | self.tp:command("QUIT") | ||
83 | return self:check(221) | ||
84 | end | ||
85 | |||
86 | function metat.__index:close() | ||
87 | return self.tp:close() | ||
59 | end | 88 | end |
60 | 89 | ||
61 | function 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() | 93 | local default = { |
65 | return code | 94 | scheme = "dict", |
95 | host = "dict.org" | ||
96 | } | ||
97 | |||
98 | local function there(f) | ||
99 | if f == "" then return nil | ||
100 | else return f end | ||
66 | end | 101 | end |
67 | 102 | ||
68 | function dict_get(word, dict) | 103 | local 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 | ||
74 | end | 119 | end |
75 | 120 | ||
76 | if arg and arg[1] then | 121 | local 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() |
79 | else | 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 | ||
81 | end | 136 | end |
137 | |||
138 | local function sget(u) | ||
139 | local gett = parse(u) | ||
140 | return tget(gett) | ||
141 | end | ||
142 | |||
143 | --function socket.protect(f) return f end | ||
144 | get = socket.protect(function(gett) | ||
145 | if type(gett) == "string" then return sget(gett) | ||
146 | else return tget(gett) end | ||
147 | end) | ||
@@ -1,5 +1,11 @@ | |||
1 | require("ltn12") | 1 | ----------------------------------------------------------------------------- |
2 | require("mime") | 2 | -- Little program to convert to and from Quoted-Printable |
3 | -- LuaSocket sample files | ||
4 | -- Author: Diego Nehab | ||
5 | -- RCS ID: $Id$ | ||
6 | ----------------------------------------------------------------------------- | ||
7 | local ltn12 = require("ltn12") | ||
8 | local mime = require("mime") | ||
3 | local convert | 9 | local convert |
4 | arg = arg or {} | 10 | arg = arg or {} |
5 | local mode = arg and arg[1] or "-et" | 11 | local 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 | ||
5 | DIST = luasocket-2.0-alpha | 5 | DIST = luasocket-2.0-beta |
6 | 6 | ||
7 | LUA = \ | 7 | LUA = \ |
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 | ||
17 | TESTS = \ | 17 | TESTS = \ |
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 | ||
30 | EXAMPLES = \ | 22 | EXAMPLES = \ |
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 | ||
39 | ETC = \ | 35 | ETC = \ |
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 | ||
48 | MAIN = \ | 42 | CORE = \ |
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 | ||
73 | MAKE = \ | ||
74 | makefile.Darwin \ | ||
75 | makefile.Linux \ | ||
76 | luasocket.export \ | ||
77 | mime.export \ | ||
78 | luasocket.sln \ | ||
79 | luasocket.vcproj \ | ||
80 | mime.vcproj | ||
81 | |||
82 | MANUAL = \ | ||
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 | |||
75 | dist: | 99 | dist: |
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 | |||
95 | clean: | 124 | clean: |
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 @@ | |||
1 | This directory contains some sample programs using LuaSocket. This code | 1 | This directory contains some sample programs using LuaSocket. This code |
2 | is not supported. | 2 | is not supported. |
3 | 3 | ||
4 | listener.lua -- socket to stdout | 4 | listener.lua -- socket to stdout |
@@ -7,21 +7,26 @@ is not supported. | |||
7 | listener.lua and talker.lua are about the simplest applications you can | 7 | listener.lua and talker.lua are about the simplest applications you can |
8 | write using LuaSocket. Run | 8 | write 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 | ||
12 | on different terminals. Whatever you type on talk.lua will be | 12 | on different terminals. Whatever you type on talk.lua will be |
13 | printed by listen.lua. | 13 | printed by listen.lua. |
14 | 14 | ||
15 | dict.lua -- dict client | 15 | b64.lua |
16 | qp.lua | ||
17 | eol.lua | ||
16 | 18 | ||
17 | The dict.lua module was a cool simple client for the DICT protocol, | 19 | These are tiny programs that perform Base64, Quoted-Printable and |
18 | written by Luiz Henrique Figueiredo. This new version has been converted | 20 | end-of-line marker conversions. |
19 | into a library, similar to the HTTP and FTP libraries, that can be used | 21 | |
20 | from within any luasocket application. Take a look on the source code | 22 | cddb.lua -- CDDB client |
21 | and you will be able to figure out how to use it. | 23 | |
24 | This is the first try on a simple CDDB client. Not really useful, but one | ||
25 | day it might become a module. | ||
22 | 26 | ||
23 | daytimeclnt.lua -- day time client | 27 | daytimeclnt.lua -- day time client |
24 | 28 | ||
29 | |||
25 | Just run the program to retrieve the hour and date in readable form from | 30 | Just run the program to retrieve the hour and date in readable form from |
26 | any server running an UDP daytime daemon. | 31 | any server running an UDP daytime daemon. |
27 | 32 | ||
@@ -40,5 +45,9 @@ function and shows how to create a simple server whith LuaSocket. Just | |||
40 | run tinyirc.lua and then open as many telnet connections as you want | 45 | run tinyirc.lua and then open as many telnet connections as you want |
41 | to ports 8080 and 8081. | 46 | to ports 8080 and 8081. |
42 | 47 | ||
48 | check-memory.lua -- checks memory consumption | ||
49 | |||
50 | This is just to see how much memory each module uses. | ||
51 | |||
43 | Good luck, | 52 | Good luck, |
44 | Diego. | 53 | Diego. |
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 | \*-------------------------------------------------------------------------*/ |
18 | int aux_open(lua_State *L) { | 18 | int 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 | ----------------------------------------------------------------------------- |
178 | local function tput(putt) | 178 | local 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) | |||
216 | end) | 216 | end) |
217 | 217 | ||
218 | local function tget(gett) | 218 | local 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 | \*-------------------------------------------------------------------------*/ |
77 | static int global_unload(lua_State *L) { | 77 | static 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 | ||
10 | To run the automatic tests on your system, make sure to compile the | 9 | To run these tests, just run lua on the server and then on the client. |
11 | library with _DEBUG defined (check makefile) and then open two | ||
12 | terminals. Run 'luasocket testsrvr.lua' on one of them and 'luasocket | ||
13 | testclnt.lua' on the other. The programs should start talking to each | ||
14 | other 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 | |||
20 | To run these tests, just run luasocket on them and see the results. | ||
21 | 10 | ||
22 | Good luck, | 11 | Good luck, |
23 | Diego. | 12 | Diego. |
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 @@ | |||
1 | a = ltn12.source.file(io.open("luasocket.lua")) | ||
2 | b = ltn12.source.file(io.open("auxiliar.lua")) | ||
3 | c = ltn12.source.cat(a, b) | ||
4 | d = ltn12.sink.file(io.stdout) | ||
5 | socket.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 @@ | |||
1 | smtp = require("smtp") | 1 | mime = require("mime") |
2 | 2 | ||
3 | function test_dot(original, right) | 3 | function 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") |
7 | end | 7 | end |
8 | 8 | ||
9 | function test_stuff(original, right) | 9 | function 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") |
13 | end | 13 | end |
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 |
52 | r, e = smtp.send{ | 52 | r, 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 | ||
59 | print(r, e) | 58 | print(r, e) |