diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-15 23:00:56 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-15 23:00:56 +0000 |
commit | 843a431ef98fd541d98fd3898463985d9bfcde28 (patch) | |
tree | 2de4cd78a58ee17aa029528ede8ff5989b819019 | |
parent | cb03a0e95429cc0d498e77fd50241c87fd2bf3ea (diff) | |
download | luasocket-843a431ef98fd541d98fd3898463985d9bfcde28.tar.gz luasocket-843a431ef98fd541d98fd3898463985d9bfcde28.tar.bz2 luasocket-843a431ef98fd541d98fd3898463985d9bfcde28.zip |
Almost done with manual...
-rw-r--r-- | doc/dns.html | 4 | ||||
-rw-r--r-- | doc/http.html | 203 | ||||
-rw-r--r-- | doc/index.html | 77 | ||||
-rw-r--r-- | doc/introduction.html | 75 | ||||
-rw-r--r-- | doc/mime.html | 2 |
5 files changed, 166 insertions, 195 deletions
diff --git a/doc/dns.html b/doc/dns.html index 8e63407..226a604 100644 --- a/doc/dns.html +++ b/doc/dns.html | |||
@@ -70,7 +70,7 @@ The function returns a string with the host name. | |||
70 | <!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 70 | <!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
71 | 71 | ||
72 | <p class=name id=tohostname> | 72 | <p class=name id=tohostname> |
73 | socket.dns.<b>tohostname()</b> | 73 | socket.dns.<b>tohostname(</b>address<b>)</b> |
74 | </p> | 74 | </p> |
75 | 75 | ||
76 | <p class=description> | 76 | <p class=description> |
@@ -91,7 +91,7 @@ followed by an error message. | |||
91 | <!-- toip +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 91 | <!-- toip +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
92 | 92 | ||
93 | <p class=name id=toip> | 93 | <p class=name id=toip> |
94 | socket.dns.<b>toip()</b> | 94 | socket.dns.<b>toip(</b>address<b>)</b> |
95 | </p> | 95 | </p> |
96 | 96 | ||
97 | <p class=description> | 97 | <p class=description> |
diff --git a/doc/http.html b/doc/http.html index 16595f7..39eb2e4 100644 --- a/doc/http.html +++ b/doc/http.html | |||
@@ -98,36 +98,36 @@ Note: MIME headers are independent of order. Therefore, there is no problem | |||
98 | in representing them in a Lua table. | 98 | in representing them in a Lua table. |
99 | </p> | 99 | </p> |
100 | 100 | ||
101 | <p> | ||
102 | The following constants can be set to control the default behaviour of | ||
103 | the HTTP module: | ||
104 | </p> | ||
105 | |||
106 | <ul> | ||
107 | <li> <tt>PORT</tt>: default port used for connections; | ||
108 | <li> <tt>PROXY</tt>: default proxy used for connections; | ||
109 | <li> <tt>TIMEOUT</tt>: sets the timeout for all I/O operations; | ||
110 | <li> <tt>USERAGENT</tt>: default user agent reported to server. | ||
111 | </ul> | ||
112 | |||
101 | <!-- http.get +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 113 | <!-- http.get +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
102 | 114 | ||
103 | <p class=name id=get> | 115 | <p class=name id=get> |
104 | socket.http.<b>get(</b>url<b>)</b><br> | 116 | http.<b>get(</b>url<b>)</b><br> |
105 | socket.http.<b>get{</b><br> | ||
106 | url = <i>string</i>,<br> | ||
107 | headers = <i>header-table</i>,<br> | ||
108 | user = <i>string</i>,<br> | ||
109 | password = <i>string</i>,<br> | ||
110 | stay = <i>bool</i>,<br> | ||
111 | <b>}</b> | ||
112 | </p> | 117 | </p> |
113 | 118 | ||
114 | <p class=description> | 119 | <p class=description> |
115 | Performs the HTTP method <tt>GET</tt>. | 120 | Performs the HTTP method <tt>GET</tt>. |
116 | </p> | 121 | </p> |
117 | 122 | ||
118 | <p class=parameters> | 123 | <p class=parameters> |
119 | The function can be | 124 | <tt>Url</tt> identifies the entity to retrieve. |
120 | called either directly with a <tt>url</tt> or with a <em>request table</em>. | ||
121 | The use of a request table allows complete control over the components of | ||
122 | the request. Values passed explicitly as fields of the request table | ||
123 | override those given by the <tt>url</tt>. For a description of the fields, | ||
124 | see the <a href=#request><tt>request</tt></a> function. | ||
125 | </p> | 125 | </p> |
126 | 126 | ||
127 | <p class=return> | 127 | <p class=return> |
128 | The function returns the response message body, the mime headers, the | 128 | If successful, the function returns the response message body, the mime |
129 | status code and an error message (if any). In case of failure, the | 129 | headers, and the status code. In case of failure, the |
130 | function returns all information it managed to gather. | 130 | function returns <tt><b>nil</b></tt> followed by an error message. |
131 | </p> | 131 | </p> |
132 | 132 | ||
133 | <p class=note> | 133 | <p class=note> |
@@ -136,35 +136,30 @@ Note: The function is trivially implemented with the use of the | |||
136 | </p> | 136 | </p> |
137 | 137 | ||
138 | <pre class=example> | 138 | <pre class=example> |
139 | -- load the http module | ||
140 | http = require("http") | ||
141 | |||
139 | -- connect to server "www.tecgraf.puc-rio.br" and retrieves this manual | 142 | -- connect to server "www.tecgraf.puc-rio.br" and retrieves this manual |
140 | -- file from "/luasocket/http.html" | 143 | -- file from "/luasocket/http.html" |
141 | b, h, c, e = socket.http.get("http://www.tecgraf.puc-rio.br/luasocket/http.html") | 144 | b, h, c = http.get("http://www.tecgraf.puc-rio.br/luasocket/http.html") |
142 | 145 | ||
143 | -- connect to server "www.tecgraf.puc-rio.br" and tries to retrieve | 146 | -- connect to server "www.tecgraf.puc-rio.br" and tries to retrieve |
144 | -- "~diego/auth/index.html". Fails because authentication is needed. | 147 | -- "~diego/auth/index.html". Fails because authentication is needed. |
145 | b, h, c, e = socket.http.get("http://www.tecgraf.puc-rio.br/~diego/auth/index.html") | 148 | b, h, c = http.get("http://www.tecgraf.puc-rio.br/~diego/auth/index.html") |
146 | -- b returns some useless page telling about the denied access, | 149 | -- b returns some useless page telling about the denied access, |
147 | -- h returns authentication information | 150 | -- h returns authentication information |
148 | -- and c returns with value 401 (Authentication Required) | 151 | -- and c returns with value 401 (Authentication Required) |
149 | 152 | ||
150 | -- tries to connect to server "wrong.host" to retrieve "/" | 153 | -- tries to connect to server "wrong.host" to retrieve "/" |
151 | -- and fails because the host does not exist. | 154 | -- and fails because the host does not exist. |
152 | b, h, c, e = socket.http.get("http://wrong.host/") | 155 | r, e = http.get("http://wrong.host/") |
153 | -- b, h, c are nil, and e returns with value "host not found" | 156 | -- r is nil, and e returns with value "host not found" |
154 | </pre> | 157 | </pre> |
155 | 158 | ||
156 | <!-- http.post ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 159 | <!-- http.post ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
157 | 160 | ||
158 | <p class=name id=post> | 161 | <p class=name id=post> |
159 | socket.http.<b>post(</b>url, body<b>)</b><br> | 162 | http.<b>post(</b>url, body<b>)</b><br> |
160 | socket.http.<b>post{</b><br> | ||
161 | url = <i>string</i>,<br> | ||
162 | headers = <i>header-table</i>,<br> | ||
163 | body = <i>string</i>,<br> | ||
164 | user = <i>string</i>,<br> | ||
165 | password = <i>string</i>,<br> | ||
166 | stay = <i>bool</i>,<br> | ||
167 | <b>}</b> | ||
168 | </p> | 163 | </p> |
169 | 164 | ||
170 | <p class=description> | 165 | <p class=description> |
@@ -181,50 +176,64 @@ Note: This function is also trivially implemented with the use of the | |||
181 | <!-- http.request ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 176 | <!-- http.request ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
182 | 177 | ||
183 | <p class=name id=request> | 178 | <p class=name id=request> |
184 | socket.http.<b>request{</b><br> | 179 | http.<b>request{</b><br> |
185 | method = <i>string</i>,<br> | ||
186 | url = <i>string</i>,<br> | 180 | url = <i>string</i>,<br> |
187 | headers = <i>header-table</i>,<br> | 181 | [sink = <i>LTN12 sink</i>],]<br> |
188 | body = <i>string</i>,<br> | 182 | [method = <i>string</i>,]<br> |
189 | user = <i>string</i>,<br> | 183 | [headers = <i>header-table</i>,]<br> |
190 | password = <i>string</i>,<br> | 184 | [source = <i>LTN12 source</i>],<br> |
191 | stay = <i>string</i>,<br> | 185 | [step = <i>LTN12 pump step</i>,]<br> |
186 | [proxy = <i>string</i>,]<br> | ||
187 | [redirect = <i>boolean</i>]<br> | ||
192 | <b>}</b> | 188 | <b>}</b> |
193 | </p> | 189 | </p> |
194 | 190 | ||
195 | <p class=description> | 191 | <p class=description> |
196 | Performs the generic HTTP request using. | 192 | Performs the generic HTTP request, controled by a request table. |
197 | </p> | 193 | </p> |
198 | 194 | ||
199 | <p class=parameters> | 195 | <p class=parameters> |
200 | The request uses <tt>method</tt> on <tt>url</tt> | 196 | The most important parameters are the <tt>url</tt> and the LTN12 |
201 | sending the request <tt>headers</tt> and request <tt>body</tt> in the | 197 | <tt>sink</tt> that will receive the downloaded content. |
202 | request message. If authentication information is provided, the function | 198 | Any part of the <tt>url</tt> can be overriden by including |
199 | the appropriate field in the request table. | ||
200 | If authentication information is provided, the function | ||
203 | uses the Basic Authentication Scheme (see <a href="#authentication">note</a>) | 201 | uses the Basic Authentication Scheme (see <a href="#authentication">note</a>) |
204 | to retrieve the document. <tt>User</tt> and <tt>password</tt> provided | 202 | to retrieve the document. If <tt>sink</tt> is <tt><b>nil</b></tt>, the |
205 | explicitly override those given by the <tt>url</tt>. The <tt>stay</tt> | 203 | function discards the downloaded data. The optional parameters are the |
206 | parameter, when set to anything but <b><tt>nil</tt></b>, prevents the function | 204 | following: |
207 | from automatically following 301 or 302 server redirect messages. | 205 | </p> |
208 | </p> | 206 | <ul> |
207 | <li><tt>method</tt>: The HTTP request method. Defaults to "GET"; | ||
208 | <li><tt>headers</tt>: Any additional HTTP headers to send with the request; | ||
209 | <li><tt>source</tt>: LTN12 source to provide the request body. If there | ||
210 | is a body, you need to provide an appropriate "<tt>content-length</tt>" | ||
211 | request header field, or the function will attempt to send the body as | ||
212 | "<tt>chunked</tt>" (something few servers support). Defaults to the empty source; | ||
213 | <li><tt>step</tt>: LTN12 pump step function used to move data. | ||
214 | Defaults to the LTN12 <tt>pump.step</tt> function. | ||
215 | <li><tt>proxy</tt>: The URL of a proxy server to use. Defaults to no proxy; | ||
216 | <li><tt>redirect</tt>: Set to <tt><b>false</b></tt> to prevent the | ||
217 | function from automatically following 301 or 302 server redirect messages. | ||
218 | </ul> | ||
209 | 219 | ||
210 | <p class=return> | 220 | <p class=return> |
211 | The function returns a table with all components of the response message | 221 | In case of failure, the function returns <tt><b>nil</b></tt> followed by an |
212 | it managed to retrieve. The response table has the following form: | 222 | error message. If successful, the function returns a table |
223 | with all components of the response message. The response table has the following form: | ||
213 | </p> | 224 | </p> |
214 | 225 | ||
215 | <blockquote><tt> | 226 | <blockquote><tt> |
216 | response = {<br> | 227 | respt = {<br> |
217 | body = <i>string</i>,<br> | ||
218 | headers = <i>header-table</i>,<br> | 228 | headers = <i>header-table</i>,<br> |
219 | status = <i>string</i>,<br> | 229 | status = <i>string</i>,<br> |
220 | code = <i>number</i>,<br> | 230 | code = <i>number</i>,<br> |
221 | error = <i>string</i><br> | ||
222 | } | 231 | } |
223 | </tt></blockquote> | 232 | </tt></blockquote> |
224 | 233 | ||
225 | <p class=return> | 234 | <p class=return> |
226 | Even when there was failure (URL not found, for example), the | 235 | Even when there was failure (URL not found, for example), the |
227 | function may succeed retrieving a message body (a web page informing the | 236 | function usually succeeds retrieving a message body (a web page informing the |
228 | URL was not found or some other useless page). To make sure the | 237 | URL was not found or some other useless page). To make sure the |
229 | operation was successful, check the returned status <tt>code</tt>. For | 238 | operation was successful, check the returned status <tt>code</tt>. For |
230 | a list of the possible values and their meanings, refer to <a | 239 | a list of the possible values and their meanings, refer to <a |
@@ -233,15 +242,18 @@ href="http://www.cs.princeton.edu/~diego/rfc/rfc2616.txt">RFC | |||
233 | </p> | 242 | </p> |
234 | 243 | ||
235 | <pre class=example> | 244 | <pre class=example> |
245 | -- load the http module | ||
246 | http = require("http") | ||
247 | |||
236 | -- Requests information about a document, without downloading it. | 248 | -- Requests information about a document, without downloading it. |
237 | -- Useful, for example, if you want to display a download gauge and need | 249 | -- Useful, for example, if you want to display a download gauge and need |
238 | -- to know the size of the document in advance | 250 | -- to know the size of the document in advance |
239 | response = socket.http.request { | 251 | respt = http.request { |
240 | method = "HEAD", | 252 | method = "HEAD", |
241 | url = "http://www.tecgraf.puc-rio.br/~diego" | 253 | url = "http://www.tecgraf.puc-rio.br/~diego" |
242 | } | 254 | } |
243 | -- Would return the following headers: | 255 | -- Would return the following headers: |
244 | -- response.headers = { | 256 | -- respt.headers = { |
245 | -- date = "Tue, 18 Sep 2001 20:42:21 GMT", | 257 | -- date = "Tue, 18 Sep 2001 20:42:21 GMT", |
246 | -- server = "Apache/1.3.12 (Unix) (Red Hat/Linux)", | 258 | -- server = "Apache/1.3.12 (Unix) (Red Hat/Linux)", |
247 | -- ["last-modified"] = "Wed, 05 Sep 2001 06:11:20 GMT", | 259 | -- ["last-modified"] = "Wed, 05 Sep 2001 06:11:20 GMT", |
@@ -276,10 +288,14 @@ authentication is required. | |||
276 | </p> | 288 | </p> |
277 | 289 | ||
278 | <pre class=example> | 290 | <pre class=example> |
291 | -- load required modules | ||
292 | http = require("http") | ||
293 | mime = require("mime") | ||
294 | |||
279 | -- Connect to server "www.tecgraf.puc-rio.br" and tries to retrieve | 295 | -- Connect to server "www.tecgraf.puc-rio.br" and tries to retrieve |
280 | -- "~diego/auth/index.html", using the provided name and password to | 296 | -- "~diego/auth/index.html", using the provided name and password to |
281 | -- authenticate the request | 297 | -- authenticate the request |
282 | response = socket.http.request{ | 298 | respt = http.request{ |
283 | url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html", | 299 | url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html", |
284 | user = "diego", | 300 | user = "diego", |
285 | password = "password" | 301 | password = "password" |
@@ -287,83 +303,12 @@ response = socket.http.request{ | |||
287 | 303 | ||
288 | -- Alternatively, one could fill the appropriate header and authenticate | 304 | -- Alternatively, one could fill the appropriate header and authenticate |
289 | -- the request directly. | 305 | -- the request directly. |
290 | headers = { | 306 | respt = http.request { |
291 | authentication = "Basic " .. socket.code.base64("diego:password") | ||
292 | } | ||
293 | response = socket.http.request { | ||
294 | url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html", | 307 | url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html", |
295 | headers = headers | 308 | headers = { authentication = "Basic " .. (mime.b64("diego:password")) } |
296 | } | 309 | } |
297 | </pre> | 310 | </pre> |
298 | 311 | ||
299 | <!-- request_cb +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
300 | |||
301 | <p class=name id=request_cb> | ||
302 | socket.http.<b>request_cb(</b>request, response<b>)</b> | ||
303 | </p> | ||
304 | |||
305 | <p class=description> | ||
306 | Performs the generic HTTP request. | ||
307 | </p> | ||
308 | |||
309 | <p class=parameters> | ||
310 | The function receives two tables as parameters. The <tt>request</tt> table | ||
311 | provides information about the request: | ||
312 | </p> | ||
313 | |||
314 | <blockquote><tt> | ||
315 | request = {<br> | ||
316 | method = <i>string</i>,<br> | ||
317 | url = <i>string</i>,<br> | ||
318 | headers = <i>header-table</i>,<br> | ||
319 | body_cb = <i>send-callback</i>,<br> | ||
320 | user = <i>string</i>,<br> | ||
321 | password = <i>string</i>,<br> | ||
322 | stay = <i>string</i>,<br> | ||
323 | }</tt> | ||
324 | </blockquote> | ||
325 | |||
326 | <p class=parameters> | ||
327 | The function uses the HTTP method specified in | ||
328 | <tt>request.method</tt> on the URL <tt>request.url</tt>, | ||
329 | sending <tt>request.headers</tt> along with the request. The request | ||
330 | message body is sent via the send callback <tt>request.body_cb</tt>. | ||
331 | If authentication information is provided, the function uses the Basic | ||
332 | Authentication Scheme (see <a href="#authentication">note</a>) to | ||
333 | retrieve the document. <tt>Request.user</tt> and | ||
334 | <tt>request.password</tt> override those given by the | ||
335 | <tt>request.url</tt>. The <tt>request.stay</tt> parameter, when set to | ||
336 | anything but <b><tt>nil</tt></b>, prevents the function from automatically | ||
337 | following 301 or 302 server redirect messages. | ||
338 | </p> | ||
339 | |||
340 | <p class=parameters> | ||
341 | The <tt>response</tt> table specifies information about the desired | ||
342 | response: | ||
343 | </p> | ||
344 | |||
345 | <blockquote><tt> | ||
346 | response = {<br> | ||
347 | body_cb = <i>receive-callback</i><br> | ||
348 | }</tt> | ||
349 | </blockquote> | ||
350 | |||
351 | <p class=return> | ||
352 | The function returns the same response table as that returned by the | ||
353 | <tt>socket.http.request</tt> function, except the response message body is | ||
354 | returned to the receive callback given by the | ||
355 | <tt>response.body_cb</tt> field. | ||
356 | </p> | ||
357 | |||
358 | <p class=note> | ||
359 | Note: For more information on callbacks, please refer to | ||
360 | <a href="stream.html#stream">Streaming with callbacks</a>. | ||
361 | </p> | ||
362 | |||
363 | <p class=note> | ||
364 | Note: Method names are case <em>sensitive</em> | ||
365 | </p> | ||
366 | |||
367 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 312 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
368 | 313 | ||
369 | <div class=footer> | 314 | <div class=footer> |
diff --git a/doc/index.html b/doc/index.html index a2c2d59..c4c1e2f 100644 --- a/doc/index.html +++ b/doc/index.html | |||
@@ -47,7 +47,7 @@ applications that deal with the Internet. | |||
47 | <p> | 47 | <p> |
48 | Network support has been implemented so that it is both efficient and | 48 | Network support has been implemented so that it is both efficient and |
49 | simple to use. LuaSocket can be used by any Lua application once it has | 49 | simple to use. LuaSocket can be used by any Lua application once it has |
50 | been properly linked with and initialized by the interpreter running the | 50 | been properly initialized by the interpreter running the |
51 | Lua application. The code has been tested and runs well on several Windows | 51 | Lua application. The code has been tested and runs well on several Windows |
52 | and Unix platforms. | 52 | and Unix platforms. |
53 | </p> | 53 | </p> |
@@ -61,7 +61,7 @@ LuaSocket. | |||
61 | </p> | 61 | </p> |
62 | 62 | ||
63 | <p> | 63 | <p> |
64 | Copyright © 1999-2003 Tecgraf/PUC-Rio. All rights reserved. <br> | 64 | Copyright © 1999-2004 Tecgraf/PUC-Rio. All rights reserved. <br> |
65 | Author: <A href="http://www.cs.princeton.edu/~diego">Diego Nehab</a> | 65 | Author: <A href="http://www.cs.princeton.edu/~diego">Diego Nehab</a> |
66 | </p> | 66 | </p> |
67 | 67 | ||
@@ -70,7 +70,7 @@ Author: <A href="http://www.cs.princeton.edu/~diego">Diego Nehab</a> | |||
70 | <h2 id=download>Download</h2> | 70 | <h2 id=download>Download</h2> |
71 | 71 | ||
72 | <p> | 72 | <p> |
73 | LuaSocket version 2.0 alpha is now available for download! It is | 73 | LuaSocket version 2.0 beta is now available for download! It is |
74 | compatible with Lua 5.0 and has been tested on | 74 | compatible with Lua 5.0 and has been tested on |
75 | Windows XP, Linux, and Mac OS X. | 75 | Windows XP, Linux, and Mac OS X. |
76 | </p> | 76 | </p> |
@@ -81,8 +81,8 @@ The library can be downloaded in source code from the following links: | |||
81 | 81 | ||
82 | <blockquote> | 82 | <blockquote> |
83 | <p> | 83 | <p> |
84 | <a href="luasocket-2.0-alpha.tar.gz">luasocket-2.0-alpha.tar.gz</a> <br> | 84 | <a href="luasocket-2.0-beta.tar.gz">luasocket-2.0-beta.tar.gz</a> <br> |
85 | <a href="luasocket-2.0-alpha.zip">luasocket-2.0-alpha.zip</a> | 85 | <a href="luasocket-2.0-beta.zip">luasocket-2.0-beta.zip</a> |
86 | </p> | 86 | </p> |
87 | </blockquote> | 87 | </blockquote> |
88 | 88 | ||
@@ -112,11 +112,11 @@ option, and should be able to run the automatic test procedures. | |||
112 | <h2 id=thanks>Special thanks</h2> | 112 | <h2 id=thanks>Special thanks</h2> |
113 | 113 | ||
114 | <p> | 114 | <p> |
115 | Throughout LuaSocket its history, many people gave sugestions that helped | 115 | Throughout LuaSocket's history, many people gave sugestions that helped |
116 | improve it. For that, I thank the Lua comunity. | 116 | improve it. For that, I thank the Lua comunity. |
117 | Special thanks go to | 117 | Special thanks go to |
118 | David Burgess, who has pushed the library to a new level of quality and | 118 | David Burgess, who has pushed the library to a new level of quality and |
119 | from whom I have learned a lot stuff that doesn't show up in RFCs. | 119 | from whom I have learned a lot of stuff that doesn't show up in RFCs. |
120 | Special thanks also to Carlos Cassino, who played a big part in the | 120 | Special thanks also to Carlos Cassino, who played a big part in the |
121 | extensible design seen in the C core of LuaSocket 2.0. | 121 | extensible design seen in the C core of LuaSocket 2.0. |
122 | </p> | 122 | </p> |
@@ -127,7 +127,7 @@ extensible design seen in the C core of LuaSocket 2.0. | |||
127 | 127 | ||
128 | 128 | ||
129 | <p> | 129 | <p> |
130 | Most of the changes for 2.0 happened in the C layer, which | 130 | Everything is new! Many changes for 2.0 happened in the C layer, which |
131 | has been almost completely rewritten. The code has been ported to Lua 5.0 | 131 | has been almost completely rewritten. The code has been ported to Lua 5.0 |
132 | and greatly improved. There have also been some API changes | 132 | and greatly improved. There have also been some API changes |
133 | that made the interface simpler and more consistent. Here are some of | 133 | that made the interface simpler and more consistent. Here are some of |
@@ -140,58 +140,85 @@ the changes that made it into version 2.0: | |||
140 | pipes (on Unix) and named pipes (on windows) as a bonus; | 140 | pipes (on Unix) and named pipes (on windows) as a bonus; |
141 | 141 | ||
142 | <li> Following the Lua 5.0 trend, all functions provided by the library are | 142 | <li> Following the Lua 5.0 trend, all functions provided by the library are |
143 | in the namespace <tt>socket</tt>. Functions such as | 143 | in namespaces. These should be obtained with calls to the |
144 | <tt>require</tt> function. Functions such as | ||
144 | send/receive/timeout/close etc do not exist anymore as stand-alone | 145 | send/receive/timeout/close etc do not exist anymore as stand-alone |
145 | functions. They are now only available as methods of the appropriate | 146 | functions. They are now only available as methods of the appropriate |
146 | objects; | 147 | objects; |
147 | 148 | ||
148 | <li> All functions return a non-nil value as first return value if successful. | 149 | <li> All functions return a non-nil value as first return value if successful. |
149 | All functions return whatever could be retrieved followed by error message | 150 | All functions return <b><tt>nil</tt></b> followed by error message |
150 | in case of error. The best way to check for errors is to check for the | 151 | in case of error; |
151 | presence of an error message; | ||
152 | 152 | ||
153 | <li> UDP connected sockets can break association with peer by calling | 153 | <li> Better error messages and parameter checking; |
154 | |||
155 | <li> Should be interrupt safe; | ||
156 | |||
157 | <li> UDP connected sockets can break association with peer by calling | ||
154 | <tt>setpeername</tt> with address '<tt>*</tt>'; | 158 | <tt>setpeername</tt> with address '<tt>*</tt>'; |
155 | 159 | ||
156 | <li> TCP has been changed to become more uniform. First create an object, | 160 | <li> TCP has been changed to become more uniform. First create an object, |
157 | then connect or bind if needed, and finally use I/O functions. The | 161 | then connect or bind if needed, and finally use I/O functions. The |
158 | <tt>socket.connect</tt> and <tt>socket.bind</tt> functions are still | 162 | <tt>socket.connect</tt> and <tt>socket.bind</tt> functions are still |
159 | provided for simplicity, but they just call <tt>socket.tcp</tt> followed | 163 | provided for simplicity, but they just call <tt>socket.tcp</tt> followed |
160 | by the <tt>connect</tt> or <tt>bind</tt> methods; | 164 | by the <tt>connect</tt> or <tt>bind/listen</tt> methods; |
161 | 165 | ||
162 | <li> Better error messages and parameter checking; | 166 | <li> Greatly reduced the number of times select is called during data |
167 | transfers, by calling only on failure; | ||
168 | |||
169 | <li> TCP can set timeout value before connecting and also bind to local | ||
170 | address before connecting; | ||
171 | |||
172 | <li> <tt>socket.select</tt> returns associative sets and checks if | ||
173 | sockets had buffered data; | ||
163 | 174 | ||
164 | <li> <tt>socket.sleep</tt> and <tt>socket.time</tt> are now part of the | 175 | <li> <tt>socket.sleep</tt> and <tt>socket.time</tt> are now part of the |
165 | library and are supported. They used to be available only when | 176 | library and are supported. They used to be available only when |
166 | LUASOCKET_DEBUG was defined, but it turns out they might be useful for | 177 | LUASOCKET_DEBUG was defined, but it turns out they might be useful for |
167 | applications; | 178 | applications; |
168 | 179 | ||
169 | <li> Socket options interface has been improved and TCP objects also | 180 | <li> <tt>socket.try</tt> and <tt>socket.protect</tt> provide a simple |
170 | support socket options. | 181 | interface to exceptions that proved very in the implementation of |
182 | high-level modules; | ||
183 | |||
184 | <li> Socket options interface has been improved. TCP objects also | ||
185 | support socket options and many other options were added. | ||
186 | |||
187 | </ul> | ||
188 | |||
189 | <p> | ||
190 | Lots of changes in the Lua modules, too. The new MIME and LTN12 modules | ||
191 | make all other modules much more powerful. The main new functionality is | ||
192 | the support for multipart messages in the SMTP module. | ||
193 | </p> | ||
194 | |||
195 | <ul> | ||
196 | |||
197 | <li> | ||
171 | 198 | ||
172 | </ul> | 199 | </ul> |
173 | 200 | ||
201 | |||
174 | <!-- incompatible +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 202 | <!-- incompatible +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
175 | 203 | ||
176 | <h3 id=incompatible>Incompatibilities with previous versions</h3> | 204 | <h3 id=incompatible>Incompatibilities with previous versions</h3> |
177 | 205 | ||
178 | <ul> | 206 | <ul> |
207 | |||
179 | <li> The introduction of namespaces affects all programs that use LuaSocket, | 208 | <li> The introduction of namespaces affects all programs that use LuaSocket, |
180 | specially code that relies on global functions. These are no longer | 209 | specially code that relies on global functions. These are no longer |
181 | available. Note that even the support modules (<tt>http</tt>, <tt>smtp</tt> | 210 | available. Note that even the support modules (<tt>http</tt>, <tt>smtp</tt> |
182 | etc) have been moved to the namespace (i.e. <tt>socket.http</tt>, | 211 | etc) are independent now and should be "<tt>require</tt>ed"; |
183 | <tt>socket.smtp</tt> etc); | 212 | |
213 | <li> FTP, SMTP and HTTP are completely new; I am sure you will | ||
214 | agree the new stuff is better; | ||
184 | 215 | ||
185 | <li> WARNING: The new <tt>send</tt>, | 216 | <li> WARNING: The new <tt>send</tt>, <tt><b>receive</b></tt>, |
186 | <tt>sendto</tt>, <tt>setpeername</tt> and <tt>setsockname</tt>, | 217 | <tt>sendto</tt>, <tt>setpeername</tt> and <tt>setsockname</tt>, |
187 | <tt>ftp.put</tt>, <tt>ftp.put_cb</tt> return convention WILL break old code; | 218 | return convention WILL break old code; |
188 | 219 | ||
189 | <li> Interface to options has changed; | 220 | <li> Interface to options has changed; |
190 | 221 | ||
191 | <li> <tt>socket.select</tt> refuses tables that have anything that is not | ||
192 | an object from the group <tt>select{able}</tt>. This includes even the | ||
193 | '<tt>n</tt>' field. Silently ignoring objects was a source of bugs for Lua | ||
194 | programs. | ||
195 | </ul> | 222 | </ul> |
196 | 223 | ||
197 | <!-- old ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 224 | <!-- old ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
diff --git a/doc/introduction.html b/doc/introduction.html index e6f0ea2..86c552b 100644 --- a/doc/introduction.html +++ b/doc/introduction.html | |||
@@ -37,12 +37,12 @@ | |||
37 | 37 | ||
38 | <p> | 38 | <p> |
39 | Communication in LuaSocket is performed via I/O objects. These can | 39 | Communication in LuaSocket is performed via I/O objects. These can |
40 | represent different network domains. Currently, support is | 40 | represent different network domains. Currently, support is provided for TCP |
41 | provided for TCP and UDP, but there is work in progress to implement SSL, | 41 | and UDP, but nothing prevents other developers from implementing SSL, Local |
42 | Local Domain, Pipes, File Descriptors etc. I/O objects provide a standard | 42 | Domain, Pipes, File Descriptors etc. I/O objects provide a standard |
43 | interface to I/O across different domains and operating systems. | 43 | interface to I/O across different domains and operating systems. |
44 | LuaSocket 2.0 has been rewritten from scratch to simplify the future | 44 | LuaSocket 2.0 has been rewritten from scratch to simplify the future |
45 | addition of new domains. | 45 | addition of new domains. |
46 | </p> | 46 | </p> |
47 | 47 | ||
48 | <p> | 48 | <p> |
@@ -93,7 +93,7 @@ Previous versions of LuaSocket provided global functions for operating on | |||
93 | I/O objects. To give the library a Lua 5.0 feel, these have been eliminated | 93 | I/O objects. To give the library a Lua 5.0 feel, these have been eliminated |
94 | from LuaSocket 2.0. I/O operations are only available as methods of the | 94 | from LuaSocket 2.0. I/O operations are only available as methods of the |
95 | corresponding I/O objects. Naturally, different I/O objects accept | 95 | corresponding I/O objects. Naturally, different I/O objects accept |
96 | different operations. The core functionality for TCP and UDP objects is | 96 | different operations. The TCP and UDP objects are |
97 | introduced in the following sections, following a few words about | 97 | introduced in the following sections, following a few words about |
98 | initialization. | 98 | initialization. |
99 | </p> | 99 | </p> |
@@ -103,18 +103,23 @@ initialization. | |||
103 | <h3>Initializing the library</h3> | 103 | <h3>Initializing the library</h3> |
104 | 104 | ||
105 | <p> | 105 | <p> |
106 | The core LuaSocket functionality is implemented in C, and usually available as | ||
107 | a dynamic library which the interpreter can load when required. | ||
106 | Beginning with version 2.0 and following the Lua 5.0 trend, all LuaSocket | 108 | Beginning with version 2.0 and following the Lua 5.0 trend, all LuaSocket |
107 | functionality is defined inside a table (or rather a namespace) stored with | 109 | functionality is defined inside a tables (or rather a namespaces). No global |
108 | the global name <tt>socket</tt>. To have this table created and its | 110 | variables are ever created. |
109 | contents made available to a Lua script, the interpreter running the script | 111 | Namespaces are obtained with the <tt>require</tt> Lua function, which loads |
110 | must be linked to the LuaSocket library, and to whatever libraries the | 112 | and initializes any required libraries and return the namespace. |
111 | host OS requires for network access (Windows requires ws2_32.lib, for | 113 | For example, the core functionality or LuaSocket is usually available |
112 | instance). LuaSocket is initialized in the | 114 | from the "<tt>socket</tt>" namespace. |
113 | Lua state given as the argument to the function | ||
114 | <tt>luaopen_socket</tt>, the only C function exported by the library. | ||
115 | After initialization, scripts are free to use all of the LuaSocket API. | ||
116 | </p> | 115 | </p> |
117 | 116 | ||
117 | <pre class="example"> | ||
118 | socket = require("socket") | ||
119 | print(socket.VERSION) | ||
120 | -- LuaSocket 2.0 | ||
121 | </pre> | ||
122 | |||
118 | <!-- tcp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 123 | <!-- tcp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
119 | 124 | ||
120 | <h3 id=tcp>TCP</h3> | 125 | <h3 id=tcp>TCP</h3> |
@@ -185,29 +190,25 @@ program. | |||
185 | </p> | 190 | </p> |
186 | 191 | ||
187 | <pre class=example> | 192 | <pre class=example> |
188 | -- create a new TCP object | 193 | -- load namespace |
189 | server, err = socket.tcp() | 194 | local socket = require("socket") |
190 | assert(server, err) | 195 | -- create a TCP socket and bind it to the local host, at any port |
191 | -- bind it to the local host, at any port | 196 | local server = socket.try(socket.bind("*", 0)) |
192 | ret, err = server:bind("*", 0) | ||
193 | assert(ret, err) | ||
194 | -- find out which port the OS chose for us | 197 | -- find out which port the OS chose for us |
195 | ip, port = server:getsockname() | 198 | local ip, port = server:getsockname() |
196 | -- print a message informing what's up | 199 | -- print a message informing what's up |
197 | print("Please telnet to localhost on port " .. port) | 200 | print("Please telnet to localhost on port " .. port) |
198 | print("After connecting, you have 10s to enter a line to be echoed") | 201 | print("After connecting, you have 10s to enter a line to be echoed") |
199 | -- loop forever waiting for clients | 202 | -- loop forever waiting for clients |
200 | while 1 do | 203 | while 1 do |
201 | -- wait for a conection from any client | 204 | -- wait for a conection from any client |
202 | client, err = server:accept() | 205 | local client = server:accept() |
203 | -- make sure we don't block waiting for this client's line | 206 | -- make sure we don't block waiting for this client's line |
204 | client:settimeout(10) | 207 | client:settimeout(10) |
205 | -- receive the line | 208 | -- receive the line |
206 | line, err = client:receive() | 209 | local line, err = client:receive() |
207 | -- if there was no error, send it back to the client | 210 | -- if there was no error, send it back to the client |
208 | if not err then | 211 | if not err then client:send(line .. "\n") end |
209 | client:send(line .. "\n") | ||
210 | end | ||
211 | -- done with client, close the object | 212 | -- done with client, close the object |
212 | client:close() | 213 | client:close() |
213 | end | 214 | end |
@@ -286,21 +287,19 @@ error message. | |||
286 | </p> | 287 | </p> |
287 | 288 | ||
288 | <pre class=example> | 289 | <pre class=example> |
289 | host = "localhost" -- change here to the host you want to contact | 290 | -- change here to the host an port you want to contact |
290 | port = port or 13 | 291 | host = "localhost" |
292 | port = 13 | ||
293 | -- load namespace | ||
294 | local socket = require("socket") | ||
291 | -- convert host name to ip address | 295 | -- convert host name to ip address |
292 | ip, err = socket.dns.toip(host) | 296 | local ip = socket.try(socket.dns.toip(host)) |
293 | assert(ip, err) | ||
294 | -- create a new UDP object | 297 | -- create a new UDP object |
295 | udp = socket.udp() | 298 | local udp = socket.udp() |
296 | -- contact daytime host | 299 | -- contact daytime host |
297 | nsent, err = udp:sendto("anything", ip, port) | 300 | socket.try(udp:sendto("anything", ip, port)) |
298 | assert(not err, err) | 301 | -- retrieve the answer and print results |
299 | -- retrieve the answer | 302 | io.write(socket.try((udp:receive()))) |
300 | dgram, err = udp:receive() | ||
301 | assert(dgram, err) | ||
302 | -- display to user | ||
303 | print(dgram) | ||
304 | </pre> | 303 | </pre> |
305 | </blockquote> | 304 | </blockquote> |
306 | 305 | ||
diff --git a/doc/mime.html b/doc/mime.html index d2fcc3c..286e41c 100644 --- a/doc/mime.html +++ b/doc/mime.html | |||
@@ -44,7 +44,7 @@ MIME is described mainly in | |||
44 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2045.txt">RFC 2045</a>, | 44 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2045.txt">RFC 2045</a>, |
45 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2046.txt">2046</a>, | 45 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2046.txt">2046</a>, |
46 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2047.txt">2047</a>, | 46 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2047.txt">2047</a>, |
47 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2047.txt">2048</a> and | 47 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2047.txt">2048</a>, and |
48 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2048.txt">2049</a>. | 48 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2048.txt">2049</a>. |
49 | </p> | 49 | </p> |
50 | 50 | ||