aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-15 23:00:56 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-15 23:00:56 +0000
commit843a431ef98fd541d98fd3898463985d9bfcde28 (patch)
tree2de4cd78a58ee17aa029528ede8ff5989b819019
parentcb03a0e95429cc0d498e77fd50241c87fd2bf3ea (diff)
downloadluasocket-843a431ef98fd541d98fd3898463985d9bfcde28.tar.gz
luasocket-843a431ef98fd541d98fd3898463985d9bfcde28.tar.bz2
luasocket-843a431ef98fd541d98fd3898463985d9bfcde28.zip
Almost done with manual...
-rw-r--r--doc/dns.html4
-rw-r--r--doc/http.html203
-rw-r--r--doc/index.html77
-rw-r--r--doc/introduction.html75
-rw-r--r--doc/mime.html2
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>
73socket.dns.<b>tohostname()</b> 73socket.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>
94socket.dns.<b>toip()</b> 94socket.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
98in representing them in a Lua table. 98in representing them in a Lua table.
99</p> 99</p>
100 100
101<p>
102The following constants can be set to control the default behaviour of
103the 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>
104socket.http.<b>get(</b>url<b>)</b><br> 116http.<b>get(</b>url<b>)</b><br>
105socket.http.<b>get{</b><br>
106&nbsp;&nbsp;url = <i>string</i>,<br>
107&nbsp;&nbsp;headers = <i>header-table</i>,<br>
108&nbsp;&nbsp;user = <i>string</i>,<br>
109&nbsp;&nbsp;password = <i>string</i>,<br>
110&nbsp;&nbsp;stay = <i>bool</i>,<br>
111<b>}</b>
112</p> 117</p>
113 118
114<p class=description> 119<p class=description>
115Performs the HTTP method <tt>GET</tt>. 120Performs the HTTP method <tt>GET</tt>.
116</p> 121</p>
117 122
118<p class=parameters> 123<p class=parameters>
119The function can be 124<tt>Url</tt> identifies the entity to retrieve.
120called either directly with a <tt>url</tt> or with a <em>request table</em>.
121The use of a request table allows complete control over the components of
122the request. Values passed explicitly as fields of the request table
123override those given by the <tt>url</tt>. For a description of the fields,
124see the <a href=#request><tt>request</tt></a> function.
125</p> 125</p>
126 126
127<p class=return> 127<p class=return>
128The function returns the response message body, the mime headers, the 128If successful, the function returns the response message body, the mime
129status code and an error message (if any). In case of failure, the 129headers, and the status code. In case of failure, the
130function returns all information it managed to gather. 130function 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
140http = 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"
141b, h, c, e = socket.http.get("http://www.tecgraf.puc-rio.br/luasocket/http.html") 144b, 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.
145b, h, c, e = socket.http.get("http://www.tecgraf.puc-rio.br/~diego/auth/index.html") 148b, 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.
152b, h, c, e = socket.http.get("http://wrong.host/") 155r, 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>
159socket.http.<b>post(</b>url, body<b>)</b><br> 162http.<b>post(</b>url, body<b>)</b><br>
160socket.http.<b>post{</b><br>
161&nbsp;&nbsp; url = <i>string</i>,<br>
162&nbsp;&nbsp; headers = <i>header-table</i>,<br>
163&nbsp;&nbsp; body = <i>string</i>,<br>
164&nbsp;&nbsp; user = <i>string</i>,<br>
165&nbsp;&nbsp; password = <i>string</i>,<br>
166&nbsp;&nbsp; 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>
184socket.http.<b>request{</b><br> 179http.<b>request{</b><br>
185&nbsp;&nbsp;method = <i>string</i>,<br>
186&nbsp;&nbsp;url = <i>string</i>,<br> 180&nbsp;&nbsp;url = <i>string</i>,<br>
187&nbsp;&nbsp;headers = <i>header-table</i>,<br> 181&nbsp;&nbsp;[sink = <i>LTN12 sink</i>],]<br>
188&nbsp;&nbsp;body = <i>string</i>,<br> 182&nbsp;&nbsp;[method = <i>string</i>,]<br>
189&nbsp;&nbsp;user = <i>string</i>,<br> 183&nbsp;&nbsp;[headers = <i>header-table</i>,]<br>
190&nbsp;&nbsp;password = <i>string</i>,<br> 184&nbsp;&nbsp;[source = <i>LTN12 source</i>],<br>
191&nbsp;&nbsp;stay = <i>string</i>,<br> 185&nbsp;&nbsp;[step = <i>LTN12 pump step</i>,]<br>
186&nbsp;&nbsp;[proxy = <i>string</i>,]<br>
187&nbsp;&nbsp;[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>
196Performs the generic HTTP request using. 192Performs the generic HTTP request, controled by a request table.
197</p> 193</p>
198 194
199<p class=parameters> 195<p class=parameters>
200The request uses <tt>method</tt> on <tt>url</tt> 196The most important parameters are the <tt>url</tt> and the LTN12
201sending the request <tt>headers</tt> and request <tt>body</tt> in the 197<tt>sink</tt> that will receive the downloaded content.
202request message. If authentication information is provided, the function 198Any part of the <tt>url</tt> can be overriden by including
199the appropriate field in the request table.
200If authentication information is provided, the function
203uses the Basic Authentication Scheme (see <a href="#authentication">note</a>) 201uses the Basic Authentication Scheme (see <a href="#authentication">note</a>)
204to retrieve the document. <tt>User</tt> and <tt>password</tt> provided 202to retrieve the document. If <tt>sink</tt> is <tt><b>nil</b></tt>, the
205explicitly override those given by the <tt>url</tt>. The <tt>stay</tt> 203function discards the downloaded data. The optional parameters are the
206parameter, when set to anything but <b><tt>nil</tt></b>, prevents the function 204following:
207from 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
210is a body, you need to provide an appropriate "<tt>content-length</tt>"
211request 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.
214Defaults 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
217function from automatically following 301 or 302 server redirect messages.
218</ul>
209 219
210<p class=return> 220<p class=return>
211The function returns a table with all components of the response message 221In case of failure, the function returns <tt><b>nil</b></tt> followed by an
212it managed to retrieve. The response table has the following form: 222error message. If successful, the function returns a table
223with 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>
216response = {<br> 227respt = {<br>
217&nbsp;&nbsp;body = <i>string</i>,<br>
218&nbsp;&nbsp;headers = <i>header-table</i>,<br> 228&nbsp;&nbsp;headers = <i>header-table</i>,<br>
219&nbsp;&nbsp;status = <i>string</i>,<br> 229&nbsp;&nbsp;status = <i>string</i>,<br>
220&nbsp;&nbsp;code = <i>number</i>,<br> 230&nbsp;&nbsp;code = <i>number</i>,<br>
221&nbsp;&nbsp;error = <i>string</i><br>
222} 231}
223</tt></blockquote> 232</tt></blockquote>
224 233
225<p class=return> 234<p class=return>
226Even when there was failure (URL not found, for example), the 235Even when there was failure (URL not found, for example), the
227function may succeed retrieving a message body (a web page informing the 236function usually succeeds retrieving a message body (a web page informing the
228URL was not found or some other useless page). To make sure the 237URL was not found or some other useless page). To make sure the
229operation was successful, check the returned status <tt>code</tt>. For 238operation was successful, check the returned status <tt>code</tt>. For
230a list of the possible values and their meanings, refer to <a 239a 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
246http = 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
239response = socket.http.request { 251respt = 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
292http = require("http")
293mime = 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
282response = socket.http.request{ 298respt = 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.
290headers = { 306respt = http.request {
291 authentication = "Basic " .. socket.code.base64("diego:password")
292}
293response = 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>
302socket.http.<b>request_cb(</b>request, response<b>)</b>
303</p>
304
305<p class=description>
306Performs the generic HTTP request.
307</p>
308
309<p class=parameters>
310The function receives two tables as parameters. The <tt>request</tt> table
311provides information about the request:
312</p>
313
314<blockquote><tt>
315request = {<br>
316&nbsp;&nbsp;method = <i>string</i>,<br>
317&nbsp;&nbsp;url = <i>string</i>,<br>
318&nbsp;&nbsp;headers = <i>header-table</i>,<br>
319&nbsp;&nbsp;body_cb = <i>send-callback</i>,<br>
320&nbsp;&nbsp;user = <i>string</i>,<br>
321&nbsp;&nbsp;password = <i>string</i>,<br>
322&nbsp;&nbsp;stay = <i>string</i>,<br>
323}</tt>
324</blockquote>
325
326<p class=parameters>
327The function uses the HTTP method specified in
328<tt>request.method</tt> on the URL <tt>request.url</tt>,
329sending <tt>request.headers</tt> along with the request. The request
330message body is sent via the send callback <tt>request.body_cb</tt>.
331If authentication information is provided, the function uses the Basic
332Authentication Scheme (see <a href="#authentication">note</a>) to
333retrieve 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
336anything but <b><tt>nil</tt></b>, prevents the function from automatically
337following 301 or 302 server redirect messages.
338</p>
339
340<p class=parameters>
341The <tt>response</tt> table specifies information about the desired
342response:
343</p>
344
345<blockquote><tt>
346response = {<br>
347&nbsp;&nbsp;body_cb = <i>receive-callback</i><br>
348}</tt>
349</blockquote>
350
351<p class=return>
352The function returns the same response table as that returned by the
353<tt>socket.http.request</tt> function, except the response message body is
354returned to the receive callback given by the
355<tt>response.body_cb</tt> field.
356</p>
357
358<p class=note>
359Note: 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>
364Note: 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>
48Network support has been implemented so that it is both efficient and 48Network support has been implemented so that it is both efficient and
49simple to use. LuaSocket can be used by any Lua application once it has 49simple to use. LuaSocket can be used by any Lua application once it has
50been properly linked with and initialized by the interpreter running the 50been properly initialized by the interpreter running the
51Lua application. The code has been tested and runs well on several Windows 51Lua application. The code has been tested and runs well on several Windows
52and Unix platforms. 52and Unix platforms.
53</p> 53</p>
@@ -61,7 +61,7 @@ LuaSocket.
61</p> 61</p>
62 62
63<p> 63<p>
64Copyright &copy; 1999-2003 Tecgraf/PUC-Rio. All rights reserved. <br> 64Copyright &copy; 1999-2004 Tecgraf/PUC-Rio. All rights reserved. <br>
65Author: <A href="http://www.cs.princeton.edu/~diego">Diego Nehab</a> 65Author: <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>
73LuaSocket version 2.0 alpha is now available for download! It is 73LuaSocket version 2.0 beta is now available for download! It is
74compatible with Lua&nbsp;5.0 and has been tested on 74compatible with Lua&nbsp;5.0 and has been tested on
75Windows&nbsp;XP, Linux, and Mac OS X. 75Windows&nbsp;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>
115Throughout LuaSocket its history, many people gave sugestions that helped 115Throughout LuaSocket's history, many people gave sugestions that helped
116improve it. For that, I thank the Lua comunity. 116improve it. For that, I thank the Lua comunity.
117Special thanks go to 117Special thanks go to
118David Burgess, who has pushed the library to a new level of quality and 118David Burgess, who has pushed the library to a new level of quality and
119from whom I have learned a lot stuff that doesn't show up in RFCs. 119from whom I have learned a lot of stuff that doesn't show up in RFCs.
120Special thanks also to Carlos Cassino, who played a big part in the 120Special thanks also to Carlos Cassino, who played a big part in the
121extensible design seen in the C core of LuaSocket 2.0. 121extensible 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>
130Most of the changes for 2.0 happened in the C layer, which 130Everything is new! Many changes for 2.0 happened in the C layer, which
131has been almost completely rewritten. The code has been ported to Lua 5.0 131has been almost completely rewritten. The code has been ported to Lua 5.0
132and greatly improved. There have also been some API changes 132and greatly improved. There have also been some API changes
133that made the interface simpler and more consistent. Here are some of 133that 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>
190Lots of changes in the Lua modules, too. The new MIME and LTN12 modules
191make all other modules much more powerful. The main new functionality is
192the 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,
180specially code that relies on global functions. These are no longer 209specially code that relies on global functions. These are no longer
181available. Note that even the support modules (<tt>http</tt>, <tt>smtp</tt> 210available. Note that even the support modules (<tt>http</tt>, <tt>smtp</tt>
182etc) have been moved to the namespace (i.e. <tt>socket.http</tt>, 211etc) 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
214agree 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; 218return 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
192an 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
194programs.
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>
39Communication in LuaSocket is performed via I/O objects. These can 39Communication in LuaSocket is performed via I/O objects. These can
40represent different network domains. Currently, support is 40represent different network domains. Currently, support is provided for TCP
41provided for TCP and UDP, but there is work in progress to implement SSL, 41and UDP, but nothing prevents other developers from implementing SSL, Local
42Local Domain, Pipes, File Descriptors etc. I/O objects provide a standard 42Domain, Pipes, File Descriptors etc. I/O objects provide a standard
43interface to I/O across different domains and operating systems. 43interface to I/O across different domains and operating systems.
44LuaSocket&nbsp;2.0 has been rewritten from scratch to simplify the future 44LuaSocket&nbsp;2.0 has been rewritten from scratch to simplify the future
45addition of new domains. 45addition 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
93I/O objects. To give the library a Lua 5.0 feel, these have been eliminated 93I/O objects. To give the library a Lua 5.0 feel, these have been eliminated
94from LuaSocket 2.0. I/O operations are only available as methods of the 94from LuaSocket 2.0. I/O operations are only available as methods of the
95corresponding I/O objects. Naturally, different I/O objects accept 95corresponding I/O objects. Naturally, different I/O objects accept
96different operations. The core functionality for TCP and UDP objects is 96different operations. The TCP and UDP objects are
97introduced in the following sections, following a few words about 97introduced in the following sections, following a few words about
98initialization. 98initialization.
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>
106The core LuaSocket functionality is implemented in C, and usually available as
107a dynamic library which the interpreter can load when required.
106Beginning with version 2.0 and following the Lua 5.0 trend, all LuaSocket 108Beginning with version 2.0 and following the Lua 5.0 trend, all LuaSocket
107functionality is defined inside a table (or rather a namespace) stored with 109functionality is defined inside a tables (or rather a namespaces). No global
108the global name <tt>socket</tt>. To have this table created and its 110variables are ever created.
109contents made available to a Lua script, the interpreter running the script 111Namespaces are obtained with the <tt>require</tt> Lua function, which loads
110must be linked to the LuaSocket library, and to whatever libraries the 112and initializes any required libraries and return the namespace.
111host OS requires for network access (Windows requires ws2_32.lib, for 113For example, the core functionality or LuaSocket is usually available
112instance). LuaSocket is initialized in the 114from the "<tt>socket</tt>" namespace.
113Lua state given as the argument to the function
114<tt>luaopen_socket</tt>, the only C function exported by the library.
115After initialization, scripts are free to use all of the LuaSocket API.
116</p> 115</p>
117 116
117<pre class="example">
118socket = require("socket")
119print(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
189server, err = socket.tcp() 194local socket = require("socket")
190assert(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 196local server = socket.try(socket.bind("*", 0))
192ret, err = server:bind("*", 0)
193assert(ret, err)
194-- find out which port the OS chose for us 197-- find out which port the OS chose for us
195ip, port = server:getsockname() 198local ip, port = server:getsockname()
196-- print a message informing what's up 199-- print a message informing what's up
197print("Please telnet to localhost on port " .. port) 200print("Please telnet to localhost on port " .. port)
198print("After connecting, you have 10s to enter a line to be echoed") 201print("After connecting, you have 10s to enter a line to be echoed")
199-- loop forever waiting for clients 202-- loop forever waiting for clients
200while 1 do 203while 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()
213end 214end
@@ -286,21 +287,19 @@ error message.
286</p> 287</p>
287 288
288<pre class=example> 289<pre class=example>
289host = "localhost" -- change here to the host you want to contact 290-- change here to the host an port you want to contact
290port = port or 13 291host = "localhost"
292port = 13
293-- load namespace
294local socket = require("socket")
291-- convert host name to ip address 295-- convert host name to ip address
292ip, err = socket.dns.toip(host) 296local ip = socket.try(socket.dns.toip(host))
293assert(ip, err)
294-- create a new UDP object 297-- create a new UDP object
295udp = socket.udp() 298local udp = socket.udp()
296-- contact daytime host 299-- contact daytime host
297nsent, err = udp:sendto("anything", ip, port) 300socket.try(udp:sendto("anything", ip, port))
298assert(not err, err) 301-- retrieve the answer and print results
299-- retrieve the answer 302io.write(socket.try((udp:receive())))
300dgram, err = udp:receive()
301assert(dgram, err)
302-- display to user
303print(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