aboutsummaryrefslogtreecommitdiff
path: root/doc/callback.html
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-02-04 14:29:11 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-02-04 14:29:11 +0000
commit0b2542d1a61fc5425ff65ab3dbf7ba7de174763f (patch)
tree8a6188e11db0c9ef6891c31e8a1bebca050b23b2 /doc/callback.html
parentf67864f86c7d703325e86b14d0ba33992c52891b (diff)
downloadluasocket-0b2542d1a61fc5425ff65ab3dbf7ba7de174763f.tar.gz
luasocket-0b2542d1a61fc5425ff65ab3dbf7ba7de174763f.tar.bz2
luasocket-0b2542d1a61fc5425ff65ab3dbf7ba7de174763f.zip
Worked on the manual.
Implemented stuffing (needs test) Added cddb and qp examples.
Diffstat (limited to 'doc/callback.html')
-rw-r--r--doc/callback.html158
1 files changed, 134 insertions, 24 deletions
diff --git a/doc/callback.html b/doc/callback.html
index 94af8ff..98b4476 100644
--- a/doc/callback.html
+++ b/doc/callback.html
@@ -31,16 +31,16 @@
31<hr> 31<hr>
32</div> 32</div>
33 33
34<!-- stream ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 34<!-- stream ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
35 35
36<h2 id=stream>Streaming with Callbacks</h2> 36<h2 id=stream>Callbacks</h2>
37 37
38<p> 38<p>
39HTTP, FTP, and SMTP transfers sometimes involve large amounts of 39HTTP, FTP, and SMTP transfers sometimes involve large amounts of
40information. Sometimes an application needs to generate outgoing data 40information. Sometimes an application needs to generate outgoing data
41in real time, or needs to process incoming information as it is being 41in real time, or needs to process incoming information as it is being
42received. To address these problems, LuaSocket allows HTTP and SMTP message 42received. To address these problems, LuaSocket allows HTTP and SMTP message
43bodies and FTP file contents to be received or sent through the 43bodies and FTP file contents to be streamed through the
44callback mechanism outlined below. 44callback mechanism outlined below.
45</p> 45</p>
46 46
@@ -52,7 +52,7 @@ chunks of data, as the data becomes available. Conversely, the <em>send
52callback</em> mechanism can be used when the application wants to incrementally provide LuaSocket with the data to be sent. 52callback</em> mechanism can be used when the application wants to incrementally provide LuaSocket with the data to be sent.
53</p> 53</p>
54 54
55<!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 55<!-- receive +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
56 56
57<p class=name id=receive> 57<p class=name id=receive>
58<b>receive_cb(</b>chunk, err<b>)</b> 58<b>receive_cb(</b>chunk, err<b>)</b>
@@ -60,7 +60,7 @@ callback</em> mechanism can be used when the application wants to incrementally
60 60
61<p class=description> 61<p class=description>
62A receive callback will be repeatedly called by 62A receive callback will be repeatedly called by
63LuaSocket wheneve new data is available. Each time it is called, the 63LuaSocket whenever new data is available. Each time it is called, the
64callback receives successive chunks of downloaded data. 64callback receives successive chunks of downloaded data.
65</p> 65</p>
66 66
@@ -113,10 +113,129 @@ Together, these two modules provide a powerful interface to send and
113receive information. 113receive information.
114</p> 114</p>
115 115
116<!-- done +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
117
118<p class=name id=done>
119socket.callback.<b>done()</b>
120</p>
121
122<p class=description>
123This function creates and returns a callback that successfully terminates
124the transmission.
125</p>
126
127<!-- fail +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
128
129<p class=name id=fail>
130socket.callback.<b>fail(</b>message<b>)</b>
131</p>
132
133<p class=description>
134This function creates and returns a callback that aborts the
135transmission with a given error <tt>message</tt>.
136</p>
137
138<!-- receive.concat +++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
139
140<p class=name id=receive.concat>
141socket.callback.<b>receive.concat(</b>cat<b>)</b>
142</p>
143
144<p class=description>
145This function creates a receive callback that stores whatever it receives
146into a concat object. When done, the application can get the contents
147received 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>.
152If <tt>cat</tt> is <b><tt>nil</tt></b>, the function creates its own
153concat object.
154</p>
155
156<p class=return>
157The function returns a receive callback for the file, and the concat object
158that will be used to store the received contents.
159</p>
160
161<!-- receive.file +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
162
163<p class=name id=receive.file>
164socket.callback.<b>receive.file(</b>file, io_err<b>)</b>
165</p>
166
167<p class=description>
168This function creates a receive callback that stores whatever it receives
169into 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
175case, the function returns a callback that just aborts
176transmission with the error message.
177</p>
178
179<p class=return>
180The function returns a receive callback for the file.
181</p>
182
183<p class=note>
184Note: This function is designed so that it directly accepts the return
185values of Lua's IO <tt>io.open</tt> library function.
186</p>
187
188<!-- receive.chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
189
190<p class=name id=receive.chain>
191socket.callback.<b>receive.chain(</b>filter, receive_cb<b>)</b>
192</p>
193
194<p class=description>
195This function creates a receive callback that passes all received data
196through 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>.
201If <tt>cat</tt> is <b><tt>nil</tt></b>, the function creates its own
202concat object.
203</p>
204
205<p class=return>
206The function returns a receive callback for the file, and the concat object
207that will be used to store the received contents.
208</p>
209
210<p class=note>
211Note: Several filters are defined in the <a href=mime.html>MIME</a>
212module. Below is an example that creates a receive callback that
213creates a string from the received contents, after decoding the
214Quoted-Printable transfer content encoding.
215</p>
216
217<pre class=example>
218string_cb, concat = socket.callback.receive.concat()
219receive_cb = socket.callback.receive.chain(
220 socket.mime.decode("quoted-printable"),
221 string_cb
222)
223</pre>
224
225<p class=note>
226The call to <tt>callback.chain</tt> creates a chained
227receive callback that decodes data using the
228<tt><a href=mime.html#decode>mime.decode</a></tt>
229Quoted-Printable MIME filter and
230hands the decoded data to a concat receive callback.
231The concatenated decoded data can be retrieved later
232from the associated concat object.
233</p>
234
116<!-- send.file ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 235<!-- send.file ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
117 236
118<p class=name id=send.file> 237<p class=name id=send.file>
119<b>send.file</b>(file, io_err<b>)</b> 238socket.callback.<b>send.file(</b>file, io_err<b>)</b>
120</p> 239</p>
121 240
122<p class=description> 241<p class=description>
@@ -126,25 +245,25 @@ When done, the callback closes the file.
126</p> 245</p>
127 246
128<p class=parameters> 247<p class=parameters>
129<tt>File</tt> is a file opened for reading. If <tt>file</tt> is 248<tt>File</tt> is a file handle opened for reading. If <tt>file</tt> is
130<b><tt>nil</tt></b>, <tt>io_err</tt> can contain an error message. In this 249<b><tt>nil</tt></b>, <tt>io_err</tt> can contain an error message. In this
131case, the function returns a callback that just aborts 250case, the function returns a callback that just aborts
132transmission with the error message. 251transmission with the error message.
133</p> 252</p>
134 253
135<p class=return> 254<p class=return>
136Returns a send callback for the file. 255The function returns a send callback for the file.
137</p> 256</p>
138 257
139<p class=note> 258<p class=note>
140Note: This function is designed so that it directly accepts the return 259Note: This function is designed so that it directly accepts the return
141values of the <tt>io.open</tt> function. 260values of Lua's IO <tt>io.open</tt> library function.
142</p> 261</p>
143 262
144<!-- send.string ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 263<!-- send.string ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
145 264
146<p class=name id=send.string> 265<p class=name id=send.string>
147<b>send.string(</b>str, err<b>)</b> 266socket.callback.<b>send.string(</b>str, err<b>)</b>
148</p> 267</p>
149 268
150<p class=description> 269<p class=description>
@@ -154,26 +273,17 @@ the contents of a string.
154 273
155<p class=parameters> 274<p class=parameters>
156<tt>Str</tt> is the string to be sent. 275<tt>Str</tt> is the string to be sent.
157<!--
158If <tt>str</tt> is
159<b><tt>nil</tt></b>, <tt>err</tt> can optionally contain an error message.
160-->
161</p> 276</p>
162 277
163<p class=return> 278<p class=return>
164Returns a send callback for the string, or <b><tt>nil</tt></b> if the string is 279It returns a send callback for the string,
165<b><tt>nil</tt></b>. 280or <b><tt>nil</tt></b> if <tt>str</tt> is <b><tt>nil</tt></b>.
166</p>
167
168<p class=note>
169Note: A <tt>nil</tt></b>
170send callback is equivalent to a callback that returns the empty string.
171</p> 281</p>
172 282
173<!-- send.chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 283<!-- send.chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
174 284
175<p class=name id=send.chain> 285<p class=name id=send.chain>
176<b>send.chain(</b>send_cb, filter<b>)</b> 286socket.callback.<b>send.chain(</b>send_cb, filter<b>)</b>
177</p> 287</p>
178 288
179<p class=description> 289<p class=description>
@@ -207,9 +317,9 @@ send_cb = socket.callback.send.chain(
207</pre> 317</pre>
208 318
209<p class=note> 319<p class=note>
210The call to <a href=mime.html#chain><tt>socket.mime.chain</tt></a> 320The call to <a href=mime.html#chain><tt>mime.chain</tt></a>
211creates a chained filter that encodes it's input and then breaks it 321creates a chained filter that encodes it's input and then breaks it
212into lines. The call to <tt>socket.callback.chain</tt> creates a chained 322into lines. The call to <tt>callback.chain</tt> creates a chained
213send callback that reads the file from disk and passes it through the 323send callback that reads the file from disk and passes it through the
214filter before sending it. 324filter before sending it.
215</p> 325</p>