diff options
-rw-r--r-- | doc/callback.html | 348 | ||||
-rw-r--r-- | doc/code.html | 202 | ||||
-rw-r--r-- | doc/dns.html | 2 | ||||
-rw-r--r-- | doc/reference.html | 118 | ||||
-rw-r--r-- | doc/stream.html | 166 |
5 files changed, 71 insertions, 765 deletions
diff --git a/doc/callback.html b/doc/callback.html deleted file mode 100644 index 98b4476..0000000 --- a/doc/callback.html +++ /dev/null | |||
@@ -1,348 +0,0 @@ | |||
1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
3 | <html> | ||
4 | |||
5 | <head> | ||
6 | <title>LuaSocket: Network support for the Lua language</title> | ||
7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
8 | </head> | ||
9 | |||
10 | <body> | ||
11 | |||
12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
13 | |||
14 | <div class=header> | ||
15 | <hr> | ||
16 | <center> | ||
17 | <table summary="LuaSocket logo"> | ||
18 | <tr><td align=center><a href="http://www.lua.org"> | ||
19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
20 | </a></td></tr> | ||
21 | <tr><td align=center valign=top>Network support for the Lua language | ||
22 | </td></tr> | ||
23 | </table> | ||
24 | <p class=bar> | ||
25 | <a href="home.html">home</a> · | ||
26 | <a href="home.html#download">download</a> · | ||
27 | <a href="introduction.html">introduction</a> · | ||
28 | <a href="reference.html">reference</a> | ||
29 | </p> | ||
30 | </center> | ||
31 | <hr> | ||
32 | </div> | ||
33 | |||
34 | <!-- stream ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
35 | |||
36 | <h2 id=stream>Callbacks</h2> | ||
37 | |||
38 | <p> | ||
39 | HTTP, FTP, and SMTP transfers sometimes involve large amounts of | ||
40 | information. Sometimes an application needs to generate outgoing data | ||
41 | in real time, or needs to process incoming information as it is being | ||
42 | received. To address these problems, LuaSocket allows HTTP and SMTP message | ||
43 | bodies and FTP file contents to be streamed through the | ||
44 | callback mechanism outlined below. | ||
45 | </p> | ||
46 | |||
47 | <p> | ||
48 | Instead of returning the received contents | ||
49 | as a big to the Lua application, the library allows the user to | ||
50 | provide a <em>receive callback</em> that will be called with successive | ||
51 | chunks of data, as the data becomes available. Conversely, the <em>send | ||
52 | callback</em> mechanism can be used when the application wants to incrementally provide LuaSocket with the data to be sent. | ||
53 | </p> | ||
54 | |||
55 | <!-- receive +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
56 | |||
57 | <p class=name id=receive> | ||
58 | <b>receive_cb(</b>chunk, err<b>)</b> | ||
59 | </p> | ||
60 | |||
61 | <p class=description> | ||
62 | A receive callback will be repeatedly called by | ||
63 | LuaSocket whenever new data is available. Each time it is called, the | ||
64 | callback receives successive chunks of downloaded data. | ||
65 | </p> | ||
66 | |||
67 | <p class=parameters> | ||
68 | <tt>Chunk</tt> contains the latest downloaded chunk of data. | ||
69 | When the transmission is over, the function is called with an | ||
70 | empty string (i.e. <tt>""</tt>) in <tt>chunk</tt>. | ||
71 | If an error occurs, the function receives a <b><tt>nil</tt></b> | ||
72 | <tt>chunk</tt> and an error message in <tt>err</tt>. | ||
73 | </p> | ||
74 | |||
75 | <p class=return> | ||
76 | The callback can abort transmission by returning <b><tt>nil</tt></b> as its first | ||
77 | return value, and an optional error message as the | ||
78 | second return value. To continue receiving | ||
79 | data, the function should return non-<b><tt>nil</tt></b> as its first return | ||
80 | value. Optionally, in this case, it may return a | ||
81 | second return value, with a new callback function to take its place. | ||
82 | </p> | ||
83 | |||
84 | <!-- send_cb ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
85 | |||
86 | <p class=name id=send> | ||
87 | <b>send_cb()</b> | ||
88 | </p> | ||
89 | |||
90 | <p class=description> | ||
91 | A send callback will be called whenever LuaSocket | ||
92 | needs more data to be sent. | ||
93 | </p> | ||
94 | |||
95 | <p class=return> | ||
96 | Each time the callback is called, it should return the next chunk of data. It | ||
97 | can optionally return, as it's second return value, a new callback to replace | ||
98 | itself. The callback can abort the process at any time by returning | ||
99 | <b><tt>nil</tt></b> followed by an optional error message. | ||
100 | </p> | ||
101 | |||
102 | <!-- predefined +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
103 | |||
104 | <h2 id=predefined>Predefined Callbacks</h2> | ||
105 | |||
106 | <p> | ||
107 | The Callback module provides several predefined callbacks to | ||
108 | perform the most common input/output operations. Callbacks are provided | ||
109 | that send and receive contents of files and strings. Furthermore, | ||
110 | composition functions are provided to chain callbacks with filters, such as | ||
111 | the filters defined in the <a href=mime.html>MIME</a> module. | ||
112 | Together, these two modules provide a powerful interface to send and | ||
113 | receive information. | ||
114 | </p> | ||
115 | |||
116 | <!-- done +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
117 | |||
118 | <p class=name id=done> | ||
119 | socket.callback.<b>done()</b> | ||
120 | </p> | ||
121 | |||
122 | <p class=description> | ||
123 | This function creates and returns a callback that successfully terminates | ||
124 | the transmission. | ||
125 | </p> | ||
126 | |||
127 | <!-- fail +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
128 | |||
129 | <p class=name id=fail> | ||
130 | socket.callback.<b>fail(</b>message<b>)</b> | ||
131 | </p> | ||
132 | |||
133 | <p class=description> | ||
134 | This function creates and returns a callback that aborts the | ||
135 | transmission with a given error <tt>message</tt>. | ||
136 | </p> | ||
137 | |||
138 | <!-- receive.concat +++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
139 | |||
140 | <p class=name id=receive.concat> | ||
141 | socket.callback.<b>receive.concat(</b>cat<b>)</b> | ||
142 | </p> | ||
143 | |||
144 | <p class=description> | ||
145 | This function creates a receive callback that stores whatever it receives | ||
146 | into a concat object. When done, the application can get the contents | ||
147 | received as a single string, directly from the concat object. | ||
148 | </p> | ||
149 | |||
150 | <p class=parameters> | ||
151 | <tt>Cat</tt> is the target concat object, or <b><tt>nil</tt></b>. | ||
152 | If <tt>cat</tt> is <b><tt>nil</tt></b>, the function creates its own | ||
153 | concat object. | ||
154 | </p> | ||
155 | |||
156 | <p class=return> | ||
157 | The function returns a receive callback for the file, and the concat object | ||
158 | that will be used to store the received contents. | ||
159 | </p> | ||
160 | |||
161 | <!-- receive.file +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
162 | |||
163 | <p class=name id=receive.file> | ||
164 | socket.callback.<b>receive.file(</b>file, io_err<b>)</b> | ||
165 | </p> | ||
166 | |||
167 | <p class=description> | ||
168 | This function creates a receive callback that stores whatever it receives | ||
169 | into a file. When done, the callback closes the file. | ||
170 | </p> | ||
171 | |||
172 | <p class=parameters> | ||
173 | <tt>File</tt> is a file handle opened for writing. If <tt>file</tt> is | ||
174 | <b><tt>nil</tt></b>, <tt>io_err</tt> can contain an error message. In this | ||
175 | case, the function returns a callback that just aborts | ||
176 | transmission with the error message. | ||
177 | </p> | ||
178 | |||
179 | <p class=return> | ||
180 | The function returns a receive callback for the file. | ||
181 | </p> | ||
182 | |||
183 | <p class=note> | ||
184 | Note: This function is designed so that it directly accepts the return | ||
185 | values of Lua's IO <tt>io.open</tt> library function. | ||
186 | </p> | ||
187 | |||
188 | <!-- receive.chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
189 | |||
190 | <p class=name id=receive.chain> | ||
191 | socket.callback.<b>receive.chain(</b>filter, receive_cb<b>)</b> | ||
192 | </p> | ||
193 | |||
194 | <p class=description> | ||
195 | This function creates a receive callback that passes all received data | ||
196 | through a filter, before handing it to a given receive callback. | ||
197 | </p> | ||
198 | |||
199 | <p class=parameters> | ||
200 | <tt>Cat</tt> is the target concat object, or <b><tt>nil</tt></b>. | ||
201 | If <tt>cat</tt> is <b><tt>nil</tt></b>, the function creates its own | ||
202 | concat object. | ||
203 | </p> | ||
204 | |||
205 | <p class=return> | ||
206 | The function returns a receive callback for the file, and the concat object | ||
207 | that will be used to store the received contents. | ||
208 | </p> | ||
209 | |||
210 | <p class=note> | ||
211 | Note: Several filters are defined in the <a href=mime.html>MIME</a> | ||
212 | module. Below is an example that creates a receive callback that | ||
213 | creates a string from the received contents, after decoding the | ||
214 | Quoted-Printable transfer content encoding. | ||
215 | </p> | ||
216 | |||
217 | <pre class=example> | ||
218 | string_cb, concat = socket.callback.receive.concat() | ||
219 | receive_cb = socket.callback.receive.chain( | ||
220 | socket.mime.decode("quoted-printable"), | ||
221 | string_cb | ||
222 | ) | ||
223 | </pre> | ||
224 | |||
225 | <p class=note> | ||
226 | The call to <tt>callback.chain</tt> creates a chained | ||
227 | receive callback that decodes data using the | ||
228 | <tt><a href=mime.html#decode>mime.decode</a></tt> | ||
229 | Quoted-Printable MIME filter and | ||
230 | hands the decoded data to a concat receive callback. | ||
231 | The concatenated decoded data can be retrieved later | ||
232 | from the associated concat object. | ||
233 | </p> | ||
234 | |||
235 | <!-- send.file ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
236 | |||
237 | <p class=name id=send.file> | ||
238 | socket.callback.<b>send.file(</b>file, io_err<b>)</b> | ||
239 | </p> | ||
240 | |||
241 | <p class=description> | ||
242 | This function creates a send callback that returns the contents | ||
243 | of a file, chunk by chunk, until the file has been entirely sent. | ||
244 | When done, the callback closes the file. | ||
245 | </p> | ||
246 | |||
247 | <p class=parameters> | ||
248 | <tt>File</tt> is a file handle opened for reading. If <tt>file</tt> is | ||
249 | <b><tt>nil</tt></b>, <tt>io_err</tt> can contain an error message. In this | ||
250 | case, the function returns a callback that just aborts | ||
251 | transmission with the error message. | ||
252 | </p> | ||
253 | |||
254 | <p class=return> | ||
255 | The function returns a send callback for the file. | ||
256 | </p> | ||
257 | |||
258 | <p class=note> | ||
259 | Note: This function is designed so that it directly accepts the return | ||
260 | values of Lua's IO <tt>io.open</tt> library function. | ||
261 | </p> | ||
262 | |||
263 | <!-- send.string ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
264 | |||
265 | <p class=name id=send.string> | ||
266 | socket.callback.<b>send.string(</b>str, err<b>)</b> | ||
267 | </p> | ||
268 | |||
269 | <p class=description> | ||
270 | This function creates a send callback that will send | ||
271 | the contents of a string. | ||
272 | </p> | ||
273 | |||
274 | <p class=parameters> | ||
275 | <tt>Str</tt> is the string to be sent. | ||
276 | </p> | ||
277 | |||
278 | <p class=return> | ||
279 | It returns a send callback for the string, | ||
280 | or <b><tt>nil</tt></b> if <tt>str</tt> is <b><tt>nil</tt></b>. | ||
281 | </p> | ||
282 | |||
283 | <!-- send.chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
284 | |||
285 | <p class=name id=send.chain> | ||
286 | socket.callback.<b>send.chain(</b>send_cb, filter<b>)</b> | ||
287 | </p> | ||
288 | |||
289 | <p class=description> | ||
290 | This function creates a send callback that will filter | ||
291 | all the data it receives from another send callback, before | ||
292 | sending it through. | ||
293 | </p> | ||
294 | |||
295 | <p class=parameters> | ||
296 | <tt>Send_cb</tt> is the send callback to be chained to <tt>filter</tt>. | ||
297 | </p> | ||
298 | |||
299 | <p class=return> | ||
300 | Returns a callback chained with the filter. | ||
301 | </p> | ||
302 | |||
303 | <p class=note> | ||
304 | Note: Several filters are defined in the <a href=mime.html>MIME</a> | ||
305 | module. Below is an example that creates a send callback that sends | ||
306 | a file's contents encoded in the Base64 transfer content encoding. | ||
307 | </p> | ||
308 | |||
309 | <pre class=example> | ||
310 | send_cb = socket.callback.send.chain( | ||
311 | socket.callback.send.file(io.open("input.bin")) | ||
312 | socket.mime.chain( | ||
313 | socket.mime.encode("base64"), | ||
314 | socket.mime.wrap("base64") | ||
315 | ) | ||
316 | ) | ||
317 | </pre> | ||
318 | |||
319 | <p class=note> | ||
320 | The call to <a href=mime.html#chain><tt>mime.chain</tt></a> | ||
321 | creates a chained filter that encodes it's input and then breaks it | ||
322 | into lines. The call to <tt>callback.chain</tt> creates a chained | ||
323 | send callback that reads the file from disk and passes it through the | ||
324 | filter before sending it. | ||
325 | </p> | ||
326 | |||
327 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
328 | |||
329 | <div class=footer> | ||
330 | <hr> | ||
331 | <center> | ||
332 | <p class=bar> | ||
333 | <a href="home.html">home</a> · | ||
334 | <a href="home.html#down">download</a> · | ||
335 | <a href="introduction.html">introduction</a> · | ||
336 | <a href="reference.html">reference</a> | ||
337 | </p> | ||
338 | <p> | ||
339 | <small> | ||
340 | Last modified by Diego Nehab on <br> | ||
341 | Sat Aug 9 01:00:41 PDT 2003 | ||
342 | </small> | ||
343 | </p> | ||
344 | </center> | ||
345 | </div> | ||
346 | |||
347 | </body> | ||
348 | </html> | ||
diff --git a/doc/code.html b/doc/code.html deleted file mode 100644 index 4668b7a..0000000 --- a/doc/code.html +++ /dev/null | |||
@@ -1,202 +0,0 @@ | |||
1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
3 | <html> | ||
4 | |||
5 | <head> | ||
6 | <title>LuaSocket: Network support for the Lua language</title> | ||
7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
8 | </head> | ||
9 | |||
10 | <body> | ||
11 | |||
12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
13 | |||
14 | <div class=header> | ||
15 | <hr> | ||
16 | <center> | ||
17 | <table summary="LuaSocket logo"> | ||
18 | <tr><td align=center><a href="http://www.lua.org"> | ||
19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
20 | </a></td></tr> | ||
21 | <tr><td align=center valign=top>Network support for the Lua language | ||
22 | </td></tr> | ||
23 | </table> | ||
24 | <p class=bar> | ||
25 | <a href="home.html">home</a> · | ||
26 | <a href="home.html#download">download</a> · | ||
27 | <a href="introduction.html">introduction</a> · | ||
28 | <a href="reference.html">reference</a> | ||
29 | </p> | ||
30 | </center> | ||
31 | <hr> | ||
32 | </div> | ||
33 | |||
34 | <!-- code +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
35 | |||
36 | <h2 id=code>Code</h2> | ||
37 | |||
38 | <p> | ||
39 | The <tt>code.lua</tt> module offers routines to convert back and forth | ||
40 | some common types of content encoding, including Base 64 and URL | ||
41 | escaping. Base 64 is described in | ||
42 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2045.txt">RFC | ||
43 | 2045</a>, | ||
44 | URL escaping is described in | ||
45 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2396.txt">RFC | ||
46 | 2396</a>. | ||
47 | </p> | ||
48 | |||
49 | <!-- base64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
50 | |||
51 | <p class=name id="base64"> | ||
52 | socket.code.<b>base64(</b>content, single<b>)</b> | ||
53 | </p> | ||
54 | |||
55 | <p class=description> | ||
56 | Applies the Base 64 content coding to a string. | ||
57 | </p> | ||
58 | |||
59 | <p class=parameters> | ||
60 | <tt>Content</tt> is the string to be encoded. | ||
61 | If <tt>single</tt> is set to anything | ||
62 | but <b><tt>nil</tt></b>, the output is returned as a single | ||
63 | line, otherwise the function splits the content into 76 character long | ||
64 | lines after encoding. | ||
65 | </p> | ||
66 | |||
67 | <p class=result> | ||
68 | The function returns the encoded string. | ||
69 | </p> | ||
70 | |||
71 | <pre class=example> | ||
72 | code = socket.code.base64("diego:password") | ||
73 | -- code = "ZGllZ286cGFzc3dvcmQ=" | ||
74 | </pre> | ||
75 | |||
76 | <!-- unbase64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
77 | |||
78 | <p class=name id="unbase64"> | ||
79 | socket.code.<b>unbase64(</b>content<b>)</b> | ||
80 | </p> | ||
81 | |||
82 | <p class=description> | ||
83 | Removes the Base 64 content coding from a string. | ||
84 | </p> | ||
85 | |||
86 | <p class=parameters> | ||
87 | <tt>Content</tt> is the string to be decoded. | ||
88 | </p> | ||
89 | |||
90 | <p class=result> | ||
91 | The function returns the decoded string. | ||
92 | </p> | ||
93 | |||
94 | <!-- escape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
95 | |||
96 | <p class=name id="escape"> | ||
97 | socket.code.<b>escape(</b>content<b>)</b> | ||
98 | </p> | ||
99 | |||
100 | <p class=description> | ||
101 | Applies the URL escaping content coding to a string | ||
102 | Each byte is encoded as a percent character followed | ||
103 | by the two byte hexadecimal representation of its integer | ||
104 | value. | ||
105 | </p> | ||
106 | |||
107 | <p class=parameters> | ||
108 | <tt>Content</tt> is the string to be encoded. | ||
109 | </p> | ||
110 | |||
111 | <p class=result> | ||
112 | The function returns the encoded string. | ||
113 | </p> | ||
114 | |||
115 | <pre class=example> | ||
116 | code = socket.code.escape("/#?;") | ||
117 | -- code = "%2f%23%3f%3b" | ||
118 | </pre> | ||
119 | |||
120 | <!-- unescape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
121 | |||
122 | <p class=name id="unescape"> | ||
123 | socket.code.<b>unescape(</b>content<b>)</b> | ||
124 | </p> | ||
125 | |||
126 | <p class=description> | ||
127 | Removes the URL escaping content coding from a string. | ||
128 | </p> | ||
129 | |||
130 | <p class=parameters> | ||
131 | <tt>Content</tt> is the string to be decoded. | ||
132 | </p> | ||
133 | |||
134 | <p class=return> | ||
135 | The function returns the decoded string. | ||
136 | </p> | ||
137 | |||
138 | <!-- hexa +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
139 | |||
140 | <p class=name id="hexa"> | ||
141 | socket.code.<b>hexa(</b>content<b>)</b> | ||
142 | </p> | ||
143 | |||
144 | <p class=description> | ||
145 | Applies the hexadecimal content coding to a string. | ||
146 | Each byte is encoded as the byte hexadecimal | ||
147 | representation of its integer value. <p> | ||
148 | </p> | ||
149 | |||
150 | <p class=parameters> | ||
151 | <tt>Content</tt> is the string to be encoded. | ||
152 | </p> | ||
153 | |||
154 | <p class=return> | ||
155 | The function returns the encoded string. | ||
156 | </p> | ||
157 | |||
158 | <pre class=example> | ||
159 | code = socket.code.hexa("\16\32\255") | ||
160 | -- code = "1020ff" | ||
161 | </pre> | ||
162 | |||
163 | <!-- unhexa +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
164 | |||
165 | <p class=name id="unhexa"> | ||
166 | socket.code.<b>unhexa(</b>content<b>)</b> | ||
167 | </p> | ||
168 | |||
169 | <p class=description> | ||
170 | Removes the hexadecimal content coding from a string. | ||
171 | </p> | ||
172 | |||
173 | <p class=parameters> | ||
174 | <tt>Content</tt> is the string to be decoded. | ||
175 | </p> | ||
176 | |||
177 | <p class=return> | ||
178 | The function returns the decoded string. | ||
179 | </p> | ||
180 | |||
181 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
182 | |||
183 | <div class=footer> | ||
184 | <hr> | ||
185 | <center> | ||
186 | <p class=bar> | ||
187 | <a href="home.html">home</a> · | ||
188 | <a href="home.html#down">download</a> · | ||
189 | <a href="introduction.html">introduction</a> · | ||
190 | <a href="reference.html">reference</a> | ||
191 | </p> | ||
192 | <p> | ||
193 | <small> | ||
194 | Last modified by Diego Nehab on <br> | ||
195 | Sat Aug 9 01:00:41 PDT 2003 | ||
196 | </small> | ||
197 | </p> | ||
198 | </center> | ||
199 | </div> | ||
200 | |||
201 | </body> | ||
202 | </html> | ||
diff --git a/doc/dns.html b/doc/dns.html index 71a9719..8e63407 100644 --- a/doc/dns.html +++ b/doc/dns.html | |||
@@ -82,7 +82,7 @@ Converts from IP address to host name. | |||
82 | </p> | 82 | </p> |
83 | 83 | ||
84 | <p class=return> | 84 | <p class=return> |
85 | The function a string with the canonic host name of the given | 85 | The function returns a string with the canonic host name of the given |
86 | <tt>address</tt>, followed by a table with all information returned by | 86 | <tt>address</tt>, followed by a table with all information returned by |
87 | the resolver. In case of error, the function returns <b><tt>nil</tt></b> | 87 | the resolver. In case of error, the function returns <b><tt>nil</tt></b> |
88 | followed by an error message. | 88 | followed by an error message. |
diff --git a/doc/reference.html b/doc/reference.html index 6e14891..6372e64 100644 --- a/doc/reference.html +++ b/doc/reference.html | |||
@@ -35,31 +35,6 @@ | |||
35 | 35 | ||
36 | <h2>Reference</h2> | 36 | <h2>Reference</h2> |
37 | 37 | ||
38 | <!-- callback +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
39 | |||
40 | <blockquote> | ||
41 | <a href="callback.html">Callbacks (socket.callback)</a> | ||
42 | <blockquote> | ||
43 | <a href="callback.html#done">done</a>, | ||
44 | <a href="callback.html#fail">fail</a>. | ||
45 | </blockquote> | ||
46 | <blockquote> | ||
47 | <a href="callback.html#send">send</a>: | ||
48 | <a href="callback.html#send.chain">chain</a>, | ||
49 | <a href="callback.html#send.file">file</a>, | ||
50 | <a href="callback.html#send.string">string</a>. | ||
51 | </blockquote> | ||
52 | <blockquote> | ||
53 | <a href="callback.html#receive">receive</a>: | ||
54 | <a href="callback.html#receive.chain">chain</a>, | ||
55 | <a href="callback.html#receive.file">file</a>, | ||
56 | <a href="callback.html#receive.concat">concat</a>. | ||
57 | </blockquote> | ||
58 | </blockquote> | ||
59 | </table> | ||
60 | |||
61 | <!-- dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
62 | |||
63 | <blockquote> | 38 | <blockquote> |
64 | <a href="dns.html">DNS services (socket.dns)</a> | 39 | <a href="dns.html">DNS services (socket.dns)</a> |
65 | <blockquote> | 40 | <blockquote> |
@@ -75,34 +50,45 @@ | |||
75 | <a href="ftp.html">FTP (socket.ftp)</a> | 50 | <a href="ftp.html">FTP (socket.ftp)</a> |
76 | <blockquote> | 51 | <blockquote> |
77 | <a href="ftp.html#get">get</a>, | 52 | <a href="ftp.html#get">get</a>, |
78 | <a href="ftp.html#get_cb">get_cb</a>, | ||
79 | <a href="ftp.html#put">put</a>, | 53 | <a href="ftp.html#put">put</a>, |
80 | <a href="ftp.html#put_cb">put_cb</a>. | 54 | <a href="ftp.html#open">open</a>. |
81 | </blockquote> | 55 | </blockquote> |
82 | </blockquote> | 56 | </blockquote> |
83 | 57 | ||
84 | <!-- misc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 58 | <!-- misc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
85 | 59 | ||
86 | <blockquote> | 60 | <blockquote> |
87 | <a href="global.html">Globals (socket)</a> | 61 | <a href="global.html">Globals</a> |
88 | <blockquote> | 62 | <blockquote> |
89 | <a href="global.html#bind">bind</a>, | 63 | <a href="global.html#LUASOCKET_LIBNAME">LUASOCKET_LIBNAME</a>, |
90 | <a href="global.html#callback">callback</a>, | ||
91 | <a href="global.html#concat">concat</a>, | ||
92 | <a href="global.html#connect">connect</a>, | ||
93 | <a href="global.html#debug">debug</a>, | ||
94 | <a href="global.html#dns">dns</a>, | ||
95 | <a href="global.html#ftp">ftp</a>, | ||
96 | <a href="global.html#http">http</a>, | ||
97 | <a href="global.html#mime">mime</a>, | 64 | <a href="global.html#mime">mime</a>, |
98 | <a href="global.html#select">select</a>, | 65 | <a href="global.html#ltn12">ltn12</a>, |
99 | <a href="global.html#sleep">sleep</a>, | 66 | <a href="global.html#socket">socket</a>. |
100 | <a href="global.html#smtp">smtp</a>, | 67 | </blockquote> |
101 | <a href="global.html#time">time</a>, | 68 | </blockquote> |
102 | <a href="global.html#tcp">tcp</a>. | 69 | </table> |
103 | <a href="global.html#udp">udp</a>, | 70 | |
104 | <a href="global.html#url">url</a>, | 71 | <blockquote> |
105 | <a href="global.html#version">version</a>. | 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>. | ||
106 | </blockquote> | 92 | </blockquote> |
107 | </blockquote> | 93 | </blockquote> |
108 | </table> | 94 | </table> |
@@ -115,15 +101,49 @@ | |||
115 | <blockquote> | 101 | <blockquote> |
116 | <a href="http.html#get">get</a>, | 102 | <a href="http.html#get">get</a>, |
117 | <a href="http.html#post">post</a>, | 103 | <a href="http.html#post">post</a>, |
118 | <a href="http.html#request">request</a>, | 104 | <a href="http.html#request">request</a>. |
119 | <a href="http.html#request_cb">request_cb</a>. | 105 | </blockquote> |
106 | </blockquote> | ||
107 | |||
108 | <!-- ltn12 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
109 | |||
110 | <blockquote> | ||
111 | <a href="ltn12.html">LTN012 (ltn12)</a> | ||
112 | <blockquote> | ||
113 | <a href="ltn12.html#filter">filter</a>: | ||
114 | <a href="ltn12.html#chain">chain</a>, | ||
115 | <a href="ltn12.html#cycle">cycle</a>. | ||
116 | </blockquote> | ||
117 | <blockquote> | ||
118 | <a href="ltn12.html#pump">pump</a>: | ||
119 | <a href="ltn12.html#all">all</a>, | ||
120 | <a href="ltn12.html#step">step</a>. | ||
121 | </blockquote> | ||
122 | <blockquote> | ||
123 | <a href="ltn12.html#sink">sink</a>: | ||
124 | <a href="ltn12.html#chain">chain</a>, | ||
125 | <a href="ltn12.html#error">error</a>, | ||
126 | <a href="ltn12.html#chain">file</a>, | ||
127 | <a href="ltn12.html#file">null</a>, | ||
128 | <a href="ltn12.html#simplify">simplify</a>, | ||
129 | <a href="ltn12.html#table">table</a>. | ||
130 | </blockquote> | ||
131 | <blockquote> | ||
132 | <a href="ltn12.html#source">source</a>: | ||
133 | <a href="ltn12.html#cat">cat</a>, | ||
134 | <a href="ltn12.html#chain">chain</a>, | ||
135 | <a href="ltn12.html#empty">empty</a>, | ||
136 | <a href="ltn12.html#file">file</a>, | ||
137 | <a href="ltn12.html#simplify">simplify</a>, | ||
138 | <a href="ltn12.html#simplify">rewind</a>, | ||
139 | <a href="ltn12.html#simplify">string</a>. | ||
120 | </blockquote> | 140 | </blockquote> |
121 | </blockquote> | 141 | </blockquote> |
122 | 142 | ||
123 | <!-- mime +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 143 | <!-- mime +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
124 | 144 | ||
125 | <blockquote> | 145 | <blockquote> |
126 | <a href="mime.html">MIME (socket.mime) </a> | 146 | <a href="mime.html">MIME (mime) </a> |
127 | <blockquote> | 147 | <blockquote> |
128 | <a href="mime.html#high">high-level</a>: | 148 | <a href="mime.html#high">high-level</a>: |
129 | <a href="mime.html#normalize">normalize</a>, | 149 | <a href="mime.html#normalize">normalize</a>, |
@@ -149,7 +169,9 @@ | |||
149 | <blockquote> | 169 | <blockquote> |
150 | <a href="smtp.html">SMTP (socket.smtp)</a> | 170 | <a href="smtp.html">SMTP (socket.smtp)</a> |
151 | <blockquote> | 171 | <blockquote> |
152 | <a href="smtp.html#mail">mail</a> | 172 | <a href="smtp.html#mail">open</a>, |
173 | <a href="smtp.html#message">message</a>, | ||
174 | <a href="smtp.html#send">send</a>. | ||
153 | </blockquote> | 175 | </blockquote> |
154 | </blockquote> | 176 | </blockquote> |
155 | 177 | ||
diff --git a/doc/stream.html b/doc/stream.html deleted file mode 100644 index 585ad18..0000000 --- a/doc/stream.html +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
3 | <html> | ||
4 | |||
5 | <head> | ||
6 | <title>LuaSocket: Network support for the Lua language</title> | ||
7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
8 | </head> | ||
9 | |||
10 | <body> | ||
11 | |||
12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
13 | |||
14 | <div class=header> | ||
15 | <hr> | ||
16 | <center> | ||
17 | <table summary="LuaSocket logo"> | ||
18 | <tr><td align=center><a href="http://www.lua.org"> | ||
19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
20 | </a></td></tr> | ||
21 | <tr><td align=center valign=top>Network support for the Lua language | ||
22 | </td></tr> | ||
23 | </table> | ||
24 | <p class=bar> | ||
25 | <a href="home.html">home</a> · | ||
26 | <a href="home.html#download">download</a> · | ||
27 | <a href="introduction.html">introduction</a> · | ||
28 | <a href="reference.html">reference</a> | ||
29 | </p> | ||
30 | </center> | ||
31 | <hr> | ||
32 | </div> | ||
33 | |||
34 | <!-- stream ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
35 | |||
36 | <h2 id=stream>Streaming with Callbacks</h2> | ||
37 | |||
38 | <p> | ||
39 | HTTP, FTP, and SMTP transfers sometimes involve large amounts of | ||
40 | information. Sometimes an application needs to generate outgoing data | ||
41 | in real time, or needs to process incoming information as it is being | ||
42 | received. To address these problems, LuaSocket allows HTTP and SMTP message | ||
43 | bodies and FTP file contents to be received or sent through the | ||
44 | callback mechanism outlined below. | ||
45 | </p> | ||
46 | |||
47 | <p> | ||
48 | Instead of returning the entire contents of an entity | ||
49 | as strings to the Lua application, the library allows the user to | ||
50 | provide a <em>receive callback</em> that will be called with successive | ||
51 | chunks of data, as the data becomes available. Conversely, the <em>send | ||
52 | callbacks</em> can be used when the application wants to incrementally | ||
53 | provide LuaSocket with the data to be sent. | ||
54 | </p> | ||
55 | |||
56 | <!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
57 | |||
58 | <p class=name id=receive_cb> | ||
59 | <b>receive_cb(</b>chunk, err<b>)</b> | ||
60 | </p> | ||
61 | |||
62 | <p class=description> | ||
63 | The callback provided by the user will be repeatedly called by the | ||
64 | library whenever new data is available. Each time it is called, the | ||
65 | callback receives successive chunks of downloaded data. | ||
66 | </p> | ||
67 | |||
68 | <p class=parameters> | ||
69 | <tt>Chunk</tt> contains the current chunk of data. | ||
70 | When the transmission is over, the function is called with an | ||
71 | empty string (i.e. <tt>""</tt>) as the <tt>chunk</tt>. | ||
72 | If an error occurs, the function receives <b><tt>nil</tt></b> | ||
73 | as <tt>chunk</tt> and an error message in <tt>err</tt>. | ||
74 | </p> | ||
75 | |||
76 | <p class=return> | ||
77 | The callback can abort transmission by returning <b><tt>nil</tt></b> as its first | ||
78 | return value, and an optional error message as the | ||
79 | second return value. If the application wants to continue receiving | ||
80 | data, the function should return non-<b><tt>nil</tt></b> as it's first return | ||
81 | value. In this case, the function can optionally return a | ||
82 | new callback function, to replace itself, as the second return value. | ||
83 | </p> | ||
84 | |||
85 | <p class=note> | ||
86 | Note: The <tt>callback</tt> module provides several standard receive callbacks, including the following: | ||
87 | </p> | ||
88 | |||
89 | <pre class=example> | ||
90 | function receive.concat(concat) | ||
91 | concat = concat or socket.concat.create() | ||
92 | local callback = function(chunk, err) | ||
93 | -- if not finished, add chunk | ||
94 | if chunk and chunk ~= "" then | ||
95 | concat:addstring(chunk) | ||
96 | return 1 | ||
97 | end | ||
98 | end | ||
99 | return callback, concat | ||
100 | end | ||
101 | </pre> | ||
102 | |||
103 | <p class=note> | ||
104 | This function creates a new receive callback that concatenates all | ||
105 | received chunks into a the same concat object, which can later be | ||
106 | queried for its contents. | ||
107 | </p> | ||
108 | |||
109 | <!-- send_cb ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
110 | |||
111 | <p class=name> | ||
112 | <b>send_cb()</b> | ||
113 | </p> | ||
114 | |||
115 | <p class=description> | ||
116 | The callback provided by the user will be repeatedly called whenever the | ||
117 | library needs more data to be sent. | ||
118 | </p> | ||
119 | |||
120 | <p class=return> | ||
121 | Each time the callback is called, it should return the next chunk of data. It | ||
122 | can optionally return, as it's second return value, a new callback to replace | ||
123 | itself. The callback can abort the process at any time by returning | ||
124 | <b><tt>nil</tt></b> followed by an optional error message. | ||
125 | </p> | ||
126 | |||
127 | <p class=note> | ||
128 | Note: Below is the implementation of the <tt>callback.send.file</tt> | ||
129 | function. Given an open file handle, it returns a send callback that will send the contents of that file, chunk by chunk. | ||
130 | </p> | ||
131 | |||
132 | <pre class=example> | ||
133 | function send.file(file, io_err) | ||
134 | -- if successful, return the callback that reads from the file | ||
135 | if file then | ||
136 | return function() | ||
137 | -- send next block of data | ||
138 | return (file:read(BLOCKSIZE)) or "" | ||
139 | end | ||
140 | -- else, return a callback that just aborts the transfer | ||
141 | else return fail(io_err or "unable to open file") end | ||
142 | end | ||
143 | </pre> | ||
144 | |||
145 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
146 | |||
147 | <div class=footer> | ||
148 | <hr> | ||
149 | <center> | ||
150 | <p class=bar> | ||
151 | <a href="home.html">home</a> · | ||
152 | <a href="home.html#down">download</a> · | ||
153 | <a href="introduction.html">introduction</a> · | ||
154 | <a href="reference.html">reference</a> | ||
155 | </p> | ||
156 | <p> | ||
157 | <small> | ||
158 | Last modified by Diego Nehab on <br> | ||
159 | Sat Aug 9 01:00:41 PDT 2003 | ||
160 | </small> | ||
161 | </p> | ||
162 | </center> | ||
163 | </div> | ||
164 | |||
165 | </body> | ||
166 | </html> | ||