diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-02-04 14:29:11 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-02-04 14:29:11 +0000 |
| commit | 0b2542d1a61fc5425ff65ab3dbf7ba7de174763f (patch) | |
| tree | 8a6188e11db0c9ef6891c31e8a1bebca050b23b2 /doc/callback.html | |
| parent | f67864f86c7d703325e86b14d0ba33992c52891b (diff) | |
| download | luasocket-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.html | 158 |
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> |
| 39 | HTTP, FTP, and SMTP transfers sometimes involve large amounts of | 39 | HTTP, FTP, and SMTP transfers sometimes involve large amounts of |
| 40 | information. Sometimes an application needs to generate outgoing data | 40 | information. Sometimes an application needs to generate outgoing data |
| 41 | in real time, or needs to process incoming information as it is being | 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 | 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 | 43 | bodies and FTP file contents to be streamed through the |
| 44 | callback mechanism outlined below. | 44 | callback 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 | |||
| 52 | callback</em> mechanism can be used when the application wants to incrementally provide LuaSocket with the data to be sent. | 52 | callback</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> |
| 62 | A receive callback will be repeatedly called by | 62 | A receive callback will be repeatedly called by |
| 63 | LuaSocket wheneve new data is available. Each time it is called, the | 63 | LuaSocket whenever new data is available. Each time it is called, the |
| 64 | callback receives successive chunks of downloaded data. | 64 | callback 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 | |||
| 113 | receive information. | 113 | receive information. |
| 114 | </p> | 114 | </p> |
| 115 | 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 | |||
| 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> | 238 | socket.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 |
| 131 | case, the function returns a callback that just aborts | 250 | case, the function returns a callback that just aborts |
| 132 | transmission with the error message. | 251 | transmission with the error message. |
| 133 | </p> | 252 | </p> |
| 134 | 253 | ||
| 135 | <p class=return> | 254 | <p class=return> |
| 136 | Returns a send callback for the file. | 255 | The function returns a send callback for the file. |
| 137 | </p> | 256 | </p> |
| 138 | 257 | ||
| 139 | <p class=note> | 258 | <p class=note> |
| 140 | Note: This function is designed so that it directly accepts the return | 259 | Note: This function is designed so that it directly accepts the return |
| 141 | values of the <tt>io.open</tt> function. | 260 | values 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> | 266 | socket.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 | <!-- | ||
| 158 | If <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> |
| 164 | Returns a send callback for the string, or <b><tt>nil</tt></b> if the string is | 279 | It returns a send callback for the string, |
| 165 | <b><tt>nil</tt></b>. | 280 | or <b><tt>nil</tt></b> if <tt>str</tt> is <b><tt>nil</tt></b>. |
| 166 | </p> | ||
| 167 | |||
| 168 | <p class=note> | ||
| 169 | Note: A <tt>nil</tt></b> | ||
| 170 | send 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> | 286 | socket.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> |
| 210 | The call to <a href=mime.html#chain><tt>socket.mime.chain</tt></a> | 320 | The call to <a href=mime.html#chain><tt>mime.chain</tt></a> |
| 211 | creates a chained filter that encodes it's input and then breaks it | 321 | creates a chained filter that encodes it's input and then breaks it |
| 212 | into lines. The call to <tt>socket.callback.chain</tt> creates a chained | 322 | into lines. The call to <tt>callback.chain</tt> creates a chained |
| 213 | send callback that reads the file from disk and passes it through the | 323 | send callback that reads the file from disk and passes it through the |
| 214 | filter before sending it. | 324 | filter before sending it. |
| 215 | </p> | 325 | </p> |
