aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-01-19 05:41:30 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-01-19 05:41:30 +0000
commit5b8d7dec541a618b4ca7f2205470a28cde2e3e25 (patch)
tree209ad0c80c9a938068401fc5b8fa51942972418f /doc
parent6ac82d50eecdf9bf55f4234ed3a5449afd7a2992 (diff)
downloadluasocket-5b8d7dec541a618b4ca7f2205470a28cde2e3e25.tar.gz
luasocket-5b8d7dec541a618b4ca7f2205470a28cde2e3e25.tar.bz2
luasocket-5b8d7dec541a618b4ca7f2205470a28cde2e3e25.zip
Updated some of the callbacks in callback.lua.
Update get.lua to use the new callbacks. The old "code" module is now the "mime" module. Updated all modules that depended on it. Updated url.lua to use the new namespace scheme, and moved the escape and unescape functions that used to be in the code.lua module to it, since these are specific to urls. Updated the callback entries in the manual.
Diffstat (limited to 'doc')
-rw-r--r--doc/reference.css1
-rw-r--r--doc/reference.html6
-rw-r--r--doc/stream.html89
3 files changed, 44 insertions, 52 deletions
diff --git a/doc/reference.css b/doc/reference.css
index 4f17046..cd7de2c 100644
--- a/doc/reference.css
+++ b/doc/reference.css
@@ -16,7 +16,6 @@ blockquote { margin-left: 3em; }
16a[href] { color: #00007f; } 16a[href] { color: #00007f; }
17 17
18p.name { 18p.name {
19 font-size: large;
20 font-family: monospace; 19 font-family: monospace;
21 padding-top: 1em; 20 padding-top: 1em;
22} 21}
diff --git a/doc/reference.html b/doc/reference.html
index 08fd068..99b1ea7 100644
--- a/doc/reference.html
+++ b/doc/reference.html
@@ -92,7 +92,7 @@
92 92
93<!-- http & ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 93<!-- http & ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
94 94
95<table summary="HTTP and FTP Index" class=index width=100% rules=cols> 95<table summary="HTTP and FTP Index" class=index width=100%>
96<colgroup> <col width="50%"> <col width="50%"> </colgroup> 96<colgroup> <col width="50%"> <col width="50%"> </colgroup>
97<tr> 97<tr>
98<td valign=top><ul> 98<td valign=top><ul>
@@ -135,7 +135,7 @@
135 135
136<!-- smtp & dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 136<!-- smtp & dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
137 137
138<table summary="SMTP and DNS Index" class=index width=100% rules=cols> 138<table summary="SMTP and DNS Index" class=index width=100%>
139<colgroup> <col width="50%"> <col width="50%"> </colgroup> 139<colgroup> <col width="50%"> <col width="50%"> </colgroup>
140<tr> 140<tr>
141<td><ul> 141<td><ul>
@@ -158,7 +158,7 @@
158 158
159<!-- url & code ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 159<!-- url & code ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
160 160
161<table summary="URL and Code Index" class=index width=100% rules=cols> 161<table summary="URL and Code Index" class=index width=100%>
162<colgroup> <col width="50%"> <col width="50%"> </colgroup> 162<colgroup> <col width="50%"> <col width="50%"> </colgroup>
163<tr> 163<tr>
164<td valign=top><ul> 164<td valign=top><ul>
diff --git a/doc/stream.html b/doc/stream.html
index 296ca2e..b88cbb5 100644
--- a/doc/stream.html
+++ b/doc/stream.html
@@ -36,21 +36,21 @@
36<h2 id=stream>Streaming with Callbacks</h2> 36<h2 id=stream>Streaming with Callbacks</h2>
37 37
38<p> 38<p>
39HTTP and FTP transfers sometimes involve large amounts of information. 39HTTP, FTP, and SMTP transfers sometimes involve large amounts of
40Sometimes an application needs to generate outgoing data in real time, 40information. Sometimes an application needs to generate outgoing data
41or needs to process incoming information as it is being received. To 41in real time, or needs to process incoming information as it is being
42address these problems, LuaSocket allows HTTP message bodies and FTP 42received. To address these problems, LuaSocket allows HTTP and SMTP message
43file contents to be received or sent through the callback mechanism 43bodies and FTP file contents to be received or sent through the
44outlined below. 44callback mechanism outlined below.
45</p> 45</p>
46 46
47<p> 47<p>
48Instead of returning the entire contents of a FTP file or HTTP message 48Instead of returning the entire contents of an entity
49body as strings to the Lua application, the library allows the user to 49as strings to the Lua application, the library allows the user to
50provide a <em>receive callback</em> that will be called with successive 50provide a <em>receive callback</em> that will be called with successive
51chunks of data, as the data becomes available. Conversely, the <em>send 51chunks of data, as the data becomes available. Conversely, the <em>send
52callbacks</em> should be used when data needed by LuaSocket 52callbacks</em> can be used when the application wants to incrementally
53is generated incrementally by the application. 53provide LuaSocket with the data to be sent.
54</p> 54</p>
55 55
56<!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 56<!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@@ -68,21 +68,26 @@ callback receives successive chunks of downloaded data.
68<p class=parameters> 68<p class=parameters>
69<tt>Chunk</tt> contains the current chunk of data. 69<tt>Chunk</tt> contains the current chunk of data.
70When the transmission is over, the function is called with an 70When the transmission is over, the function is called with an
71empty string (i.e.&nbsp;<tt>""</tt>) as the <tt>chunk</tt>. If an error occurs, the 71empty string (i.e.&nbsp;<tt>""</tt>) as the <tt>chunk</tt>.
72function receives <tt>nil</tt> as <tt>chunk</tt> and an error message as 72If an error occurs, the function receives <tt>nil</tt>
73<tt>err</tt>. 73as <tt>chunk</tt> and an error message in <tt>err</tt>.
74</p> 74</p>
75 75
76<p class=return> 76<p class=return>
77The callback can abort transmission by returning 77The callback can abort transmission by returning <tt>nil</tt> as its first
78<tt>nil</tt> as its first return value. In that case, it can also return 78return value, and an optional error message as the
79an error message. Any non-<tt>nil</tt> return value proceeds with the 79second return value. If the application wants to continue receiving
80transmission. 80data, the function should return non-<tt>nil</tt> as it's first return
81value. In this case, the function can optionally return a
82new callback function, to replace itself, as the second return value.
83</p>
84
85<p class=note>
86Note: The <tt>callback</tt> module provides several standard receive callbacks, including the following:
81</p> 87</p>
82 88
83<pre class=example> 89<pre class=example>
84-- The implementation of socket.callback.receive_concat 90function receive.concat(concat)
85function Public.receive_concat(concat)
86 concat = concat or socket.concat.create() 91 concat = concat or socket.concat.create()
87 local callback = function(chunk, err) 92 local callback = function(chunk, err)
88 -- if not finished, add chunk 93 -- if not finished, add chunk
@@ -95,6 +100,12 @@ function Public.receive_concat(concat)
95end 100end
96</pre> 101</pre>
97 102
103<p class=note>
104This function creates a new receive callback that concatenates all
105received chunks into a the same concat object, which can later be
106queried for its contents.
107</p>
108
98<!-- send_cb ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 109<!-- send_cb ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
99 110
100<p class=name> 111<p class=name>
@@ -107,45 +118,27 @@ library needs more data to be sent.
107</p> 118</p>
108 119
109<p class=return> 120<p class=return>
110Each time the callback is called, it 121Each time the callback is called, it should return the next chunk of data. It
111should return the next part of the information the library is expecting, 122can optionally return, as it's second return value, a new callback to replace
112followed by the total number of bytes to be sent. 123itself. The callback can abort the process at any time by returning
113The callback can abort 124<tt>nil</tt> followed by an optional error message.
114the process at any time by returning <tt>nil</tt> followed by an
115optional error message.
116</p> 125</p>
117 126
118
119<p class=note> 127<p class=note>
120Note: The need for the second return value comes from the fact that, with 128Note: Below is the implementation of the <tt>callback.send.file</tt>
121the HTTP protocol for instance, the library needs to know in advance the 129function. Given an open file handle, it returns a send callback that will send the contents of that file, chunk by chunk.
122total number of bytes that will be sent.
123</p> 130</p>
124 131
125<pre class=example> 132<pre class=example>
126-- The implementation of socket.callback.send_file 133function send.file(file, io_err)
127function Public.send_file(file) 134 -- if successful, return the callback that reads from the file
128 local callback
129 -- if successfull, return the callback that reads from the file
130 if file then 135 if file then
131 -- get total size 136 return function()
132 local size = file:seek("end")
133 -- go back to start of file
134 file:seek("set")
135 callback = function()
136 -- send next block of data 137 -- send next block of data
137 local chunk = file:read(Public.BLOCKSIZE) 138 return (file:read(BLOCKSIZE)) or ""
138 if not chunk then file:close() end
139 return chunk, size
140 end 139 end
141 -- else, return a callback that just aborts the transfer 140 -- else, return a callback that just aborts the transfer
142 else 141 else return fail(io_err or "unable to open file") end
143 callback = function()
144 -- just abort
145 return nil, "unable to open file"
146 end
147 end
148 return callback, file
149end 142end
150</pre> 143</pre>
151 144