diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-20 08:56:19 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-20 08:56:19 +0000 |
| commit | 5e09779c7f6b1710150d5a0f12d86ded7ede75c6 (patch) | |
| tree | ffd2e2e7d918cc30015c89bd14122aa8cadb1546 | |
| parent | f20f4889bfe5a02cd9b77868b90cc8042352176a (diff) | |
| download | luasocket-5e09779c7f6b1710150d5a0f12d86ded7ede75c6.tar.gz luasocket-5e09779c7f6b1710150d5a0f12d86ded7ede75c6.tar.bz2 luasocket-5e09779c7f6b1710150d5a0f12d86ded7ede75c6.zip | |
In pre release mode!
| -rw-r--r-- | NEW | 69 | ||||
| -rw-r--r-- | config | 20 | ||||
| -rw-r--r-- | doc/http.html | 13 | ||||
| -rw-r--r-- | doc/index.html | 7 | ||||
| -rw-r--r-- | doc/installation.html | 8 | ||||
| -rw-r--r-- | doc/tcp.html | 1 | ||||
| -rw-r--r-- | etc/README | 93 | ||||
| -rw-r--r-- | etc/check-memory.lua | 2 | ||||
| -rw-r--r-- | makefile.dist | 211 | ||||
| -rw-r--r-- | samples/README | 57 | ||||
| -rw-r--r-- | samples/forward.lua | 207 | ||||
| -rw-r--r-- | samples/lpr.lua | 2 | ||||
| -rw-r--r-- | test/httptest.lua | 4 |
13 files changed, 283 insertions, 411 deletions
| @@ -1,21 +1,54 @@ | |||
| 1 | What's New | 1 | What's New |
| 2 | 2 | ||
| 3 | The big change for the 2.0 (beta3) release was the adoption of the Lua | 3 | There is no big change for the 2.0 (final) release. It is |
| 4 | 5.1 package proposal. There were several bug fixes too (a beta is a | 4 | basically a bug fix release. The main improvement is in the |
| 5 | beta, is a beta). | 5 | non-blocking support. |
| 6 | 6 | ||
| 7 | * New compat-5.1 distribution: | 7 | * New: sample module dispatch.lua implements a coroutine |
| 8 | - Instalation uses new directory structure; | 8 | based dispatcher; |
| 9 | - Namespace hierarchy is in now back in use (ex. socket.url instead of url); | 9 | * New: sample check-links.lua works both in blocking and |
| 10 | - All modules call require even for standard libraries; | 10 | non-blocking mode using coroutines (using the new |
| 11 | * LTN12 avoids coroutines (so you can go wild on the C side); | 11 | dispatcher); |
| 12 | * socket.select wasn't calling tm_markstart; | 12 | * New: sample forward.lua implements a coroutine based |
| 13 | * Kludge on wsocket.c:sock_send for Windows timeout issue moved to | 13 | forward server (using the new dispatcher); |
| 14 | buffer.c:sendraw so it's not a kludge anymore; | 14 | * Improved: tcp:send(data, i, j) to return (i+sent-1). This |
| 15 | * socket.protect only catches errors thrown by socket.try; | 15 | is great for non-blocking I/O, but might break some code; |
| 16 | * Fixed udp:sendto to call sock_sendto instead of sock_send; | 16 | * Improved: HTTP, SMTP, and FTP functions to accept a new |
| 17 | * close wasn't returning 1! | 17 | field create that overrides the function used to create |
| 18 | * socket.gettime returns time since Unix Epoch 1/1/1970 (UTC) | 18 | socket objects; |
| 19 | * socket.sleep is robust to interrupts; | 19 | * Improved: smtp.message now supports multipart/alternative |
| 20 | * http.PROXY wasn't working. | 20 | (for the HTML messages we all love so much); |
| 21 | * fixed some of the examples | 21 | * Fixed: smtp.send was hanging on errors returned by LTN12 |
| 22 | sources; | ||
| 23 | * Fixed: url.absolute() to work when base_url is in parsed | ||
| 24 | form; | ||
| 25 | * Fixed: http.request() not to redirect when the location | ||
| 26 | header is empty (naughty servers...); | ||
| 27 | * Fixed: tcp{client}:shutdown() to check for class instead | ||
| 28 | of group; | ||
| 29 | * Fixed: The manual to stop using socket.try() in place of | ||
| 30 | assert(), since it can't; | ||
| 31 | * Improved: Got rid of package.loaded.base = _G kludge; | ||
| 32 | * Fixed: Parts of the manual referred to require("http") | ||
| 33 | instead of require("socket.http"); | ||
| 34 | * Improved: Socket and MIME binaries are called 'core' each | ||
| 35 | inside their directory (ex. "socket/core.dll"). The 'l' | ||
| 36 | prefix was just a bad idea; | ||
| 37 | * Improved: Using bundles in Mac OS X, instead of dylibs; | ||
| 38 | * Fixed: luasocket.h to export luaopen_socket_core; | ||
| 39 | * Fixed: udp:setpeername() so you can "disconnect" an UDP | ||
| 40 | socket; | ||
| 41 | * Fixed: A weird bug in HTTP support that caused some | ||
| 42 | requests to fail (Florian Berger); | ||
| 43 | * Fixed: Bug in socket.select() that caused sockets with | ||
| 44 | descriptor 0 to be ignored (Renato Maia); | ||
| 45 | * Fixed: "Bug" that caused dns.toip() to crash under uLinux | ||
| 46 | (William Trenker); | ||
| 47 | * Fixed: "Bug" that caused gethostbyname to crash under VMS | ||
| 48 | (Renato Maia); | ||
| 49 | * Fixed: tcp:send("") to return 0 bytes sent (Alexander | ||
| 50 | Marinov); | ||
| 51 | * Improved: socket.DEBUG and socket.VERSION became | ||
| 52 | socket._DEBUGs and socket._VERSION for uniformity with other | ||
| 53 | libraries; | ||
| 54 | * Improved: socket.select now works on empty sets on Windows. | ||
| @@ -37,20 +37,20 @@ INSTALL_EXEC=cp | |||
| 37 | # Compiler and linker settings | 37 | # Compiler and linker settings |
| 38 | # for Mac OS X | 38 | # for Mac OS X |
| 39 | # | 39 | # |
| 40 | #CC=gcc | 40 | CC=gcc |
| 41 | #DEF=-DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN | 41 | DEF=-DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN |
| 42 | #CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common | 42 | CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common |
| 43 | #LDFLAGS=-bundle -undefined dynamic_lookup | 43 | LDFLAGS=-bundle -undefined dynamic_lookup |
| 44 | #LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc | 44 | LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc |
| 45 | 45 | ||
| 46 | #------ | 46 | #------ |
| 47 | # Compiler and linker settings | 47 | # Compiler and linker settings |
| 48 | # for Linux | 48 | # for Linux |
| 49 | CC=gcc | 49 | #CC=gcc |
| 50 | DEF=-DLUASOCKET_DEBUG | 50 | #DEF=-DLUASOCKET_DEBUG |
| 51 | CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fpic | 51 | #CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fpic |
| 52 | LDFLAGS=-O -shared | 52 | #LDFLAGS=-O -shared |
| 53 | LD=gcc | 53 | #LD=gcc |
| 54 | 54 | ||
| 55 | #------ | 55 | #------ |
| 56 | # End of makefile configuration | 56 | # End of makefile configuration |
diff --git a/doc/http.html b/doc/http.html index 096ab2b..9d80c23 100644 --- a/doc/http.html +++ b/doc/http.html | |||
| @@ -209,11 +209,16 @@ Here are a few examples with the simple interface: | |||
| 209 | 209 | ||
| 210 | <pre class=example> | 210 | <pre class=example> |
| 211 | -- load the http module | 211 | -- load the http module |
| 212 | http = require("socket.http") | 212 | local io = require("io") |
| 213 | local http = require("socket.http") | ||
| 214 | local ltn12 = require("ltn12") | ||
| 213 | 215 | ||
| 214 | -- connect to server "www.tecgraf.puc-rio.br" and retrieves this manual | 216 | -- connect to server "www.cs.princeton.edu" and retrieves this manual |
| 215 | -- file from "/luasocket/http.html" | 217 | -- file from "~diego/professional/luasocket/http.html" and print it to stdout |
| 216 | b = http.request("http://www.tecgraf.puc-rio.br/luasocket/http.html") | 218 | http.request{ |
| 219 | url = "http://www.cs.princeton.edu/~diego/professional/luasocket/http.html", | ||
| 220 | sink = ltn12.sink.file(io.stdout) | ||
| 221 | } | ||
| 217 | 222 | ||
| 218 | -- connect to server "www.example.com" and tries to retrieve | 223 | -- connect to server "www.example.com" and tries to retrieve |
| 219 | -- "/private/index.html". Fails because authentication is needed. | 224 | -- "/private/index.html". Fails because authentication is needed. |
diff --git a/doc/index.html b/doc/index.html index 3d5acb3..7ac0d4c 100644 --- a/doc/index.html +++ b/doc/index.html | |||
| @@ -165,6 +165,13 @@ support. | |||
| 165 | </p> | 165 | </p> |
| 166 | 166 | ||
| 167 | <ul> | 167 | <ul> |
| 168 | <li> New: sample module <tt>dispatch.lua</tt> implements a | ||
| 169 | coroutine based dispatcher; | ||
| 170 | <li> New: sample <tt>check-links.lua</tt> works | ||
| 171 | both in blocking and non-blocking mode using coroutines | ||
| 172 | (using the new dispatcher); | ||
| 173 | <li> New: sample <tt>forward.lua</tt> implements a coroutine | ||
| 174 | based forward server (using the new dispatcher); | ||
| 168 | <li> Improved: <tt>tcp:send(data, i, j)</tt> to return <tt>(i+sent-1)</tt>. This is great for non-blocking I/O, but might break some code; | 175 | <li> Improved: <tt>tcp:send(data, i, j)</tt> to return <tt>(i+sent-1)</tt>. This is great for non-blocking I/O, but might break some code; |
| 169 | <li> Improved: HTTP, SMTP, and FTP functions to accept a new field | 176 | <li> Improved: HTTP, SMTP, and FTP functions to accept a new field |
| 170 | <tt>create</tt> that overrides the function used to create socket objects; | 177 | <tt>create</tt> that overrides the function used to create socket objects; |
diff --git a/doc/installation.html b/doc/installation.html index 1b82ed3..4086f41 100644 --- a/doc/installation.html +++ b/doc/installation.html | |||
| @@ -76,9 +76,9 @@ distribution directory structure:</p> | |||
| 76 | <pre class=example> | 76 | <pre class=example> |
| 77 | <SHARE>/compat-5.1.lua | 77 | <SHARE>/compat-5.1.lua |
| 78 | <SHARE>/ltn12.lua | 78 | <SHARE>/ltn12.lua |
| 79 | <SHARE>/mime/init.lua (originally mime.lua) | 79 | <SHARE>/mime/mime.lua |
| 80 | <LIB>/mime/core.dll | 80 | <LIB>/mime/core.dll |
| 81 | <SHARE>/socket/init.lua (originally socket.lua) | 81 | <SHARE>/socket/socket.lua |
| 82 | <LIB>/socket/core.dll | 82 | <LIB>/socket/core.dll |
| 83 | <SHARE>/socket/http.lua | 83 | <SHARE>/socket/http.lua |
| 84 | <SHARE>/socket/tp.lua | 84 | <SHARE>/socket/tp.lua |
| @@ -88,9 +88,7 @@ distribution directory structure:</p> | |||
| 88 | </pre> | 88 | </pre> |
| 89 | 89 | ||
| 90 | <p> Naturally, on Unix systems, <tt>core.dll</tt> | 90 | <p> Naturally, on Unix systems, <tt>core.dll</tt> |
| 91 | would be replaced by <tt>core.so</tt>. Notice that in the instalation, | 91 | would be replaced by <tt>core.so</tt>. |
| 92 | <tt>socket.lua</tt> becomes <tt>socket/init.lua</tt>, and the same happens | ||
| 93 | with <tt>mime.lua</tt>, which becomes <tt>mime/init.lua</tt>. | ||
| 94 | </p> | 92 | </p> |
| 95 | 93 | ||
| 96 | <p> In order for the interpreter to find all LuaSocket components, three | 94 | <p> In order for the interpreter to find all LuaSocket components, three |
diff --git a/doc/tcp.html b/doc/tcp.html index 5c810de..2c687c0 100644 --- a/doc/tcp.html +++ b/doc/tcp.html | |||
| @@ -446,6 +446,7 @@ The method returns 1 in case of success and <tt><b>nil</b></tt> otherwise. | |||
| 446 | <!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 446 | <!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
| 447 | 447 | ||
| 448 | <p class=name id=settimeout> | 448 | <p class=name id=settimeout> |
| 449 | master:<b>settimeout(</b>value [, mode]<b>)</b><br> | ||
| 449 | client:<b>settimeout(</b>value [, mode]<b>)</b><br> | 450 | client:<b>settimeout(</b>value [, mode]<b>)</b><br> |
| 450 | server:<b>settimeout(</b>value [, mode]<b>)</b> | 451 | server:<b>settimeout(</b>value [, mode]<b>)</b> |
| 451 | </p> | 452 | </p> |
| @@ -1,48 +1,89 @@ | |||
| 1 | This directory contains code that is more useful than the examples. This code | 1 | This directory contains code that is more useful than the |
| 2 | *is* supported. | 2 | samples. This code *is* supported. |
| 3 | 3 | ||
| 4 | tftp.lua -- Trivial FTP client | 4 | tftp.lua -- Trivial FTP client |
| 5 | 5 | ||
| 6 | This module implements file retrieval by the TFTP protocol. Its main use | 6 | This module implements file retrieval by the TFTP protocol. |
| 7 | was to test the UDP code, but since someone found it usefull, I turned it | 7 | Its main use was to test the UDP code, but since someone |
| 8 | into a module that is almost official (no uploads, yet). | 8 | found it usefull, I turned it into a module that is almost |
| 9 | official (no uploads, yet). | ||
| 9 | 10 | ||
| 10 | dict.lua -- Dict client | 11 | dict.lua -- Dict client |
| 11 | 12 | ||
| 12 | The dict.lua module started with a cool simple client for the DICT | 13 | The dict.lua module started with a cool simple client |
| 13 | protocol, written by Luiz Henrique Figueiredo. This new version has been | 14 | for the DICT protocol, written by Luiz Henrique Figueiredo. |
| 14 | converted into a library, similar to the HTTP and FTP libraries, that can | 15 | This new version has been converted into a library, similar |
| 15 | be used from within any luasocket application. Take a look on the source | 16 | to the HTTP and FTP libraries, that can be used from within |
| 16 | code and you will be able to figure out how to use it. | 17 | any luasocket application. Take a look on the source code |
| 18 | and you will be able to figure out how to use it. | ||
| 17 | 19 | ||
| 18 | lp.lua -- LPD client | 20 | lp.lua -- LPD client library |
| 19 | 21 | ||
| 20 | The lp.lua module implements the client part of the Line Printer Daemon | 22 | The lp.lua module implements the client part of the Line |
| 21 | protocol, used to print files on Unix machines. It is courtesy of David | 23 | Printer Daemon protocol, used to print files on Unix |
| 22 | Burgess and I heard he would be the one supporting it, even after I messed | 24 | machines. It is courtesy of David Burgess! See the source |
| 23 | with it. See the source code and the lpr.lua in the examples directory. | 25 | code and the lpr.lua in the examples directory. |
| 26 | |||
| 27 | b64.lua | ||
| 28 | qp.lua | ||
| 29 | eol.lua | ||
| 30 | |||
| 31 | These are tiny programs that perform Base64, | ||
| 32 | Quoted-Printable and end-of-line marker conversions. | ||
| 24 | 33 | ||
| 25 | get.lua -- file retriever | 34 | get.lua -- file retriever |
| 26 | 35 | ||
| 27 | This little program is a client that uses the FTP and HTTP code to | 36 | This little program is a client that uses the FTP and |
| 28 | implement a command line file graber. Just run | 37 | HTTP code to implement a command line file graber. Just |
| 38 | run | ||
| 29 | 39 | ||
| 30 | lua get.lua <remote-file> [<local-file>] | 40 | lua get.lua <remote-file> [<local-file>] |
| 31 | 41 | ||
| 32 | to download a remote file (either ftp:// or http://) to the specified | 42 | to download a remote file (either ftp:// or http://) to |
| 33 | local file. The program also prints the download throughput, elapsed | 43 | the specified local file. The program also prints the |
| 34 | time, bytes already downloaded etc during download. | 44 | download throughput, elapsed time, bytes already downloaded |
| 45 | etc during download. | ||
| 46 | |||
| 47 | check-memory.lua -- checks memory consumption | ||
| 48 | |||
| 49 | This is just to see how much memory each module uses. | ||
| 50 | |||
| 51 | dispatch.lua -- coroutine based dispatcher | ||
| 52 | |||
| 53 | This is a first try at a coroutine based non-blocking | ||
| 54 | dispatcher for LuaSocket. Take a look at 'check-links.lua' | ||
| 55 | and at 'forward.lua' to see how to use it. | ||
| 35 | 56 | ||
| 36 | check-links.lua -- HTML link checker program | 57 | check-links.lua -- HTML link checker program |
| 37 | 58 | ||
| 38 | This little program scans a HTML file and checks for broken links. It is | 59 | This little program scans a HTML file and checks for broken |
| 39 | similar to check-links.pl by Jamie Zawinski, but uses all facilities of | 60 | links. It is similar to check-links.pl by Jamie Zawinski, |
| 40 | the LuaSocket library and the Lua language. It has not been thoroughly | 61 | but uses all facilities of the LuaSocket library and the Lua |
| 41 | tested, but it should work. Just run | 62 | language. It has not been thoroughly tested, but it should |
| 63 | work. Just run | ||
| 64 | |||
| 65 | lua check-links.lua [-n] {<url>} > output | ||
| 66 | |||
| 67 | and open the result to see a list of broken links. You can | ||
| 68 | also use the '-n' switch to run the same program in | ||
| 69 | non-blocking mode to see how much faster things can get. | ||
| 70 | |||
| 71 | forward.lua -- coroutine based forward server | ||
| 72 | |||
| 73 | This is a forward server that can accept several connections | ||
| 74 | and transfers simultaneously using non-blocking I/O and the | ||
| 75 | coroutine-based dispatcher. You can run, for example | ||
| 76 | |||
| 77 | lua forward.lua 8080:proxy.com:3128 | ||
| 78 | |||
| 79 | to redirect all local conections to port 8080 to the host | ||
| 80 | 'proxy.com' at port 3128. | ||
| 42 | 81 | ||
| 43 | lua check-links.lua {<url>} > output | 82 | unix.c and unix.h |
| 44 | 83 | ||
| 45 | and open the result to see a list of broken links. | 84 | This is an implementation of Unix local domain sockets and |
| 85 | demonstrates how to extend LuaSocket with a new type of | ||
| 86 | transport. It has been tested on Linux and on Mac OS X. | ||
| 46 | 87 | ||
| 47 | Good luck, | 88 | Good luck, |
| 48 | Diego. | 89 | Diego. |
diff --git a/etc/check-memory.lua b/etc/check-memory.lua index 7bcdf67..7bd984d 100644 --- a/etc/check-memory.lua +++ b/etc/check-memory.lua | |||
| @@ -7,7 +7,7 @@ function load(s) | |||
| 7 | print(s .. ":\t " .. (b-a) .. "k") | 7 | print(s .. ":\t " .. (b-a) .. "k") |
| 8 | end | 8 | end |
| 9 | 9 | ||
| 10 | load("url") | 10 | load("socket.url") |
| 11 | load("ltn12") | 11 | load("ltn12") |
| 12 | load("socket") | 12 | load("socket") |
| 13 | load("mime") | 13 | load("mime") |
diff --git a/makefile.dist b/makefile.dist index 8b79653..54a9751 100644 --- a/makefile.dist +++ b/makefile.dist | |||
| @@ -4,125 +4,128 @@ | |||
| 4 | 4 | ||
| 5 | DIST = luasocket-2.0 | 5 | DIST = luasocket-2.0 |
| 6 | 6 | ||
| 7 | COMPAT = compat-5.1r4 | 7 | COMPAT = src/compat-5.1r4 |
| 8 | 8 | ||
| 9 | LUA = \ | 9 | |
| 10 | ftp.lua \ | 10 | TEST = \ |
| 11 | http.lua \ | 11 | test/testclnt.lua \ |
| 12 | ltn12.lua \ | 12 | test/testsrvr.lua \ |
| 13 | mime.lua \ | 13 | test/testsupport.lua |
| 14 | smtp.lua \ | 14 | |
| 15 | socket.lua \ | 15 | SAMPLES = \ |
| 16 | tp.lua \ | 16 | samples/README \ |
| 17 | url.lua | 17 | samples/cddb.lua \ |
| 18 | 18 | samples/daytimeclnt.lua \ | |
| 19 | TESTS = \ | 19 | samples/echoclnt.lua \ |
| 20 | testclnt.lua \ | 20 | samples/echosrvr.lua \ |
| 21 | testsrvr.lua \ | 21 | samples/listener.lua \ |
| 22 | testsupport.lua | 22 | samples/lpr.lua \ |
| 23 | 23 | samples/talker.lua \ | |
| 24 | EXAMPLES = \ | 24 | samples/tinyirc.lua |
| 25 | check-memory.lua \ | ||
| 26 | b64.lua \ | ||
| 27 | cddb.lua \ | ||
| 28 | daytimeclnt.lua \ | ||
| 29 | echoclnt.lua \ | ||
| 30 | echosrvr.lua \ | ||
| 31 | eol.lua \ | ||
| 32 | listener.lua \ | ||
| 33 | qp.lua \ | ||
| 34 | lpr.lua \ | ||
| 35 | talker.lua \ | ||
| 36 | tinyirc.lua | ||
| 37 | 25 | ||
| 38 | ETC = \ | 26 | ETC = \ |
| 39 | check-links.lua \ | 27 | etc/README \ |
| 40 | check-links-nb.lua \ | 28 | etc/b64.lua \ |
| 41 | dict.lua \ | 29 | etc/check-links.lua \ |
| 42 | get.lua \ | 30 | etc/check-memory.lua \ |
| 43 | unix.c \ | 31 | etc/dict.lua \ |
| 44 | unix.h \ | 32 | etc/dispatch.lua \ |
| 45 | lp.lua \ | 33 | etc/eol.lua \ |
| 46 | tftp.lua | 34 | etc/forward.lua \ |
| 47 | 35 | etc/get.lua \ | |
| 48 | CORE = \ | 36 | etc/links \ |
| 49 | auxiliar.c \ | 37 | etc/lp.lua \ |
| 50 | auxiliar.h \ | 38 | etc/qp.lua \ |
| 51 | buffer.c \ | 39 | etc/tftp.lua |
| 52 | buffer.h \ | 40 | |
| 53 | except.c \ | 41 | SRC = \ |
| 54 | except.h \ | 42 | src/auxiliar.c \ |
| 55 | inet.c \ | 43 | src/auxiliar.h \ |
| 56 | inet.h \ | 44 | src/buffer.c \ |
| 57 | io.c \ | 45 | src/buffer.h \ |
| 58 | io.h \ | 46 | src/except.c \ |
| 59 | luasocket.c \ | 47 | src/except.h \ |
| 60 | luasocket.h \ | 48 | src/inet.c \ |
| 61 | mime.c \ | 49 | src/inet.h \ |
| 62 | mime.h \ | 50 | src/io.c \ |
| 63 | options.c \ | 51 | src/io.h \ |
| 64 | options.h \ | 52 | src/luasocket.c \ |
| 65 | select.c \ | 53 | src/luasocket.h \ |
| 66 | select.h \ | 54 | src/mime.c \ |
| 67 | socket.h \ | 55 | src/mime.h \ |
| 68 | tcp.c \ | 56 | src/options.c \ |
| 69 | tcp.h \ | 57 | src/options.h \ |
| 70 | timeout.c \ | 58 | src/select.c \ |
| 71 | timeout.h \ | 59 | src/select.h \ |
| 72 | udp.c \ | 60 | src/socket.h \ |
| 73 | udp.h \ | 61 | src/tcp.c \ |
| 74 | usocket.c \ | 62 | src/tcp.h \ |
| 75 | usocket.h \ | 63 | src/timeout.c \ |
| 76 | wsocket.c \ | 64 | src/timeout.h \ |
| 77 | wsocket.h | 65 | src/udp.c \ |
| 66 | src/udp.h \ | ||
| 67 | src/unix.c \ | ||
| 68 | src/unix.h \ | ||
| 69 | src/usocket.c \ | ||
| 70 | src/usocket.h \ | ||
| 71 | src/wsocket.c \ | ||
| 72 | src/wsocket.h \ | ||
| 73 | src/ftp.lua \ | ||
| 74 | src/http.lua \ | ||
| 75 | src/ltn12.lua \ | ||
| 76 | src/mime.lua \ | ||
| 77 | src/smtp.lua \ | ||
| 78 | src/socket.lua \ | ||
| 79 | src/tp.lua \ | ||
| 80 | src/url.lua | ||
| 78 | 81 | ||
| 79 | MAKE = \ | 82 | MAKE = \ |
| 80 | makefile \ | 83 | makefile \ |
| 81 | config \ | 84 | config \ |
| 82 | luasocket.sln \ | 85 | luasocket.sln \ |
| 83 | luasocket.vcproj \ | 86 | socket.vcproj \ |
| 84 | mime.vcproj | 87 | mime.vcproj |
| 85 | 88 | ||
| 86 | MANUAL = \ | 89 | DOC = \ |
| 87 | manual/dns.html \ | 90 | doc/dns.html \ |
| 88 | manual/ftp.html \ | 91 | doc/ftp.html \ |
| 89 | manual/home.html \ | 92 | doc/home.html \ |
| 90 | manual/http.html \ | 93 | doc/http.html \ |
| 91 | manual/introduction.html \ | 94 | doc/installation.html \ |
| 92 | manual/ltn12.html \ | 95 | doc/introduction.html \ |
| 93 | manual/luasocket.png \ | 96 | doc/ltn12.html \ |
| 94 | manual/mime.html \ | 97 | doc/luasocket.png \ |
| 95 | manual/installation.html \ | 98 | doc/mime.html \ |
| 96 | manual/reference.css \ | 99 | doc/reference.css \ |
| 97 | manual/reference.html \ | 100 | doc/reference.html \ |
| 98 | manual/smtp.html \ | 101 | doc/smtp.html \ |
| 99 | manual/socket.html \ | 102 | doc/socket.html \ |
| 100 | manual/tcp.html \ | 103 | doc/tcp.html \ |
| 101 | manual/udp.html \ | 104 | doc/udp.html \ |
| 102 | manual/url.html | 105 | doc/url.html |
| 103 | 106 | ||
| 104 | dist: | 107 | dist: |
| 105 | mkdir -p $(DIST)/examples | 108 | mkdir -p $(DIST) |
| 106 | mkdir -p $(DIST)/tests | ||
| 107 | mkdir -p $(DIST)/etc | ||
| 108 | mkdir -p $(DIST)/lua | ||
| 109 | mkdir -p $(DIST)/manual | ||
| 110 | cp -vfr $(COMPAT) $(DIST) | ||
| 111 | cp -vf $(CORE) $(DIST) | ||
| 112 | cp -vf README $(DIST) | ||
| 113 | cp -vf NEW $(DIST) | 109 | cp -vf NEW $(DIST) |
| 114 | cp -vf LICENSE $(DIST) | 110 | cp -vf LICENSE $(DIST) |
| 115 | cp -vf $(MAKE) $(DIST) | 111 | cp -vf $(MAKE) $(DIST) |
| 116 | cp -vf make.README $(DIST)/INSTALL | 112 | |
| 117 | cp -vf $(LUA) $(DIST)/lua | 113 | mkdir -p $(DIST)/etc |
| 118 | cp -vf lua.README $(DIST)/lua/README | ||
| 119 | cp -vf $(EXAMPLES) $(DIST)/examples | ||
| 120 | cp -vf examples.README $(DIST)/examples/README | ||
| 121 | cp -vf $(TESTS) $(DIST)/tests | ||
| 122 | cp -vf tests.README $(DIST)/tests/README | ||
| 123 | cp -vf $(ETC) $(DIST)/etc | 114 | cp -vf $(ETC) $(DIST)/etc |
| 124 | cp -vf etc.README $(DIST)/etc/README | 115 | |
| 125 | cp -vf $(MANUAL) $(DIST)/manual | 116 | mkdir -p $(DIST)/src |
| 117 | cp -vf $(SRC) $(DIST)/src | ||
| 118 | cp -vfr $(COMPAT) $(DIST)/src | ||
| 119 | |||
| 120 | mkdir -p $(DIST)/doc | ||
| 121 | cp -vf $(DOC) $(DIST)/doc | ||
| 122 | |||
| 123 | mkdir -p $(DIST)/samples | ||
| 124 | cp -vf $(SAMPLES) $(DIST)/samples | ||
| 125 | |||
| 126 | mkdir -p $(DIST)/test | ||
| 127 | cp -vf $(TEST) $(DIST)/test | ||
| 128 | |||
| 126 | tar -zcvf $(DIST).tar.gz $(DIST) | 129 | tar -zcvf $(DIST).tar.gz $(DIST) |
| 127 | zip -r $(DIST).zip $(DIST) | 130 | zip -r $(DIST).zip $(DIST) |
| 128 | 131 | ||
diff --git a/samples/README b/samples/README index 0100a4a..e63a6f5 100644 --- a/samples/README +++ b/samples/README | |||
| @@ -1,59 +1,50 @@ | |||
| 1 | This directory contains some sample programs using LuaSocket. This code | 1 | This directory contains some sample programs using |
| 2 | is not supported. | 2 | LuaSocket. This code is not supported. |
| 3 | 3 | ||
| 4 | listener.lua -- socket to stdout | 4 | listener.lua -- socket to stdout |
| 5 | talker.lua -- stdin to socket | 5 | talker.lua -- stdin to socket |
| 6 | 6 | ||
| 7 | listener.lua and talker.lua are about the simplest applications you can | 7 | listener.lua and talker.lua are about the simplest |
| 8 | write using LuaSocket. Run | 8 | applications you can write using LuaSocket. Run |
| 9 | 9 | ||
| 10 | 'lua listener.lua' and 'lua talker.lua' | 10 | 'lua listener.lua' and 'lua talker.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 |
| 13 | printed by listen.lua. | 13 | be printed by listen.lua. |
| 14 | |||
| 15 | b64.lua | ||
| 16 | qp.lua | ||
| 17 | eol.lua | ||
| 18 | |||
| 19 | These are tiny programs that perform Base64, Quoted-Printable and | ||
| 20 | end-of-line marker conversions. | ||
| 21 | 14 | ||
| 22 | lpr.lua -- lpr client | 15 | lpr.lua -- lpr client |
| 23 | 16 | ||
| 24 | This is a cool program written by David Burgess to print files using the | 17 | This is a cool program written by David Burgess to print |
| 25 | Line Printer Daemon protocol, widely used in Unix machines. It uses the | 18 | files using the Line Printer Daemon protocol, widely used in |
| 26 | lp.lua implementation, in the etc directory. Just run | 19 | Unix machines. It uses the lp.lua implementation, in the |
| 27 | 'lua lpr.lua <filename> queue=<printername>' and the file will print! | 20 | etc directory. Just run 'lua lpr.lua <filename> |
| 21 | queue=<printername>' and the file will print! | ||
| 28 | 22 | ||
| 29 | cddb.lua -- CDDB client | 23 | cddb.lua -- CDDB client |
| 30 | 24 | ||
| 31 | This is the first try on a simple CDDB client. Not really useful, but one | 25 | This is the first try on a simple CDDB client. Not really |
| 32 | day it might become a module. | 26 | useful, but one day it might become a module. |
| 33 | 27 | ||
| 34 | daytimeclnt.lua -- day time client | 28 | daytimeclnt.lua -- day time client |
| 35 | 29 | ||
| 36 | 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 |
| 37 | any server running an UDP daytime daemon. | 31 | readable form from any server running an UDP daytime daemon. |
| 38 | 32 | ||
| 39 | echoclnt.lua -- UDP echo client | 33 | echoclnt.lua -- UDP echo client |
| 40 | echosrvr.lua -- UDP echo server | 34 | echosrvr.lua -- UDP echo server |
| 41 | 35 | ||
| 42 | These are a UDP echo client/server pair. They work with other client and | 36 | These are a UDP echo client/server pair. They work with |
| 43 | servers as well. | 37 | other client and servers as well. |
| 44 | 38 | ||
| 45 | tinyirc.lua -- irc like broadcast server | 39 | tinyirc.lua -- irc like broadcast server |
| 46 | 40 | ||
| 47 | This is a simple server that waits simultaneously on two server sockets | 41 | This is a simple server that waits simultaneously on two |
| 48 | for telnet connections. Everything it receives from the telnet clients | 42 | server sockets for telnet connections. Everything it |
| 49 | is broadcasted to every other connected client. It tests the select | 43 | receives from the telnet clients is broadcasted to every |
| 50 | function and shows how to create a simple server whith LuaSocket. Just | 44 | other connected client. It tests the select function and |
| 51 | run tinyirc.lua and then open as many telnet connections as you want | 45 | shows how to create a simple server whith LuaSocket. Just |
| 52 | to ports 8080 and 8081. | 46 | run tinyirc.lua and then open as many telnet connections |
| 53 | 47 | as you want to ports 8080 and 8081. | |
| 54 | check-memory.lua -- checks memory consumption | ||
| 55 | |||
| 56 | This is just to see how much memory each module uses. | ||
| 57 | 48 | ||
| 58 | Good luck, | 49 | Good luck, |
| 59 | Diego. | 50 | Diego. |
diff --git a/samples/forward.lua b/samples/forward.lua deleted file mode 100644 index 548a753..0000000 --- a/samples/forward.lua +++ /dev/null | |||
| @@ -1,207 +0,0 @@ | |||
| 1 | -- load our favourite library | ||
| 2 | local socket = require"socket" | ||
| 3 | |||
| 4 | -- creates a new set data structure | ||
| 5 | function newset() | ||
| 6 | local reverse = {} | ||
| 7 | local set = {} | ||
| 8 | return setmetatable(set, {__index = { | ||
| 9 | insert = function(set, value) | ||
| 10 | if not reverse[value] then | ||
| 11 | table.insert(set, value) | ||
| 12 | reverse[value] = table.getn(set) | ||
| 13 | end | ||
| 14 | end, | ||
| 15 | remove = function(set, value) | ||
| 16 | local index = reverse[value] | ||
| 17 | if index then | ||
| 18 | reverse[value] = nil | ||
| 19 | local top = table.remove(set) | ||
| 20 | if top ~= value then | ||
| 21 | reverse[top] = index | ||
| 22 | set[index] = top | ||
| 23 | end | ||
| 24 | end | ||
| 25 | end | ||
| 26 | }}) | ||
| 27 | end | ||
| 28 | |||
| 29 | -- timeout before an inactive thread is kicked | ||
| 30 | local TIMEOUT = 10 | ||
| 31 | -- set of connections waiting to receive data | ||
| 32 | local receiving = newset(1) | ||
| 33 | -- set of sockets waiting to send data | ||
| 34 | local sending = newset() | ||
| 35 | -- context for connections and servers | ||
| 36 | local context = {} | ||
| 37 | |||
| 38 | function wait(who, what) | ||
| 39 | if what == "input" then receiving:insert(who) | ||
| 40 | else sending:insert(who) end | ||
| 41 | context[who].last = socket.gettime() | ||
| 42 | coroutine.yield() | ||
| 43 | end | ||
| 44 | |||
| 45 | -- initializes the forward server | ||
| 46 | function init() | ||
| 47 | if table.getn(arg) < 1 then | ||
| 48 | print("Usage") | ||
| 49 | print(" lua forward.lua <iport:ohost:oport> ...") | ||
| 50 | os.exit(1) | ||
| 51 | end | ||
| 52 | -- for each tunnel, start a new server socket | ||
| 53 | for i, v in ipairs(arg) do | ||
| 54 | -- capture forwarding parameters | ||
| 55 | local iport, ohost, oport = | ||
| 56 | socket.skip(2, string.find(v, "([^:]+):([^:]+):([^:]+)")) | ||
| 57 | assert(iport, "invalid arguments") | ||
| 58 | -- create our server socket | ||
| 59 | local server = assert(socket.bind("*", iport)) | ||
| 60 | server:settimeout(0) -- we don't want to be killed by bad luck | ||
| 61 | -- make sure server is tested for readability | ||
| 62 | receiving:insert(server) | ||
| 63 | -- add server context | ||
| 64 | context[server] = { | ||
| 65 | thread = coroutine.create(accept), | ||
| 66 | ohost = ohost, | ||
| 67 | oport = oport | ||
| 68 | } | ||
| 69 | end | ||
| 70 | end | ||
| 71 | |||
| 72 | -- starts a connection in a non-blocking way | ||
| 73 | function connect(who, host, port) | ||
| 74 | who:settimeout(0) | ||
| 75 | local ret, err = who:connect(host, port) | ||
| 76 | if not ret and err == "timeout" then | ||
| 77 | wait(who, "output") | ||
| 78 | ret, err = who:connect(host, port) | ||
| 79 | if not ret and err ~= "already connected" then | ||
| 80 | kick(context[who].peer) | ||
| 81 | kick(who) | ||
| 82 | return | ||
| 83 | end | ||
| 84 | end | ||
| 85 | return forward(who) | ||
| 86 | end | ||
| 87 | |||
| 88 | -- gets rid of a client | ||
| 89 | function kick(who) | ||
| 90 | if who then | ||
| 91 | sending:remove(who) | ||
| 92 | receiving:remove(who) | ||
| 93 | who:close() | ||
| 94 | context[who] = nil | ||
| 95 | end | ||
| 96 | end | ||
| 97 | |||
| 98 | -- loops accepting connections and creating new threads to deal with them | ||
| 99 | function accept(server) | ||
| 100 | while true do | ||
| 101 | -- accept a new connection and start a new coroutine to deal with it | ||
| 102 | local client = server:accept() | ||
| 103 | if client then | ||
| 104 | -- create contexts for client and peer. | ||
| 105 | local peer, err = socket.tcp() | ||
| 106 | if peer then | ||
| 107 | context[client] = { | ||
| 108 | last = socket.gettime(), | ||
| 109 | -- client goes straight to forwarding loop | ||
| 110 | thread = coroutine.create(forward), | ||
| 111 | peer = peer, | ||
| 112 | } | ||
| 113 | context[peer] = { | ||
| 114 | last = socket.gettime(), | ||
| 115 | peer = client, | ||
| 116 | -- peer first tries to connect to forwarding address | ||
| 117 | thread = coroutine.create(connect), | ||
| 118 | last = socket.gettime() | ||
| 119 | } | ||
| 120 | -- resume peer and client so they can do their thing | ||
| 121 | local ohost = context[server].ohost | ||
| 122 | local oport = context[server].oport | ||
| 123 | coroutine.resume(context[peer].thread, peer, ohost, oport) | ||
| 124 | coroutine.resume(context[client].thread, client) | ||
| 125 | else | ||
| 126 | print(err) | ||
| 127 | client:close() | ||
| 128 | end | ||
| 129 | end | ||
| 130 | -- tell scheduler we are done for now | ||
| 131 | wait(server, "input") | ||
| 132 | end | ||
| 133 | end | ||
| 134 | |||
| 135 | -- forwards all data arriving to the appropriate peer | ||
| 136 | function forward(who) | ||
| 137 | who:settimeout(0) | ||
| 138 | while true do | ||
| 139 | -- wait until we have something to read | ||
| 140 | wait(who, "input") | ||
| 141 | -- try to read as much as possible | ||
| 142 | local data, rec_err, partial = who:receive("*a") | ||
| 143 | -- if we had an error other than timeout, abort | ||
| 144 | if rec_err and rec_err ~= "timeout" then return kick(who) end | ||
| 145 | -- if we got a timeout, we probably have partial results to send | ||
| 146 | data = data or partial | ||
| 147 | -- forward what we got right away | ||
| 148 | local peer = context[who].peer | ||
| 149 | while true do | ||
| 150 | -- tell scheduler we need to wait until we can send something | ||
| 151 | wait(who, "output") | ||
| 152 | local ret, snd_err | ||
| 153 | local start = 0 | ||
| 154 | ret, snd_err, start = peer:send(data, start+1) | ||
| 155 | if ret then break | ||
| 156 | elseif snd_err ~= "timeout" then return kick(who) end | ||
| 157 | end | ||
| 158 | -- if we are done receiving, we are done | ||
| 159 | if not rec_err then | ||
| 160 | kick(who) | ||
| 161 | kick(peer) | ||
| 162 | break | ||
| 163 | end | ||
| 164 | end | ||
| 165 | end | ||
| 166 | |||
| 167 | -- loop waiting until something happens, restarting the thread to deal with | ||
| 168 | -- what happened, and routing it to wait until something else happens | ||
| 169 | function go() | ||
| 170 | while true do | ||
| 171 | -- check which sockets are interesting and act on them | ||
| 172 | readable, writable = socket.select(receiving, sending) | ||
| 173 | -- for all readable connections, resume its thread | ||
| 174 | for _, who in ipairs(readable) do | ||
| 175 | if context[who] then | ||
| 176 | receiving:remove(who) | ||
| 177 | coroutine.resume(context[who].thread, who) | ||
| 178 | end | ||
| 179 | end | ||
| 180 | -- for all writable connections, do the same | ||
| 181 | for _, who in ipairs(writable) do | ||
| 182 | if context[who] then | ||
| 183 | sending:remove(who) | ||
| 184 | coroutine.resume(context[who].thread, who) | ||
| 185 | end | ||
| 186 | end | ||
| 187 | -- put all inactive threads in death row | ||
| 188 | local now = socket.gettime() | ||
| 189 | local deathrow | ||
| 190 | for who, data in pairs(context) do | ||
| 191 | if data.peer then | ||
| 192 | if now - data.last > TIMEOUT then | ||
| 193 | -- only create table if at least one is doomed | ||
| 194 | deathrow = deathrow or {} | ||
| 195 | deathrow[who] = true | ||
| 196 | end | ||
| 197 | end | ||
| 198 | end | ||
| 199 | -- finally kick everyone in deathrow | ||
| 200 | if deathrow then | ||
| 201 | for who in pairs(deathrow) do kick(who) end | ||
| 202 | end | ||
| 203 | end | ||
| 204 | end | ||
| 205 | |||
| 206 | init() | ||
| 207 | go() | ||
diff --git a/samples/lpr.lua b/samples/lpr.lua index caab387..5ab4d69 100644 --- a/samples/lpr.lua +++ b/samples/lpr.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | local lp = require("socket.lp") | 1 | local lp = require("socket.lp") |
| 2 | 2 | ||
| 3 | local function usage() | 3 | local function usage() |
| 4 | print('\nUsage: lua lptest.lua [filename] [keyword=val...]\n') | 4 | print('\nUsage: lua lpr.lua [filename] [keyword=val...]\n') |
| 5 | print('Valid keywords are :') | 5 | print('Valid keywords are :') |
| 6 | print( | 6 | print( |
| 7 | ' host=remote host or IP address (default "localhost")\n' .. | 7 | ' host=remote host or IP address (default "localhost")\n' .. |
diff --git a/test/httptest.lua b/test/httptest.lua index 0951389..c05b4cc 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
| @@ -22,8 +22,8 @@ http.TIMEOUT = 10 | |||
| 22 | 22 | ||
| 23 | local t = socket.gettime() | 23 | local t = socket.gettime() |
| 24 | 24 | ||
| 25 | host = host or "dell-diego" -- "diego.student.princeton.edu" | 25 | host = host or "diego.student.princeton.edu" |
| 26 | proxy = proxy or "http://dell-diego:3128" | 26 | proxy = proxy or "http://localhost:3128" |
| 27 | prefix = prefix or "/luasocket-test" | 27 | prefix = prefix or "/luasocket-test" |
| 28 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | 28 | cgiprefix = cgiprefix or "/luasocket-test-cgi" |
| 29 | index_file = "index.html" | 29 | index_file = "index.html" |
