diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-05-26 04:58:32 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-05-26 04:58:32 +0000 |
commit | bf738a03368b8de9c574d9631f131c5a520acf7b (patch) | |
tree | a65c512ce4601b056417ff7154ebdc254d762054 | |
parent | 4b7c2db4b7109bf57abd1b76abf24eba27f51aa1 (diff) | |
download | luasocket-bf738a03368b8de9c574d9631f131c5a520acf7b.tar.gz luasocket-bf738a03368b8de9c574d9631f131c5a520acf7b.tar.bz2 luasocket-bf738a03368b8de9c574d9631f131c5a520acf7b.zip |
Working with in the manual.
-rw-r--r-- | TODO | 38 | ||||
-rw-r--r-- | doc/reference.html | 57 | ||||
-rw-r--r-- | doc/socket.html | 117 | ||||
-rw-r--r-- | src/ftp.lua | 2 | ||||
-rw-r--r-- | src/smtp.lua | 6 | ||||
-rw-r--r-- | src/tp.lua | 10 | ||||
-rw-r--r-- | test/testmesg.lua | 3 |
7 files changed, 171 insertions, 62 deletions
@@ -19,38 +19,40 @@ | |||
19 | * Separar as classes em arquivos | 19 | * Separar as classes em arquivos |
20 | * Retorno de sendto em datagram sockets pode ser refused | 20 | * Retorno de sendto em datagram sockets pode ser refused |
21 | * select sets are now associative | 21 | * select sets are now associative |
22 | 22 | * colocar pump.all, pump.step | |
23 | colocar pump.all, pump.step e pump.simplify. | 23 | * mudar ltn12.html e usar o exemplo source.cat que está muito melhor. |
24 | mudar ltn12.html e usar o exemplo source.cat que está muito melhor. | 24 | * break smtp.send into c = smtp.open, c:send() c:close() |
25 | 25 | * fazer com que a socket.source e socket.sink sejam "selectable". | |
26 | break smtp.send into c = smtp.open, c:send() c:close() | 26 | * change mime.eol to output marker on detection of first candidate, instead |
27 | of on the second. that way it works in one pass for strings that end with | ||
28 | one candidate. | ||
29 | * unify backbone of smtp and ftp | ||
30 | * unify filter and send/receive callback. new sink/source/pump idea. | ||
31 | * get rid of aux_optlstring | ||
32 | * get rid of unpack in mime.lua | ||
33 | * create socket.(sink|source).simplify | ||
34 | * break chain into a simpler binary chain and a complex (recursive) one. | ||
35 | * Create a passive mode option for the FTP (good for firewall). | ||
36 | * Modules should return their namespace table in the end of the chunk. | ||
37 | |||
38 | ajeitar o manual sobre select, mais liberal agora | ||
39 | conjunto associativo | ||
27 | 40 | ||
28 | falar sobre encodet/wrapt/decodet no manual sobre mime | 41 | falar sobre encodet/wrapt/decodet no manual sobre mime |
29 | 42 | ||
30 | 43 | ||
31 | RECEIVE MUDOU!!! (partial stuff) COLOCAR NO MANUAL. | 44 | RECEIVE MUDOU!!! (partial stuff) COLOCAR NO MANUAL. |
32 | HTTP.lua mudou bastante também. | 45 | HTTP.lua mudou bastante também. |
33 | 46 | pump.step usado em todo mundo que recebe source ou sink | |
34 | fazer com que a socket.source e socket.sink sejam "selectable". | ||
35 | |||
36 | change mime.eol to output marker on detection of first candidate, instead | ||
37 | of on the second. that way it works in one pass for strings that end with | ||
38 | one candidate. | ||
39 | 47 | ||
40 | colocar um userdata com gc metamethod pra chamar sock_close (WSAClose); | 48 | colocar um userdata com gc metamethod pra chamar sock_close (WSAClose); |
41 | sources ans sinks are always simple in http and ftp and smtp | 49 | sources ans sinks are always simple in http and ftp and smtp |
42 | unify backbone of smtp and ftp | ||
43 | expose encode/decode tables to provide extensibility for mime module | 50 | expose encode/decode tables to provide extensibility for mime module |
44 | use coroutines instead of fancy filters | 51 | use coroutines instead of fancy filters |
45 | unify filter and send/receive callback. new sink/source/pump idea. | ||
46 | get rid of aux_optlstring | ||
47 | wrap sink and sources with a function that performs the replacement | ||
48 | get rid of unpack in mime.lua | ||
49 | 52 | ||
50 | check garbage collection in test*.lua | 53 | check garbage collection in test*.lua |
51 | pop3??? | 54 | pop3??? |
52 | 55 | ||
53 | break chain into a simpler binary chain and a complex (recursive) one. | ||
54 | 56 | ||
55 | add socket.TIMEOUT to be default timeout? | 57 | add socket.TIMEOUT to be default timeout? |
56 | 58 | ||
@@ -123,9 +125,7 @@ to do with it. | |||
123 | 125 | ||
124 | Make sure nobody can fuck up with the metatables... | 126 | Make sure nobody can fuck up with the metatables... |
125 | 127 | ||
126 | Create a passive mode option for the FTP (good for firewall). | ||
127 | 128 | ||
128 | Modules should return their namespace table in the end of the chunk. | ||
129 | 129 | ||
130 | Adjust dates in all files | 130 | Adjust dates in all files |
131 | 131 | ||
diff --git a/doc/reference.html b/doc/reference.html index 6372e64..ba519c0 100644 --- a/doc/reference.html +++ b/doc/reference.html | |||
@@ -55,10 +55,10 @@ | |||
55 | </blockquote> | 55 | </blockquote> |
56 | </blockquote> | 56 | </blockquote> |
57 | 57 | ||
58 | <!-- misc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 58 | <!-- global +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
59 | 59 | ||
60 | <blockquote> | 60 | <blockquote> |
61 | <a href="global.html">Globals</a> | 61 | <a href="global.html">Global symbols</a> |
62 | <blockquote> | 62 | <blockquote> |
63 | <a href="global.html#LUASOCKET_LIBNAME">LUASOCKET_LIBNAME</a>, | 63 | <a href="global.html#LUASOCKET_LIBNAME">LUASOCKET_LIBNAME</a>, |
64 | <a href="global.html#mime">mime</a>, | 64 | <a href="global.html#mime">mime</a>, |
@@ -68,32 +68,6 @@ | |||
68 | </blockquote> | 68 | </blockquote> |
69 | </table> | 69 | </table> |
70 | 70 | ||
71 | <blockquote> | ||
72 | <a href="socket.html">LuaSocket namespace (socket)</a> | ||
73 | <blockquote> | ||
74 | <a href="socket.html#bind">bind</a>, | ||
75 | <a href="socket.html#connect">connect</a>, | ||
76 | <a href="socket.html#debug">debug</a>, | ||
77 | <a href="socket.html#dns">dns</a>, | ||
78 | <a href="socket.html#ftp">ftp</a>, | ||
79 | <a href="socket.html#http">http</a>, | ||
80 | <a href="socket.html#protect">protect</a>, | ||
81 | <a href="socket.html#select">select</a>, | ||
82 | <a href="socket.html#sink">sink</a>, | ||
83 | <a href="socket.html#source">source</a>, | ||
84 | <a href="socket.html#sleep">sleep</a>, | ||
85 | <a href="socket.html#smtp">smtp</a>, | ||
86 | <a href="socket.html#time">time</a>, | ||
87 | <a href="socket.html#tcp">tcp</a>, | ||
88 | <a href="socket.html#try">try</a>, | ||
89 | <a href="socket.html#udp">udp</a>, | ||
90 | <a href="socket.html#url">url</a>, | ||
91 | <a href="socket.html#version">version</a>. | ||
92 | </blockquote> | ||
93 | </blockquote> | ||
94 | </table> | ||
95 | |||
96 | |||
97 | <!-- http +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 71 | <!-- http +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
98 | 72 | ||
99 | <blockquote> | 73 | <blockquote> |
@@ -175,6 +149,33 @@ | |||
175 | </blockquote> | 149 | </blockquote> |
176 | </blockquote> | 150 | </blockquote> |
177 | 151 | ||
152 | <!-- socket +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
153 | |||
154 | <blockquote> | ||
155 | <a href="socket.html">The socket namespace (socket)</a> | ||
156 | <blockquote> | ||
157 | <a href="tcp.html#bind">bind</a>, | ||
158 | <a href="tcp.html#connect">connect</a>, | ||
159 | <a href="socket.html#debug">debug</a>, | ||
160 | <a href="dns.html#dns">dns</a>, | ||
161 | <a href="ftp.html#ftp">ftp</a>, | ||
162 | <a href="http.html#http">http</a>, | ||
163 | <a href="socket.html#protect">protect</a>, | ||
164 | <a href="socket.html#select">select</a>, | ||
165 | <a href="socket.html#sink">sink</a>, | ||
166 | <a href="socket.html#source">source</a>, | ||
167 | <a href="socket.html#sleep">sleep</a>, | ||
168 | <a href="smtp.html#smtp">smtp</a>, | ||
169 | <a href="socket.html#time">time</a>, | ||
170 | <a href="tcp.html#tcp">tcp</a>, | ||
171 | <a href="socket.html#try">try</a>, | ||
172 | <a href="udp.html#udp">udp</a>, | ||
173 | <a href="url.html#url">url</a>, | ||
174 | <a href="socket.html#version">version</a>. | ||
175 | </blockquote> | ||
176 | </blockquote> | ||
177 | </table> | ||
178 | |||
178 | <!-- tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 179 | <!-- tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
179 | 180 | ||
180 | <blockquote> | 181 | <blockquote> |
diff --git a/doc/socket.html b/doc/socket.html index 9372648..bde882b 100644 --- a/doc/socket.html +++ b/doc/socket.html | |||
@@ -33,7 +33,7 @@ | |||
33 | 33 | ||
34 | <!-- socket +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 34 | <!-- socket +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
35 | 35 | ||
36 | <h2 id=socket>The LuaSocket namespace</h2> | 36 | <h2 id=socket>The socket namespace</h2> |
37 | 37 | ||
38 | <p> | 38 | <p> |
39 | The <tt>socket</tt> namespace contains the namespace tables for all | 39 | The <tt>socket</tt> namespace contains the namespace tables for all |
@@ -74,7 +74,120 @@ The function an equivalent function that instead of throwing exceptoins, | |||
74 | returns <tt><b>nil</b></tt> followed by an error message. | 74 | returns <tt><b>nil</b></tt> followed by an error message. |
75 | </p> | 75 | </p> |
76 | 76 | ||
77 | <!-- toip +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 77 | <!-- select +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
78 | |||
79 | <p class=name id=select> | ||
80 | socket.<b>select(</b>recvt, sendt [, timeout]<b>)</b> | ||
81 | </p> | ||
82 | |||
83 | <p class=description> | ||
84 | Waits for a number of sockets to change status. | ||
85 | </p> | ||
86 | |||
87 | <p class=parameters> | ||
88 | <tt>Recvt</tt> is an array with the sockets to test for characters | ||
89 | available for reading. Sockets in the <tt>sendt</tt> array are watched to | ||
90 | see if it is OK to immediately write on them. <tt>Timeout</tt> is the | ||
91 | maximum amount of time (in seconds) to wait for a change in status. A | ||
92 | <tt><b>nil</b></tt>, negative or omitted <tt>timeout</tt> value allows the | ||
93 | function to block indefinitely. <tt>Recvt</tt> and <tt>sendt</tt> can also | ||
94 | be empty tables or <tt><b>nil</b></tt>. Non-socket values in the arrays | ||
95 | will be silently ignored. | ||
96 | </p> | ||
97 | |||
98 | <p class=return> The function returns a table with the sockets ready for | ||
99 | reading, a table with the sockets ready for writing and an error message. | ||
100 | The error message is "<tt>timeout</tt>" if a timeout condition was met and | ||
101 | <tt><b>nil</b></tt> otherwise. The returned tables are associative, to | ||
102 | simplify the test if a specific socket has changed status. | ||
103 | </p> | ||
104 | |||
105 | <p class=note> | ||
106 | <b>Important Note</b>: a known bug in WinSock causes <tt>select</tt> to fail | ||
107 | on non-blocking TCP sockets. The function may return a socket as | ||
108 | writable even though the socket is <em>not</em> ready for sending. | ||
109 | </p> | ||
110 | |||
111 | <p class=note> | ||
112 | <b>Important note</b>: calling select with a server socket in the receive | ||
113 | parameter before a call to accept does <em>not</em> guarantee | ||
114 | <a href=tcp.html#accept><tt>accept</tt></a> will return immediately. | ||
115 | Use the <a href=tcp.html#timeout><tt>timeout</tt></a> | ||
116 | method or <tt>accept</tt> might block forever. | ||
117 | </p> | ||
118 | |||
119 | <p class=note> | ||
120 | Interesting note: as mentioned in some manuals, calling select with both | ||
121 | sets empty and a non-null timeout is a fairly portable way to sleep with | ||
122 | sub-second precision. | ||
123 | </p> | ||
124 | |||
125 | |||
126 | <!-- sink ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
127 | |||
128 | <p class=name id=sink> | ||
129 | socket.<b>sink(</b>mode, socket<b>)</b> | ||
130 | </p> | ||
131 | |||
132 | <p class=description> | ||
133 | Creates an | ||
134 | <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN012</a> | ||
135 | sink from a stream socket object. | ||
136 | </p> | ||
137 | |||
138 | <p class=parameters> | ||
139 | <tt>Mode</tt> defines the behaviour of the sink. The following | ||
140 | options are available: | ||
141 | </p> | ||
142 | <ul> | ||
143 | <li> <tt>"http-chunked"</tt>: sends data through socket after applying the | ||
144 | <em>chunked transfer coding</em>, closing the socket when done; | ||
145 | <li> <tt>"close-when-done"</tt>: sends all received data through the | ||
146 | socket, closing the socket when done; | ||
147 | <li> <tt>"keep-open"</tt>: sends all received data through the | ||
148 | socket, leaving it open when done. | ||
149 | </ul> | ||
150 | <p> | ||
151 | <tt>Socket</tt> is the stream socket object used to send the data. | ||
152 | </p> | ||
153 | |||
154 | <p class=return> | ||
155 | The function returns a sink with the appropriate behavior. | ||
156 | </p> | ||
157 | |||
158 | <!-- source +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
159 | |||
160 | <p class=name id=source> | ||
161 | socket.<b>source(</b>mode, socket [, length]<b>)</b> | ||
162 | </p> | ||
163 | |||
164 | <p class=description> | ||
165 | Creates an | ||
166 | <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN012</a> | ||
167 | source from a stream socket object. | ||
168 | </p> | ||
169 | |||
170 | <p class=parameters> | ||
171 | <tt>Mode</tt> defines the behaviour of the source. The following | ||
172 | options are available: | ||
173 | </p> | ||
174 | <ul> | ||
175 | <li> <tt>"http-chunked"</tt>: receives data from socket and removes the | ||
176 | <em>chunked transfer coding</em> before returning the data; | ||
177 | <li> <tt>"by-length"</tt>: receives a fixed number of bytes from the | ||
178 | socket. This mode requires the extra argument <tt>length</tt>; | ||
179 | <li> <tt>"until-closed"</tt>: receives data from a socket until the other | ||
180 | side closes the connection. | ||
181 | </ul> | ||
182 | <p> | ||
183 | <tt>Socket</tt> is the stream socket object used to receive the data. | ||
184 | </p> | ||
185 | |||
186 | <p class=return> | ||
187 | The function returns a source with the appropriate behavior. | ||
188 | </p> | ||
189 | |||
190 | <!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
78 | 191 | ||
79 | <p class=name id=try> | 192 | <p class=name id=try> |
80 | socket.<b>try(</b>ret<sub>1</sub>, ret<sub>2</sub> ... ret<sub>N</sub><b>)</b> | 193 | socket.<b>try(</b>ret<sub>1</sub>, ret<sub>2</sub> ... ret<sub>N</sub><b>)</b> |
diff --git a/src/ftp.lua b/src/ftp.lua index ee1f9aa..306b77f 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
@@ -114,7 +114,7 @@ function metat.__index:send(sendt) | |||
114 | if err then data:close() end | 114 | if err then data:close() end |
115 | return ret, err | 115 | return ret, err |
116 | end | 116 | end |
117 | local sink = socket.sink("close-when-empty", data) | 117 | local sink = socket.sink("close-when-done", data) |
118 | socket.try(ltn12.pump.all(sendt.source, sink, checkstep)) | 118 | socket.try(ltn12.pump.all(sendt.source, sink, checkstep)) |
119 | if string.find(code, "1..") then socket.try(self.tp:check("2..")) end | 119 | if string.find(code, "1..") then socket.try(self.tp:check("2..")) end |
120 | return 1 | 120 | return 1 |
diff --git a/src/smtp.lua b/src/smtp.lua index 6ddeaae..8e672a0 100644 --- a/src/smtp.lua +++ b/src/smtp.lua | |||
@@ -51,10 +51,10 @@ function metat.__index:rcpt(to) | |||
51 | return socket.try(self.tp:check("2..")) | 51 | return socket.try(self.tp:check("2..")) |
52 | end | 52 | end |
53 | 53 | ||
54 | function metat.__index:data(src) | 54 | function metat.__index:data(src, step) |
55 | socket.try(self.tp:command("DATA")) | 55 | socket.try(self.tp:command("DATA")) |
56 | socket.try(self.tp:check("3..")) | 56 | socket.try(self.tp:check("3..")) |
57 | socket.try(self.tp:source(src)) | 57 | socket.try(self.tp:source(src, step)) |
58 | socket.try(self.tp:send("\r\n.\r\n")) | 58 | socket.try(self.tp:send("\r\n.\r\n")) |
59 | return socket.try(self.tp:check("2..")) | 59 | return socket.try(self.tp:check("2..")) |
60 | end | 60 | end |
@@ -78,7 +78,7 @@ function metat.__index:send(mailt) | |||
78 | else | 78 | else |
79 | self:rcpt(mailt.rcpt) | 79 | self:rcpt(mailt.rcpt) |
80 | end | 80 | end |
81 | self:data(ltn12.source.chain(mailt.source, stuff())) | 81 | self:data(ltn12.source.chain(mailt.source, stuff()), mailt.step) |
82 | end | 82 | end |
83 | 83 | ||
84 | function open(server, port) | 84 | function open(server, port) |
@@ -87,13 +87,9 @@ function metat.__index:getcontrol() | |||
87 | return self.control | 87 | return self.control |
88 | end | 88 | end |
89 | 89 | ||
90 | function metat.__index:source(src, instr) | 90 | function metat.__index:source(source, step) |
91 | while true do | 91 | local sink = socket.sink("keep-open", self.control) |
92 | local chunk, err = src() | 92 | return ltn12.pump.all(source, sink, step or ltn12.pump.step) |
93 | if not chunk then return not err, err end | ||
94 | local ret, err = self.control:send(chunk) | ||
95 | if not ret then return nil, err end | ||
96 | end | ||
97 | end | 93 | end |
98 | 94 | ||
99 | -- closes the underlying control | 95 | -- closes the underlying control |
diff --git a/test/testmesg.lua b/test/testmesg.lua index 796977e..8b33133 100644 --- a/test/testmesg.lua +++ b/test/testmesg.lua | |||
@@ -49,6 +49,5 @@ print(socket.smtp.send { | |||
49 | rcpt = "<diego@cs.princeton.edu>", | 49 | rcpt = "<diego@cs.princeton.edu>", |
50 | from = "<diego@cs.princeton.edu>", | 50 | from = "<diego@cs.princeton.edu>", |
51 | source = socket.smtp.message(mesgt), | 51 | source = socket.smtp.message(mesgt), |
52 | server = "mail.iis.com.br", | 52 | server = "mail.cs.princeton.edu" |
53 | port = 7 | ||
54 | }) | 53 | }) |