diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-01-24 02:47:24 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-01-24 02:47:24 +0000 |
commit | 62a4c505e488c714e8795ea85564504562d30301 (patch) | |
tree | f270f53f26905b7275cea172e52ebc269a41c695 | |
parent | 0c9f420a3549df3fb331bb24157b65a3301641d4 (diff) | |
download | luasocket-62a4c505e488c714e8795ea85564504562d30301.tar.gz luasocket-62a4c505e488c714e8795ea85564504562d30301.tar.bz2 luasocket-62a4c505e488c714e8795ea85564504562d30301.zip |
Working on the manual...
Making better tests for error messages.
Changed a few names.
Moved gethostname to inet.c.
-rw-r--r-- | TODO | 6 | ||||
-rw-r--r-- | doc/callback.html | 160 | ||||
-rw-r--r-- | doc/code.html | 2 | ||||
-rw-r--r-- | doc/dns.html | 4 | ||||
-rw-r--r-- | doc/ftp.html | 4 | ||||
-rw-r--r-- | doc/http.html | 4 | ||||
-rw-r--r-- | doc/reference.css | 14 | ||||
-rw-r--r-- | doc/reference.html | 298 | ||||
-rw-r--r-- | doc/smtp.html | 2 | ||||
-rw-r--r-- | doc/stream.html | 8 | ||||
-rw-r--r-- | doc/tcp.html | 22 | ||||
-rw-r--r-- | doc/udp.html | 18 | ||||
-rw-r--r-- | doc/url.html | 2 | ||||
-rw-r--r-- | etc/b64.lua | 11 | ||||
-rw-r--r-- | src/inet.c | 21 | ||||
-rw-r--r-- | src/luasocket.c | 27 | ||||
-rw-r--r-- | src/mime.c | 16 | ||||
-rw-r--r-- | src/mime.lua | 19 | ||||
-rw-r--r-- | test/httptest.lua | 2 | ||||
-rw-r--r-- | test/mimetest.lua | 10 | ||||
-rw-r--r-- | test/testclnt.lua | 4 |
21 files changed, 340 insertions, 314 deletions
@@ -1,4 +1,5 @@ | |||
1 | manual | 1 | manual |
2 | check all occurences of it's | ||
2 | add shutdown | 3 | add shutdown |
3 | add gethostname | 4 | add gethostname |
4 | the need of a content-length header in the post method... | 5 | the need of a content-length header in the post method... |
@@ -22,6 +23,11 @@ tests | |||
22 | checar garbage collection | 23 | checar garbage collection |
23 | check for interrupts | 24 | check for interrupts |
24 | 25 | ||
26 | close has to block... | ||
27 | fmt is not a good name | ||
28 | change wrap() to accept a number and default to "character" | ||
29 | move gethostname to dns table | ||
30 | get rid of _cb in name of functions? | ||
25 | trust character constants in mime.c? noooooo. | 31 | trust character constants in mime.c? noooooo. |
26 | smtp.lua needs stuff filter | 32 | smtp.lua needs stuff filter |
27 | 33 | ||
diff --git a/doc/callback.html b/doc/callback.html index 2c7ecd5..94af8ff 100644 --- a/doc/callback.html +++ b/doc/callback.html | |||
@@ -45,113 +45,72 @@ callback mechanism outlined below. | |||
45 | </p> | 45 | </p> |
46 | 46 | ||
47 | <p> | 47 | <p> |
48 | Instead of returning the entire contents of an entity | 48 | Instead of returning the received contents |
49 | as strings to the Lua application, the library allows the user to | 49 | as a big to the Lua application, the library allows the user to |
50 | provide a <em>receive callback</em> that will be called with successive | 50 | provide a <em>receive callback</em> that will be called with successive |
51 | chunks of data, as the data becomes available. Conversely, the <em>send | 51 | chunks of data, as the data becomes available. Conversely, the <em>send |
52 | callbacks</em> can be used when the application wants to incrementally | 52 | callback</em> mechanism can be used when the application wants to incrementally provide LuaSocket with the data to be sent. |
53 | provide LuaSocket with the data to be sent. | ||
54 | </p> | 53 | </p> |
55 | 54 | ||
56 | <!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 55 | <!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
57 | 56 | ||
58 | <p class=name id=receive_cb> | 57 | <p class=name id=receive> |
59 | ret, err_or_f = <b>receive_cb(</b>chunk, err<b>)</b> | 58 | <b>receive_cb(</b>chunk, err<b>)</b> |
60 | </p> | 59 | </p> |
61 | 60 | ||
62 | <p class=description> | 61 | <p class=description> |
63 | The callback provided by the user will be repeatedly called by the | 62 | A receive callback will be repeatedly called by |
64 | library whenever new data is available. Each time it is called, the | 63 | LuaSocket wheneve new data is available. Each time it is called, the |
65 | callback receives successive chunks of downloaded data. | 64 | callback receives successive chunks of downloaded data. |
66 | </p> | 65 | </p> |
67 | 66 | ||
68 | <p class=parameters> | 67 | <p class=parameters> |
69 | <tt>Chunk</tt> contains the current chunk of data. | 68 | <tt>Chunk</tt> contains the latest downloaded chunk of data. |
70 | When the transmission is over, the function is called with an | 69 | When the transmission is over, the function is called with an |
71 | empty string (i.e. <tt>""</tt>) as the <tt>chunk</tt>. | 70 | empty string (i.e. <tt>""</tt>) in <tt>chunk</tt>. |
72 | If an error occurs, the function receives <tt>nil</tt> | 71 | If an error occurs, the function receives a <b><tt>nil</tt></b> |
73 | as <tt>chunk</tt> and an error message in <tt>err</tt>. | 72 | <tt>chunk</tt> and an error message in <tt>err</tt>. |
74 | </p> | 73 | </p> |
75 | 74 | ||
76 | <p class=return> | 75 | <p class=return> |
77 | The callback can abort transmission by returning <tt>nil</tt> as its first | 76 | The callback can abort transmission by returning <b><tt>nil</tt></b> as its first |
78 | return value, and an optional error message as the | 77 | return value, and an optional error message as the |
79 | second return value. If the application wants to continue receiving | 78 | second return value. To continue receiving |
80 | data, the function should return non-<tt>nil</tt> as it's first return | 79 | data, the function should return non-<b><tt>nil</tt></b> as its first return |
81 | value. In this case, the function can optionally return a | 80 | value. Optionally, in this case, it may return a |
82 | new callback function, to replace itself, as the second return value. | 81 | second return value, with a new callback function to take its place. |
83 | </p> | ||
84 | |||
85 | <p class=note> | ||
86 | Note: The <tt>callback</tt> module provides several standard receive callbacks, including the following: | ||
87 | </p> | ||
88 | |||
89 | <pre class=example> | ||
90 | function receive.concat(concat) | ||
91 | concat = concat or socket.concat.create() | ||
92 | local callback = function(chunk, err) | ||
93 | -- if not finished, add chunk | ||
94 | if chunk and chunk ~= "" then | ||
95 | concat:addstring(chunk) | ||
96 | return 1 | ||
97 | end | ||
98 | end | ||
99 | return callback, concat | ||
100 | end | ||
101 | </pre> | ||
102 | |||
103 | <p class=note> | ||
104 | This function creates a new receive callback that concatenates all | ||
105 | received chunks into a the same concat object, which can later be | ||
106 | queried for its contents. | ||
107 | </p> | 82 | </p> |
108 | 83 | ||
109 | <!-- send_cb ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 84 | <!-- send_cb ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
110 | 85 | ||
111 | <p class=name> | 86 | <p class=name id=send> |
112 | chunk, err_or_r = <b>send_cb()</b> | 87 | <b>send_cb()</b> |
113 | </p> | 88 | </p> |
114 | 89 | ||
115 | <p class=description> | 90 | <p class=description> |
116 | The callback provided by the user will be repeatedly called whenever the | 91 | A send callback will be called whenever LuaSocket |
117 | library needs more data to be sent. | 92 | needs more data to be sent. |
118 | </p> | 93 | </p> |
119 | 94 | ||
120 | <p class=return> | 95 | <p class=return> |
121 | Each time the callback is called, it should return the next chunk of data. It | 96 | Each time the callback is called, it should return the next chunk of data. It |
122 | can optionally return, as it's second return value, a new callback to replace | 97 | can optionally return, as it's second return value, a new callback to replace |
123 | itself. The callback can abort the process at any time by returning | 98 | itself. The callback can abort the process at any time by returning |
124 | <tt>nil</tt> followed by an optional error message. | 99 | <b><tt>nil</tt></b> followed by an optional error message. |
125 | </p> | ||
126 | |||
127 | <p class=note> | ||
128 | Note: Below is the implementation of the <tt>callback.send.file</tt> | ||
129 | function. Given an open file handle, it returns a send callback that will send the contents of that file, chunk by chunk. | ||
130 | </p> | 100 | </p> |
131 | 101 | ||
132 | <pre class=example> | ||
133 | function send.file(file, io_err) | ||
134 | -- if successful, return the callback that reads from the file | ||
135 | if file then | ||
136 | return function() | ||
137 | -- send next block of data | ||
138 | return (file:read(BLOCKSIZE)) or "" | ||
139 | end | ||
140 | -- else, return a callback that just aborts the transfer | ||
141 | else return fail(io_err or "unable to open file") end | ||
142 | end | ||
143 | </pre> | ||
144 | |||
145 | <!-- predefined +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 102 | <!-- predefined +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
146 | 103 | ||
147 | <h2 id=predefined>Predefined Callbacks</h2> | 104 | <h2 id=predefined>Predefined Callbacks</h2> |
148 | 105 | ||
149 | <p> | 106 | <p> |
150 | The module <tt>callback.lua</tt> provides several predefined callbacks to | 107 | The Callback module provides several predefined callbacks to |
151 | perform the most common input/output operations. Callbacks are provided | 108 | perform the most common input/output operations. Callbacks are provided |
152 | that send and receive contents of files and strings. Furthermore, | 109 | that send and receive contents of files and strings. Furthermore, |
153 | composition functions are provided to chain callbacks with filters, such as | 110 | composition functions are provided to chain callbacks with filters, such as |
154 | the filters defined in the <tt>mime.lua</tt> module. | 111 | the filters defined in the <a href=mime.html>MIME</a> module. |
112 | Together, these two modules provide a powerful interface to send and | ||
113 | receive information. | ||
155 | </p> | 114 | </p> |
156 | 115 | ||
157 | <!-- send.file ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 116 | <!-- send.file ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
@@ -161,15 +120,16 @@ the filters defined in the <tt>mime.lua</tt> module. | |||
161 | </p> | 120 | </p> |
162 | 121 | ||
163 | <p class=description> | 122 | <p class=description> |
164 | This function creates a send callback that will return the contents | 123 | This function creates a send callback that returns the contents |
165 | of a the file, until the file has been entirely sent. When done, the | 124 | of a file, chunk by chunk, until the file has been entirely sent. |
166 | callback closes the file. | 125 | When done, the callback closes the file. |
167 | </p> | 126 | </p> |
168 | 127 | ||
169 | <p class=parameters> | 128 | <p class=parameters> |
170 | <tt>File</tt> is a file open for reading. If <tt>file</tt> is | 129 | <tt>File</tt> is a file opened for reading. If <tt>file</tt> is |
171 | <tt>nil</tt>, <tt>io_err</tt> can contain an error message and the | 130 | <b><tt>nil</tt></b>, <tt>io_err</tt> can contain an error message. In this |
172 | returned callback just aborts transmission with the error message. | 131 | case, the function returns a callback that just aborts |
132 | transmission with the error message. | ||
173 | </p> | 133 | </p> |
174 | 134 | ||
175 | <p class=return> | 135 | <p class=return> |
@@ -177,14 +137,14 @@ Returns a send callback for the file. | |||
177 | </p> | 137 | </p> |
178 | 138 | ||
179 | <p class=note> | 139 | <p class=note> |
180 | Note: The function is designed so that it directly accepts the return | 140 | Note: This function is designed so that it directly accepts the return |
181 | values of the <tt>io.open</tt> function. | 141 | values of the <tt>io.open</tt> function. |
182 | </p> | 142 | </p> |
183 | 143 | ||
184 | <!-- send.string ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 144 | <!-- send.string ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
185 | 145 | ||
186 | <p class=name id=send.string> | 146 | <p class=name id=send.string> |
187 | <b>send.string(</b>str<b>)</b> | 147 | <b>send.string(</b>str, err<b>)</b> |
188 | </p> | 148 | </p> |
189 | 149 | ||
190 | <p class=description> | 150 | <p class=description> |
@@ -193,29 +153,33 @@ the contents of a string. | |||
193 | </p> | 153 | </p> |
194 | 154 | ||
195 | <p class=parameters> | 155 | <p class=parameters> |
196 | <tt>Str</tt> is the string to be sent. | 156 | <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 | --> | ||
197 | </p> | 161 | </p> |
198 | 162 | ||
199 | <p class=return> | 163 | <p class=return> |
200 | Returns a send callback for the string, or <tt>nil</tt> if the string is | 164 | Returns a send callback for the string, or <b><tt>nil</tt></b> if the string is |
201 | <tt>nil</tt>. | 165 | <b><tt>nil</tt></b>. |
202 | </p> | 166 | </p> |
203 | 167 | ||
204 | <p class=note> | 168 | <p class=note> |
205 | Note: If any function in the LuaSocket API receives a <tt>nil</tt> | 169 | Note: A <tt>nil</tt></b> |
206 | send callback, it assumes there is nothing to be sent. | 170 | send callback is equivalent to a callback that returns the empty string. |
207 | </p> | 171 | </p> |
208 | 172 | ||
209 | <!-- send.chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 173 | <!-- send.chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
210 | 174 | ||
211 | <p class=name id=send.string> | 175 | <p class=name id=send.chain> |
212 | <b>send.chain(</b>send_cb, filter<b>)</b> | 176 | <b>send.chain(</b>send_cb, filter<b>)</b> |
213 | </p> | 177 | </p> |
214 | 178 | ||
215 | <p class=description> | 179 | <p class=description> |
216 | This function creates a send callback that will send | 180 | This function creates a send callback that will filter |
217 | all data that it gets from another callback, | 181 | all the data it receives from another send callback, before |
218 | after passing the data through a filter. | 182 | sending it through. |
219 | </p> | 183 | </p> |
220 | 184 | ||
221 | <p class=parameters> | 185 | <p class=parameters> |
@@ -226,7 +190,29 @@ after passing the data through a filter. | |||
226 | Returns a callback chained with the filter. | 190 | Returns a callback chained with the filter. |
227 | </p> | 191 | </p> |
228 | 192 | ||
229 | (write a note!) | 193 | <p class=note> |
194 | Note: Several filters are defined in the <a href=mime.html>MIME</a> | ||
195 | module. Below is an example that creates a send callback that sends | ||
196 | a file's contents encoded in the Base64 transfer content encoding. | ||
197 | </p> | ||
198 | |||
199 | <pre class=example> | ||
200 | send_cb = socket.callback.send.chain( | ||
201 | socket.callback.send.file(io.open("input.bin")) | ||
202 | socket.mime.chain( | ||
203 | socket.mime.encode("base64"), | ||
204 | socket.mime.wrap("base64") | ||
205 | ) | ||
206 | ) | ||
207 | </pre> | ||
208 | |||
209 | <p class=note> | ||
210 | The call to <a href=mime.html#chain><tt>socket.mime.chain</tt></a> | ||
211 | 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 | ||
213 | send callback that reads the file from disk and passes it through the | ||
214 | filter before sending it. | ||
215 | </p> | ||
230 | 216 | ||
231 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 217 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
232 | 218 | ||
diff --git a/doc/code.html b/doc/code.html index 45fd21a..4668b7a 100644 --- a/doc/code.html +++ b/doc/code.html | |||
@@ -59,7 +59,7 @@ Applies the Base 64 content coding to a string. | |||
59 | <p class=parameters> | 59 | <p class=parameters> |
60 | <tt>Content</tt> is the string to be encoded. | 60 | <tt>Content</tt> is the string to be encoded. |
61 | If <tt>single</tt> is set to anything | 61 | If <tt>single</tt> is set to anything |
62 | but <tt>nil</tt>, the output is returned as a single | 62 | but <b><tt>nil</tt></b>, the output is returned as a single |
63 | line, otherwise the function splits the content into 76 character long | 63 | line, otherwise the function splits the content into 76 character long |
64 | lines after encoding. | 64 | lines after encoding. |
65 | </p> | 65 | </p> |
diff --git a/doc/dns.html b/doc/dns.html index 6abf341..17cee45 100644 --- a/doc/dns.html +++ b/doc/dns.html | |||
@@ -70,7 +70,7 @@ Converts from IP address to host name. | |||
70 | <p class=return> | 70 | <p class=return> |
71 | The function a string with the canonic host name of the given | 71 | The function a string with the canonic host name of the given |
72 | <tt>address</tt>, followed by a table with all information returned by | 72 | <tt>address</tt>, followed by a table with all information returned by |
73 | the resolver. In case of error, the function returns <tt>nil</tt> | 73 | the resolver. In case of error, the function returns <b><tt>nil</tt></b> |
74 | followed by an error message. | 74 | followed by an error message. |
75 | </p> | 75 | </p> |
76 | 76 | ||
@@ -92,7 +92,7 @@ Converts from host name to IP address. | |||
92 | <p class=return> | 92 | <p class=return> |
93 | Returns a string with the first IP address found for <tt>address</tt>, | 93 | Returns a string with the first IP address found for <tt>address</tt>, |
94 | followed by a table with all information returned by the resolver. | 94 | followed by a table with all information returned by the resolver. |
95 | In case of error, the function returns <tt>nil</tt> followed by an error | 95 | In case of error, the function returns <b><tt>nil</tt></b> followed by an error |
96 | message. | 96 | message. |
97 | </p> | 97 | </p> |
98 | 98 | ||
diff --git a/doc/ftp.html b/doc/ftp.html index 8072afe..6776a17 100644 --- a/doc/ftp.html +++ b/doc/ftp.html | |||
@@ -88,7 +88,7 @@ determines the transfer type. If <tt><path></tt> ends with a | |||
88 | <p class=return> | 88 | <p class=return> |
89 | If successful, the function returns | 89 | If successful, the function returns |
90 | the file content as a string. In case of error, the function returns | 90 | the file content as a string. In case of error, the function returns |
91 | <tt>nil</tt> and an error message describing the error. | 91 | <b><tt>nil</tt></b> and an error message describing the error. |
92 | </p> | 92 | </p> |
93 | 93 | ||
94 | <pre class=example> | 94 | <pre class=example> |
@@ -165,7 +165,7 @@ function tries to log in as '<tt>anonymous</tt>'. | |||
165 | 165 | ||
166 | <p class=return> | 166 | <p class=return> |
167 | If successful, the function returns 1. In case of error, the | 167 | If successful, the function returns 1. In case of error, the |
168 | function returns <tt>nil</tt> followed by a string describing the error. | 168 | function returns <b><tt>nil</tt></b> followed by a string describing the error. |
169 | </p> | 169 | </p> |
170 | 170 | ||
171 | <pre class=example> | 171 | <pre class=example> |
diff --git a/doc/http.html b/doc/http.html index b7469a4..f977ea9 100644 --- a/doc/http.html +++ b/doc/http.html | |||
@@ -203,7 +203,7 @@ request message. If authentication information is provided, the function | |||
203 | uses the Basic Authentication Scheme (see <a href="#authentication">note</a>) | 203 | uses the Basic Authentication Scheme (see <a href="#authentication">note</a>) |
204 | to retrieve the document. <tt>User</tt> and <tt>password</tt> provided | 204 | to retrieve the document. <tt>User</tt> and <tt>password</tt> provided |
205 | explicitly override those given by the <tt>url</tt>. The <tt>stay</tt> | 205 | explicitly override those given by the <tt>url</tt>. The <tt>stay</tt> |
206 | parameter, when set to anything but <tt>nil</tt>, prevents the function | 206 | parameter, when set to anything but <b><tt>nil</tt></b>, prevents the function |
207 | from automatically following 301 or 302 server redirect messages. | 207 | from automatically following 301 or 302 server redirect messages. |
208 | </p> | 208 | </p> |
209 | 209 | ||
@@ -333,7 +333,7 @@ Authentication Scheme (see <a href="#authentication">note</a>) to | |||
333 | retrieve the document. <tt>Request.user</tt> and | 333 | retrieve the document. <tt>Request.user</tt> and |
334 | <tt>request.password</tt> override those given by the | 334 | <tt>request.password</tt> override those given by the |
335 | <tt>request.url</tt>. The <tt>request.stay</tt> parameter, when set to | 335 | <tt>request.url</tt>. The <tt>request.stay</tt> parameter, when set to |
336 | anything but <tt>nil</tt>, prevents the function from automatically | 336 | anything but <b><tt>nil</tt></b>, prevents the function from automatically |
337 | following 301 or 302 server redirect messages. | 337 | following 301 or 302 server redirect messages. |
338 | </p> | 338 | </p> |
339 | 339 | ||
diff --git a/doc/reference.css b/doc/reference.css index 2a8987e..607ac4f 100644 --- a/doc/reference.css +++ b/doc/reference.css | |||
@@ -1,11 +1,19 @@ | |||
1 | body { margin-left: 1em; margin-right: 1em; } | 1 | body { |
2 | margin-left: 1em; | ||
3 | margin-right: 1em; | ||
4 | font-family: "Verdana"; | ||
5 | } | ||
6 | |||
7 | tt { | ||
8 | font-family: "Andale Mono", monospace; | ||
9 | } | ||
2 | 10 | ||
3 | h1, h2, h3, h4 { margin-left: 0em; } | 11 | h1, h2, h3, h4 { margin-left: 0em; } |
4 | 12 | ||
5 | p { margin-left: 1em; } | 13 | p { margin-left: 1em; } |
6 | 14 | ||
7 | p.name { | 15 | p.name { |
8 | font-family: monospace; | 16 | font-family: "Andale Mono", monospace; |
9 | padding-top: 1em; | 17 | padding-top: 1em; |
10 | margin-left: 0em; | 18 | margin-left: 0em; |
11 | } | 19 | } |
@@ -18,6 +26,8 @@ pre.example { | |||
18 | background: #ccc; | 26 | background: #ccc; |
19 | padding: 1em; | 27 | padding: 1em; |
20 | margin-left: 1em; | 28 | margin-left: 1em; |
29 | font-family: "Andale Mono", monospace; | ||
30 | font-size: small; | ||
21 | } | 31 | } |
22 | 32 | ||
23 | hr { | 33 | hr { |
diff --git a/doc/reference.html b/doc/reference.html index 99b1ea7..0bfd378 100644 --- a/doc/reference.html +++ b/doc/reference.html | |||
@@ -35,155 +35,173 @@ | |||
35 | 35 | ||
36 | <h2>Reference</h2> | 36 | <h2>Reference</h2> |
37 | 37 | ||
38 | <!-- tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 38 | <!-- callback +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
39 | 39 | ||
40 | <table summary="TCP Index" class=index width=100%> | 40 | <blockquote> |
41 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | 41 | <a href="callback.html">Callbacks (socket.callback)</a> |
42 | <tr> | 42 | <blockquote> |
43 | <td><ul> | 43 | <a href="callback.html#send">send</a>: |
44 | <li><a href="tcp.html">TCP (socket.tcp)</a> | 44 | <a href="callback.html#send.chain">chain</a>, |
45 | <ul> | 45 | <a href="callback.html#send.file">file</a>, |
46 | <li><a href="tcp.html#accept">accept</a> | 46 | <a href="callback.html#send.string">string</a>. |
47 | <li><a href="tcp.html#bind">bind</a> | 47 | </blockquote> |
48 | <li><a href="tcp.html#close">close</a> | 48 | <blockquote> |
49 | <li><a href="tcp.html#connect">connect</a> | 49 | <a href="callback.html#receive">receive</a>: |
50 | <li><a href="tcp.html#getpeername">getpeername</a> | 50 | <a href="callback.html#receive.chain">chain</a>, |
51 | </ul> | 51 | <a href="callback.html#receive.file">file</a>, |
52 | </ul></td> | 52 | <a href="callback.html#receive.concat">concat</a>. |
53 | <td valign=top><ul> | 53 | </blockquote> |
54 | <li><a href="tcp.html#getsockname">getsockname</a> | 54 | </blockquote> |
55 | <li><a href="tcp.html#receive">receive</a> | ||
56 | <li><a href="tcp.html#send">send</a> | ||
57 | <li><a href="tcp.html#setoption">setoption</a> | ||
58 | <li><a href="tcp.html#settimeout">settimeout</a> | ||
59 | </ul></td> | ||
60 | </tr> | ||
61 | </table> | 55 | </table> |
62 | 56 | ||
63 | <hr> | 57 | <!-- dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
64 | 58 | ||
65 | <!-- udp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 59 | <blockquote> |
66 | 60 | <a href="dns.html">DNS services (socket.dns)</a> | |
67 | <table summary="UDP Index" class=index width=100%> | 61 | <blockquote> |
68 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | 62 | <a href="dns.html#toip">toip</a>, |
69 | <tr> | 63 | <a href="dns.html#tohostname">tohostname</a>, |
70 | <td><ul> | 64 | <a href="dns.html#gethostname">gethostname</a>. |
71 | <li><a href="udp.html">UDP (socket.udp)</a> | 65 | </blockquote> |
72 | <ul> | 66 | </blockquote> |
73 | <li><a href="udp.html#close">close</a> | 67 | |
74 | <li><a href="udp.html#getpeername">getpeername</a> | 68 | <!-- ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
75 | <li><a href="udp.html#getsockname">getsockname</a> | 69 | |
76 | <li><a href="udp.html#receive">receive</a> | 70 | <blockquote> |
77 | <li><a href="udp.html#receivefrom">receivefrom</a> | 71 | <a href="ftp.html">FTP (socket.ftp)</a> |
78 | </ul> | 72 | <blockquote> |
79 | </ul></td> | 73 | <a href="ftp.html#get">get</a>, |
80 | <td><ul> | 74 | <a href="ftp.html#get_cb">get_cb</a>, |
81 | <li><a href="udp.html#send">send</a> | 75 | <a href="ftp.html#put">put</a>, |
82 | <li><a href="udp.html#sendto">sendto</a> | 76 | <a href="ftp.html#put_cb">put_cb</a>. |
83 | <li><a href="udp.html#setpeername">setpeername</a> | 77 | </blockquote> |
84 | <li><a href="udp.html#setsockname">setsockname</a> | 78 | </blockquote> |
85 | <li><a href="udp.html#setoption">setoption</a> | 79 | |
86 | <li><a href="udp.html#settimeout">settimeout</a> | 80 | <!-- misc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
87 | </ul></td> | 81 | |
88 | </tr> | 82 | <blockquote> |
89 | </table> | 83 | <a href="global.html">Globals (socket)</a> |
90 | 84 | <blockquote> | |
91 | <hr> | 85 | <a href="global.html#bind">bind</a>, |
92 | 86 | <a href="global.html#callback">callback</a>, | |
93 | <!-- http & ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 87 | <a href="global.html#concat">concat</a>, |
94 | 88 | <a href="global.html#connect">connect</a>, | |
95 | <table summary="HTTP and FTP Index" class=index width=100%> | 89 | <a href="global.html#debug">debug</a>, |
96 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | 90 | <a href="global.html#dns">dns</a>, |
97 | <tr> | 91 | <a href="global.html#ftp">ftp</a>, |
98 | <td valign=top><ul> | 92 | <a href="global.html#http">http</a>, |
99 | <li><a href="http.html">HTTP (socket.http)</a> | 93 | <a href="global.html#mime">mime</a>, |
100 | <ul> | 94 | <a href="global.html#select">select</a>, |
101 | <li><a href="http.html#get">get</a> | 95 | <a href="global.html#sleep">sleep</a>, |
102 | <li><a href="http.html#post">post</a> | 96 | <a href="global.html#smtp">smtp</a>, |
103 | <li><a href="http.html#request">request</a> | 97 | <a href="global.html#time">time</a>, |
104 | <li><a href="http.html#request_cb">request_cb</a> | 98 | <a href="global.html#tcp">tcp</a>. |
105 | </ul> | 99 | <a href="global.html#udp">udp</a>, |
106 | </ul></td> | 100 | <a href="global.html#url">url</a>, |
107 | <td valign=top><ul> | 101 | <a href="global.html#version">version</a>. |
108 | <li><a href="ftp.html">FTP (socket.ftp)</a> | 102 | </blockquote> |
109 | <ul> | 103 | </blockquote> |
110 | <li><a href="ftp.html#get">get</a> | ||
111 | <li><a href="ftp.html#get_cb">get_cb</a> | ||
112 | <li><a href="ftp.html#put">put</a> | ||
113 | <li><a href="ftp.html#put_cb">put_cb</a> | ||
114 | </ul> | ||
115 | </ul></td> | ||
116 | </tr> | ||
117 | </table> | 104 | </table> |
118 | 105 | ||
119 | <hr> | ||
120 | 106 | ||
121 | <!-- http & ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 107 | <!-- http +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
122 | 108 | ||
123 | <table summary="Streaming Index" class=index width=100%> | 109 | <blockquote> |
124 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | 110 | <a href="http.html">HTTP (socket.http)</a> |
125 | <tr><td valign=top><ul> | 111 | <blockquote> |
126 | <li><a href="stream.html">Streaming with Callbacks</a> | 112 | <a href="http.html#get">get</a>, |
127 | <ul> | 113 | <a href="http.html#post">post</a>, |
128 | <li><a href="stream.html#receive_cb">receive_cb</a> | 114 | <a href="http.html#request">request</a>, |
129 | <li><a href="stream.html#send_cb">send_cb</a> | 115 | <a href="http.html#request_cb">request_cb</a>. |
130 | </ul> | 116 | </blockquote> |
131 | </ul></td></tr> | 117 | </blockquote> |
132 | </table> | 118 | |
119 | <!-- mime +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
120 | |||
121 | <blockquote> | ||
122 | <a href="mime.html">MIME (socket.mime) </a> | ||
123 | <blockquote> | ||
124 | <a href="mime.html#filters">filters</a>: | ||
125 | <a href="mime.html#decode">canonic</a>, | ||
126 | <a href="mime.html#chain">chain</a>, | ||
127 | <a href="mime.html#decode">decode</a>, | ||
128 | <a href="mime.html#encode">encode</a>, | ||
129 | <a href="mime.html#wrap">wrap</a>. | ||
130 | </blockquote> | ||
131 | <blockquote> | ||
132 | <a href="mime.html#low-level">low-level</a>: | ||
133 | <a href="mime.html#b64">b64</a>, | ||
134 | <a href="mime.html#unb64">unb64</a>, | ||
135 | <a href="mime.html#eol">eol</a>, | ||
136 | <a href="mime.html#qp">qp</a>, | ||
137 | <a href="mime.html#unqp">unqp</a>, | ||
138 | <a href="mime.html#wrp">wrp</a>, | ||
139 | <a href="mime.html#qpwrp">qpwrp</a>. | ||
140 | </blockquote> | ||
141 | </blockquote> | ||
142 | |||
143 | <!-- smtp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
144 | |||
145 | <blockquote> | ||
146 | <a href="smtp.html">SMTP (socket.smtp)</a> | ||
147 | <blockquote> | ||
148 | <a href="smtp.html#mail">mail</a> | ||
149 | </blockquote> | ||
150 | </blockquote> | ||
133 | 151 | ||
134 | <hr> | 152 | <!-- tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
135 | 153 | ||
136 | <!-- smtp & dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 154 | <blockquote> |
137 | 155 | <a href="tcp.html">TCP (socket.tcp)</a> | |
138 | <table summary="SMTP and DNS Index" class=index width=100%> | 156 | <blockquote> |
139 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | 157 | <a href="tcp.html#accept">accept</a>, |
140 | <tr> | 158 | <a href="tcp.html#bind">bind</a>, |
141 | <td><ul> | 159 | <a href="tcp.html#close">close</a>, |
142 | <li><a href="smtp.html">SMTP (socket.smtp)</a> | 160 | <a href="tcp.html#connect">connect</a>, |
143 | <ul> | 161 | <a href="tcp.html#getpeername">getpeername</a>, |
144 | <li> <a href="smtp.html#mail">mail</a> | 162 | <a href="tcp.html#getsockname">getsockname</a>, |
145 | </ul> | 163 | <a href="tcp.html#receive">receive</a>, |
146 | </ul></td> | 164 | <a href="tcp.html#send">send</a>, |
147 | <td><ul> | 165 | <a href="tcp.html#setoption">setoption</a>, |
148 | <li><a href="dns.html">DNS services (socket.dns)</a> | 166 | <a href="tcp.html#settimeout">settimeout</a>, |
149 | <ul> | 167 | <a href="tcp.html#shutdown">shutdown</a>. |
150 | <li><a href="dns.html#toip">toip</a> | 168 | </blockquote> |
151 | <li><a href="dns.html#tohostname">tohostname</a> | 169 | </blockquote> |
152 | </ul> | ||
153 | </ul></td> | ||
154 | </tr> | ||
155 | </table> | ||
156 | 170 | ||
157 | <hr> | 171 | <!-- udp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
158 | 172 | ||
159 | <!-- url & code ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 173 | <blockquote> |
160 | 174 | <a href="udp.html">UDP (socket.udp)</a> | |
161 | <table summary="URL and Code Index" class=index width=100%> | 175 | <blockquote> |
162 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | 176 | <a href="udp.html#close">close</a>, |
163 | <tr> | 177 | <a href="udp.html#getpeername">getpeername</a>, |
164 | <td valign=top><ul> | 178 | <a href="udp.html#getsockname">getsockname</a>, |
165 | <li><a href="url.html">URL (socket.url) </a> | 179 | <a href="udp.html#receive">receive</a>, |
166 | <ul> | 180 | <a href="udp.html#receivefrom">receivefrom</a>, |
167 | <li> <a href="url.html#absolute">absolute</a> | 181 | <a href="udp.html#send">send</a>, |
168 | <li> <a href="url.html#build">build</a> | 182 | <a href="udp.html#sendto">sendto</a>, |
169 | <li> <a href="url.html#build_path">build_path</a> | 183 | <a href="udp.html#setpeername">setpeername</a>, |
170 | <li> <a href="url.html#parse">parse</a> | 184 | <a href="udp.html#setsockname">setsockname</a>, |
171 | <li> <a href="url.html#parse_path">parse_path</a> | 185 | <a href="udp.html#setoption">setoption</a>, |
172 | </ul> | 186 | <a href="udp.html#settimeout">settimeout</a>, |
173 | </ul></td> | 187 | <a href="udp.html#settimeout">shutdown</a>. |
174 | <td valign=top><ul> | 188 | </blockquote> |
175 | <li> <a href="code.html">Code (socket.code) </a> | 189 | </blockquote> |
176 | <ul> | 190 | |
177 | <li> <a href="code.html#base64">base64</a> | 191 | <!-- url ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
178 | <li> <a href="code.html#unbase64">unbase64</a> | 192 | |
179 | <li> <a href="code.html#escape">escape</a> | 193 | <blockquote> |
180 | <li> <a href="code.html#unescape">unescape</a> | 194 | <a href="url.html">URL (socket.url) </a> |
181 | <li> <a href="code.html#hexa">hexa</a> | 195 | <blockquote> |
182 | <li> <a href="code.html#unhexa">unhexa</a> | 196 | <a href="url.html#absolute">absolute</a>, |
183 | </ul> | 197 | <a href="url.html#build">build</a>, |
184 | </ul></td> | 198 | <a href="url.html#build_path">build_path</a>, |
185 | </tr> | 199 | <a href="url.html#quote">quote</a>, |
186 | </table> | 200 | <a href="url.html#parse">parse</a>, |
201 | <a href="url.html#parse_path">parse_path</a>, | ||
202 | <a href="url.html#quote">unquote</a>. | ||
203 | </blockquote> | ||
204 | </blockquote> | ||
187 | 205 | ||
188 | <!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 206 | <!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
189 | 207 | ||
diff --git a/doc/smtp.html b/doc/smtp.html index aa92149..0862de0 100644 --- a/doc/smtp.html +++ b/doc/smtp.html | |||
@@ -105,7 +105,7 @@ and text <tt>body</tt>. The message is sent using the server | |||
105 | 105 | ||
106 | <p class=return> | 106 | <p class=return> |
107 | If successful, the function returns 1. Otherwise, the function returns | 107 | If successful, the function returns 1. Otherwise, the function returns |
108 | <tt>nil</tt> followed by an error message. | 108 | <b><tt>nil</tt></b> followed by an error message. |
109 | </p> | 109 | </p> |
110 | 110 | ||
111 | <p class=note> | 111 | <p class=note> |
diff --git a/doc/stream.html b/doc/stream.html index b88cbb5..585ad18 100644 --- a/doc/stream.html +++ b/doc/stream.html | |||
@@ -69,15 +69,15 @@ callback receives successive chunks of downloaded data. | |||
69 | <tt>Chunk</tt> contains the current chunk of data. | 69 | <tt>Chunk</tt> contains the current chunk of data. |
70 | When the transmission is over, the function is called with an | 70 | When the transmission is over, the function is called with an |
71 | empty string (i.e. <tt>""</tt>) as the <tt>chunk</tt>. | 71 | empty string (i.e. <tt>""</tt>) as the <tt>chunk</tt>. |
72 | If an error occurs, the function receives <tt>nil</tt> | 72 | If an error occurs, the function receives <b><tt>nil</tt></b> |
73 | as <tt>chunk</tt> and an error message in <tt>err</tt>. | 73 | as <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> |
77 | The callback can abort transmission by returning <tt>nil</tt> as its first | 77 | The callback can abort transmission by returning <b><tt>nil</tt></b> as its first |
78 | return value, and an optional error message as the | 78 | return value, and an optional error message as the |
79 | second return value. If the application wants to continue receiving | 79 | second return value. If the application wants to continue receiving |
80 | data, the function should return non-<tt>nil</tt> as it's first return | 80 | data, the function should return non-<b><tt>nil</tt></b> as it's first return |
81 | value. In this case, the function can optionally return a | 81 | value. In this case, the function can optionally return a |
82 | new callback function, to replace itself, as the second return value. | 82 | new callback function, to replace itself, as the second return value. |
83 | </p> | 83 | </p> |
@@ -121,7 +121,7 @@ library needs more data to be sent. | |||
121 | Each time the callback is called, it should return the next chunk of data. It | 121 | Each time the callback is called, it should return the next chunk of data. It |
122 | can optionally return, as it's second return value, a new callback to replace | 122 | can optionally return, as it's second return value, a new callback to replace |
123 | itself. The callback can abort the process at any time by returning | 123 | itself. The callback can abort the process at any time by returning |
124 | <tt>nil</tt> followed by an optional error message. | 124 | <b><tt>nil</tt></b> followed by an optional error message. |
125 | </p> | 125 | </p> |
126 | 126 | ||
127 | <p class=note> | 127 | <p class=note> |
diff --git a/doc/tcp.html b/doc/tcp.html index 0be535a..eb4cdfa 100644 --- a/doc/tcp.html +++ b/doc/tcp.html | |||
@@ -51,7 +51,7 @@ method.</p> | |||
51 | 51 | ||
52 | <p class=return> | 52 | <p class=return> |
53 | In case of success, a new master object is returned. In case of error, | 53 | In case of success, a new master object is returned. In case of error, |
54 | <tt>nil</tt> is returned, followed by an error message. | 54 | <b><tt>nil</tt></b> is returned, followed by an error message. |
55 | </p> | 55 | </p> |
56 | 56 | ||
57 | <!-- accept +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 57 | <!-- accept +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
@@ -67,7 +67,7 @@ object and returns a client object representing that connection. | |||
67 | 67 | ||
68 | <p class=return> | 68 | <p class=return> |
69 | If a connection is successfully initiated, a client object is returned. | 69 | If a connection is successfully initiated, a client object is returned. |
70 | If a timeout condition is met, the method returns <tt>nil</tt> followed | 70 | If a timeout condition is met, the method returns <b><tt>nil</tt></b> followed |
71 | by the error string '<tt>timeout</tt>'. | 71 | by the error string '<tt>timeout</tt>'. |
72 | </p> | 72 | </p> |
73 | 73 | ||
@@ -111,7 +111,7 @@ attempts connection, the connection is refused. | |||
111 | 111 | ||
112 | <p class=return> | 112 | <p class=return> |
113 | In case of success, the method returns 1. In case of error, the | 113 | In case of success, the method returns 1. In case of error, the |
114 | method returns <tt>nil</tt> followed by an error message. | 114 | method returns <b><tt>nil</tt></b> followed by an error message. |
115 | </p> | 115 | </p> |
116 | 116 | ||
117 | <p class=note> | 117 | <p class=note> |
@@ -165,7 +165,7 @@ and <a href=#close><tt>close</tt></a>. | |||
165 | </p> | 165 | </p> |
166 | 166 | ||
167 | <p class=return> | 167 | <p class=return> |
168 | In case of error, the method returns <tt>nil</tt> followed by a string | 168 | In case of error, the method returns <b><tt>nil</tt></b> followed by a string |
169 | describing the error. In case of success, the method returns 1. | 169 | describing the error. In case of success, the method returns 1. |
170 | </p> | 170 | </p> |
171 | 171 | ||
@@ -187,7 +187,7 @@ Returns information about the remote side of a connected client object. | |||
187 | <p class=return> | 187 | <p class=return> |
188 | Returns a string with the IP address of the peer, followed by the | 188 | Returns a string with the IP address of the peer, followed by the |
189 | port number that peer is using for the connection. | 189 | port number that peer is using for the connection. |
190 | In case of error, the method returns <tt>nil</tt>. | 190 | In case of error, the method returns <b><tt>nil</tt></b>. |
191 | </p> | 191 | </p> |
192 | 192 | ||
193 | <p class=note> | 193 | <p class=note> |
@@ -207,7 +207,7 @@ Returns the local address information associated to the object. | |||
207 | 207 | ||
208 | <p class=return> | 208 | <p class=return> |
209 | The method returns a string with local IP address and a number with | 209 | The method returns a string with local IP address and a number with |
210 | the port. In case of error, the method returns <tt>nil</tt>. | 210 | the port. In case of error, the method returns <b><tt>nil</tt></b>. |
211 | </p> | 211 | </p> |
212 | 212 | ||
213 | <p class=note> | 213 | <p class=note> |
@@ -248,7 +248,7 @@ bytes from the socket. | |||
248 | 248 | ||
249 | <p class=return> | 249 | <p class=return> |
250 | The method returns one value for each pattern, followed by a single | 250 | The method returns one value for each pattern, followed by a single |
251 | error code that can be <tt>nil</tt> in case of success, the string | 251 | error code that can be <b><tt>nil</tt></b> in case of success, the string |
252 | '<tt>closed</tt>' in case the connection was closed before the | 252 | '<tt>closed</tt>' in case the connection was closed before the |
253 | transmission was completed or the string '<tt>timeout</tt>' in case | 253 | transmission was completed or the string '<tt>timeout</tt>' in case |
254 | there was a timeout during the operation. | 254 | there was a timeout during the operation. |
@@ -278,7 +278,7 @@ result to LuaSocket instead of passing several independent strings. | |||
278 | 278 | ||
279 | <p class=return> | 279 | <p class=return> |
280 | The method returns the number of bytes accepted by the transport layer, | 280 | The method returns the number of bytes accepted by the transport layer, |
281 | followed by an error code. The error code is <tt>nil</tt> if the operation | 281 | followed by an error code. The error code is <b><tt>nil</tt></b> if the operation |
282 | completed with no errors, the string '<tt>closed</tt>' in case | 282 | completed with no errors, the string '<tt>closed</tt>' in case |
283 | the connection was closed before the transmission was completed or the | 283 | the connection was closed before the transmission was completed or the |
284 | string '<tt>timeout</tt>' in case there was a timeout during the | 284 | string '<tt>timeout</tt>' in case there was a timeout during the |
@@ -288,7 +288,7 @@ operation. | |||
288 | <p class=note> | 288 | <p class=note> |
289 | Note: The return values for the <tt>send</tt> method have been changed in | 289 | Note: The return values for the <tt>send</tt> method have been changed in |
290 | LuaSocket 2.0! In previous versions, the method returned only the | 290 | LuaSocket 2.0! In previous versions, the method returned only the |
291 | error message. Since returning <tt>nil</tt> in case of success goes | 291 | error message. Since returning <b><tt>nil</tt></b> in case of success goes |
292 | against all other LuaSocket methods and functions, the | 292 | against all other LuaSocket methods and functions, the |
293 | <tt>send</tt> method been changed for the sake of uniformity. | 293 | <tt>send</tt> method been changed for the sake of uniformity. |
294 | </p> | 294 | </p> |
@@ -330,7 +330,7 @@ considered broken and processes using the socket are notified. | |||
330 | </ul> | 330 | </ul> |
331 | 331 | ||
332 | <p class=return> | 332 | <p class=return> |
333 | The method returns 1 in case of success, or <tt>nil</tt> otherwise. | 333 | The method returns 1 in case of success, or <b><tt>nil</tt></b> otherwise. |
334 | </p> | 334 | </p> |
335 | 335 | ||
336 | <p class=note> | 336 | <p class=note> |
@@ -374,7 +374,7 @@ a call.</li> | |||
374 | </ul> | 374 | </ul> |
375 | 375 | ||
376 | <p class=parameters> | 376 | <p class=parameters> |
377 | The <tt>nil</tt> timeout <tt>value</tt> allows operations to block | 377 | The <b><tt>nil</tt></b> timeout <tt>value</tt> allows operations to block |
378 | indefinitely. Negative timeout values have the same effect. | 378 | indefinitely. Negative timeout values have the same effect. |
379 | </p> | 379 | </p> |
380 | 380 | ||
diff --git a/doc/udp.html b/doc/udp.html index 7f2ecce..9f5cf8f 100644 --- a/doc/udp.html +++ b/doc/udp.html | |||
@@ -52,7 +52,7 @@ is used to connect the object. | |||
52 | 52 | ||
53 | <p class="return"> | 53 | <p class="return"> |
54 | In case of success, a new unconnected UDP object | 54 | In case of success, a new unconnected UDP object |
55 | returned. In case of error, <tt>nil</tt> is returned, followed by | 55 | returned. In case of error, <b><tt>nil</tt></b> is returned, followed by |
56 | an error message. | 56 | an error message. |
57 | </p> | 57 | </p> |
58 | 58 | ||
@@ -112,7 +112,7 @@ Returns the local address information associated to the object. | |||
112 | <p class="return"> | 112 | <p class="return"> |
113 | The method returns a string with local IP | 113 | The method returns a string with local IP |
114 | address and a number with the port. In case of error, the method | 114 | address and a number with the port. In case of error, the method |
115 | returns <tt>nil</tt>. | 115 | returns <b><tt>nil</tt></b>. |
116 | </p> | 116 | </p> |
117 | 117 | ||
118 | <p class="note"> | 118 | <p class="note"> |
@@ -150,7 +150,7 @@ maximum datagram size is used. | |||
150 | <p class="return"> | 150 | <p class="return"> |
151 | In case of success, the method return the | 151 | In case of success, the method return the |
152 | received datagram. In case of timeout, the method returns | 152 | received datagram. In case of timeout, the method returns |
153 | <tt>nil</tt> followed by the string '<tt>timeout</tt>'. | 153 | <b><tt>nil</tt></b> followed by the string '<tt>timeout</tt>'. |
154 | </p> | 154 | </p> |
155 | 155 | ||
156 | <!-- receivefrom +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 156 | <!-- receivefrom +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
@@ -183,7 +183,7 @@ Beware that the maximum datagram size for UDP is 576 bytes. | |||
183 | 183 | ||
184 | <p class="return"> | 184 | <p class="return"> |
185 | If successful, the method returns 1. In case of | 185 | If successful, the method returns 1. In case of |
186 | error, the method returns <tt>nil</tt> followed by the | 186 | error, the method returns <b><tt>nil</tt></b> followed by the |
187 | '<tt>refused</tt>' message. | 187 | '<tt>refused</tt>' message. |
188 | </p> | 188 | </p> |
189 | 189 | ||
@@ -214,7 +214,7 @@ names are <em>not</em> allowed for performance reasons. | |||
214 | 214 | ||
215 | <p class="return"> | 215 | <p class="return"> |
216 | If successful, the method returns 1. In case of | 216 | If successful, the method returns 1. In case of |
217 | error, the method returns <tt>nil</tt> followed by the | 217 | error, the method returns <b><tt>nil</tt></b> followed by the |
218 | '<tt>refused</tt>' message. | 218 | '<tt>refused</tt>' message. |
219 | </p> | 219 | </p> |
220 | 220 | ||
@@ -258,7 +258,7 @@ case, the <tt>port</tt> argument is ignored. | |||
258 | 258 | ||
259 | <p class="return"> | 259 | <p class="return"> |
260 | In case of error the method returns | 260 | In case of error the method returns |
261 | <tt>nil</tt> followed by an error message. In case of success, the | 261 | <b><tt>nil</tt></b> followed by an error message. In case of success, the |
262 | method returns 1. | 262 | method returns 1. |
263 | </p> | 263 | </p> |
264 | 264 | ||
@@ -288,7 +288,7 @@ all local interfaces using the constant <tt>INADDR_ANY</tt>. If | |||
288 | 288 | ||
289 | <p class="return"> | 289 | <p class="return"> |
290 | If successful, the method returns 1. In case of | 290 | If successful, the method returns 1. In case of |
291 | error, the method returns <tt>nil</tt> followed by an error | 291 | error, the method returns <b><tt>nil</tt></b> followed by an error |
292 | message. | 292 | message. |
293 | </p> | 293 | </p> |
294 | 294 | ||
@@ -328,7 +328,7 @@ socket.</li> | |||
328 | 328 | ||
329 | <p class="return"> | 329 | <p class="return"> |
330 | The method returns 1 in case of success, or | 330 | The method returns 1 in case of success, or |
331 | <tt>nil</tt> followed by an error message otherwise. | 331 | <b><tt>nil</tt></b> followed by an error message otherwise. |
332 | </p> | 332 | </p> |
333 | 333 | ||
334 | <p class="note"> | 334 | <p class="note"> |
@@ -356,7 +356,7 @@ give up and fail with an error code. | |||
356 | 356 | ||
357 | <p class="parameters"> | 357 | <p class="parameters"> |
358 | The amount of time to wait is specified as | 358 | The amount of time to wait is specified as |
359 | the <tt>value</tt> parameter, in seconds. The <tt>nil</tt> timeout | 359 | the <tt>value</tt> parameter, in seconds. The <b><tt>nil</tt></b> timeout |
360 | <tt>value</tt> allows operations to block indefinitely. Negative | 360 | <tt>value</tt> allows operations to block indefinitely. Negative |
361 | timeout values have the same effect. | 361 | timeout values have the same effect. |
362 | </p> | 362 | </p> |
diff --git a/doc/url.html b/doc/url.html index e67ea13..0eafafa 100644 --- a/doc/url.html +++ b/doc/url.html | |||
@@ -148,7 +148,7 @@ component. | |||
148 | 148 | ||
149 | <p class=parameters> | 149 | <p class=parameters> |
150 | <tt>Segments</tt> is a list of strings with the <tt><segment></tt> | 150 | <tt>Segments</tt> is a list of strings with the <tt><segment></tt> |
151 | parts. If <tt>unsafe</tt> is anything but <tt>nil</tt>, reserved | 151 | parts. If <tt>unsafe</tt> is anything but <b><tt>nil</tt></b>, reserved |
152 | characters are left untouched. | 152 | characters are left untouched. |
153 | </p> | 153 | </p> |
154 | 154 | ||
diff --git a/etc/b64.lua b/etc/b64.lua index 7a4607d..de83578 100644 --- a/etc/b64.lua +++ b/etc/b64.lua | |||
@@ -1,6 +1,11 @@ | |||
1 | local base64 = socket.mime.base64.encode() | 1 | local convert |
2 | local split = socket.mime.split() | 2 | if arg and arg[1] == '-d' then |
3 | local convert = socket.mime.chain(base64, split) | 3 | convert = socket.mime.decode("base64") |
4 | else | ||
5 | local base64 = socket.mime.encode("base64") | ||
6 | local wrap = socket.mime.wrap() | ||
7 | convert = socket.mime.chain(base64, wrap) | ||
8 | end | ||
4 | while 1 do | 9 | while 1 do |
5 | local chunk = io.read(4096) | 10 | local chunk = io.read(4096) |
6 | io.write(convert(chunk)) | 11 | io.write(convert(chunk)) |
@@ -19,11 +19,13 @@ | |||
19 | static int inet_global_toip(lua_State *L); | 19 | static int inet_global_toip(lua_State *L); |
20 | static int inet_global_tohostname(lua_State *L); | 20 | static int inet_global_tohostname(lua_State *L); |
21 | static void inet_pushresolved(lua_State *L, struct hostent *hp); | 21 | static void inet_pushresolved(lua_State *L, struct hostent *hp); |
22 | static int inet_global_gethostname(lua_State *L); | ||
22 | 23 | ||
23 | /* DNS functions */ | 24 | /* DNS functions */ |
24 | static luaL_reg func[] = { | 25 | static luaL_reg func[] = { |
25 | { "toip", inet_global_toip }, | 26 | { "toip", inet_global_toip }, |
26 | { "tohostname", inet_global_tohostname }, | 27 | { "tohostname", inet_global_tohostname }, |
28 | { "gethostname", inet_global_gethostname}, | ||
27 | { NULL, NULL} | 29 | { NULL, NULL} |
28 | }; | 30 | }; |
29 | 31 | ||
@@ -101,6 +103,25 @@ static int inet_global_tohostname(lua_State *L) | |||
101 | return 2; | 103 | return 2; |
102 | } | 104 | } |
103 | 105 | ||
106 | /*-------------------------------------------------------------------------*\ | ||
107 | * Gets the host name | ||
108 | \*-------------------------------------------------------------------------*/ | ||
109 | static int inet_global_gethostname(lua_State *L) | ||
110 | { | ||
111 | char name[257]; | ||
112 | name[256] = '\0'; | ||
113 | if (gethostname(name, 256) < 0) { | ||
114 | lua_pushnil(L); | ||
115 | lua_pushstring(L, "gethostname failed"); | ||
116 | return 2; | ||
117 | } else { | ||
118 | lua_pushstring(L, name); | ||
119 | return 1; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | |||
124 | |||
104 | /*=========================================================================*\ | 125 | /*=========================================================================*\ |
105 | * Lua methods | 126 | * Lua methods |
106 | \*=========================================================================*/ | 127 | \*=========================================================================*/ |
diff --git a/src/luasocket.c b/src/luasocket.c index 73583a8..bfe71c2 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
@@ -38,15 +38,8 @@ | |||
38 | /*=========================================================================*\ | 38 | /*=========================================================================*\ |
39 | * Declarations | 39 | * Declarations |
40 | \*=========================================================================*/ | 40 | \*=========================================================================*/ |
41 | static int global_gethostname(lua_State *L); | ||
42 | static int base_open(lua_State *L); | 41 | static int base_open(lua_State *L); |
43 | 42 | ||
44 | /* functions in library namespace */ | ||
45 | static luaL_reg func[] = { | ||
46 | {"gethostname", global_gethostname}, | ||
47 | {NULL, NULL} | ||
48 | }; | ||
49 | |||
50 | /*-------------------------------------------------------------------------*\ | 43 | /*-------------------------------------------------------------------------*\ |
51 | * Setup basic stuff. | 44 | * Setup basic stuff. |
52 | \*-------------------------------------------------------------------------*/ | 45 | \*-------------------------------------------------------------------------*/ |
@@ -70,30 +63,10 @@ static int base_open(lua_State *L) | |||
70 | lua_pushstring(L, "LUASOCKET_LIBNAME"); | 63 | lua_pushstring(L, "LUASOCKET_LIBNAME"); |
71 | lua_pushstring(L, LUASOCKET_LIBNAME); | 64 | lua_pushstring(L, LUASOCKET_LIBNAME); |
72 | lua_settable(L, LUA_GLOBALSINDEX); | 65 | lua_settable(L, LUA_GLOBALSINDEX); |
73 | /* define library functions */ | ||
74 | luaL_openlib(L, LUASOCKET_LIBNAME, func, 0); | ||
75 | lua_pop(L, 1); | ||
76 | return 0; | 66 | return 0; |
77 | } | 67 | } |
78 | 68 | ||
79 | /*-------------------------------------------------------------------------*\ | 69 | /*-------------------------------------------------------------------------*\ |
80 | * Gets the host name | ||
81 | \*-------------------------------------------------------------------------*/ | ||
82 | static int global_gethostname(lua_State *L) | ||
83 | { | ||
84 | char name[257]; | ||
85 | name[256] = '\0'; | ||
86 | if (gethostname(name, 256) < 0) { | ||
87 | lua_pushnil(L); | ||
88 | lua_pushstring(L, "gethostname failed"); | ||
89 | return 2; | ||
90 | } else { | ||
91 | lua_pushstring(L, name); | ||
92 | return 1; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | /*-------------------------------------------------------------------------*\ | ||
97 | * Initializes all library modules. | 70 | * Initializes all library modules. |
98 | \*-------------------------------------------------------------------------*/ | 71 | \*-------------------------------------------------------------------------*/ |
99 | LUASOCKET_API int luaopen_socket(lua_State *L) | 72 | LUASOCKET_API int luaopen_socket(lua_State *L) |
@@ -27,12 +27,12 @@ static const char EQCRLF[3] = {'=', CR, LF}; | |||
27 | /*=========================================================================*\ | 27 | /*=========================================================================*\ |
28 | * Internal function prototypes. | 28 | * Internal function prototypes. |
29 | \*=========================================================================*/ | 29 | \*=========================================================================*/ |
30 | static int mime_global_fmt(lua_State *L); | 30 | static int mime_global_wrp(lua_State *L); |
31 | static int mime_global_b64(lua_State *L); | 31 | static int mime_global_b64(lua_State *L); |
32 | static int mime_global_unb64(lua_State *L); | 32 | static int mime_global_unb64(lua_State *L); |
33 | static int mime_global_qp(lua_State *L); | 33 | static int mime_global_qp(lua_State *L); |
34 | static int mime_global_unqp(lua_State *L); | 34 | static int mime_global_unqp(lua_State *L); |
35 | static int mime_global_qpfmt(lua_State *L); | 35 | static int mime_global_qpwrp(lua_State *L); |
36 | static int mime_global_eol(lua_State *L); | 36 | static int mime_global_eol(lua_State *L); |
37 | 37 | ||
38 | static void b64setup(UC *b64unbase); | 38 | static void b64setup(UC *b64unbase); |
@@ -54,10 +54,10 @@ static luaL_reg func[] = { | |||
54 | { "eol", mime_global_eol }, | 54 | { "eol", mime_global_eol }, |
55 | { "qp", mime_global_qp }, | 55 | { "qp", mime_global_qp }, |
56 | { "unqp", mime_global_unqp }, | 56 | { "unqp", mime_global_unqp }, |
57 | { "qpfmt", mime_global_qpfmt }, | 57 | { "qpwrp", mime_global_qpwrp }, |
58 | { "b64", mime_global_b64 }, | 58 | { "b64", mime_global_b64 }, |
59 | { "unb64", mime_global_unb64 }, | 59 | { "unb64", mime_global_unb64 }, |
60 | { "fmt", mime_global_fmt }, | 60 | { "wrp", mime_global_wrp }, |
61 | { NULL, NULL } | 61 | { NULL, NULL } |
62 | }; | 62 | }; |
63 | 63 | ||
@@ -127,13 +127,13 @@ static const char *optlstring(lua_State *L, int n, const char *v, size_t *l) | |||
127 | \*=========================================================================*/ | 127 | \*=========================================================================*/ |
128 | /*-------------------------------------------------------------------------*\ | 128 | /*-------------------------------------------------------------------------*\ |
129 | * Incrementaly breaks a string into lines | 129 | * Incrementaly breaks a string into lines |
130 | * A, n = fmt(l, B, length, marker) | 130 | * A, n = wrp(l, B, length, marker) |
131 | * A is a copy of B, broken into lines of at most 'length' bytes. | 131 | * A is a copy of B, broken into lines of at most 'length' bytes. |
132 | * 'l' is how many bytes are left for the first line of B. | 132 | * 'l' is how many bytes are left for the first line of B. |
133 | * 'n' is the number of bytes left in the last line of A. | 133 | * 'n' is the number of bytes left in the last line of A. |
134 | * Marker is the end-of-line marker. | 134 | * Marker is the end-of-line marker. |
135 | \*-------------------------------------------------------------------------*/ | 135 | \*-------------------------------------------------------------------------*/ |
136 | static int mime_global_fmt(lua_State *L) | 136 | static int mime_global_wrp(lua_State *L) |
137 | { | 137 | { |
138 | size_t size = 0; | 138 | size_t size = 0; |
139 | int left = (int) luaL_checknumber(L, 1); | 139 | int left = (int) luaL_checknumber(L, 1); |
@@ -526,14 +526,14 @@ static int mime_global_unqp(lua_State *L) | |||
526 | 526 | ||
527 | /*-------------------------------------------------------------------------*\ | 527 | /*-------------------------------------------------------------------------*\ |
528 | * Incrementally breaks a quoted-printed string into lines | 528 | * Incrementally breaks a quoted-printed string into lines |
529 | * A, n = qpfmt(l, B, length) | 529 | * A, n = qpwrp(l, B, length) |
530 | * A is a copy of B, broken into lines of at most 'length' bytes. | 530 | * A is a copy of B, broken into lines of at most 'length' bytes. |
531 | * 'l' is how many bytes are left for the first line of B. | 531 | * 'l' is how many bytes are left for the first line of B. |
532 | * 'n' is the number of bytes left in the last line of A. | 532 | * 'n' is the number of bytes left in the last line of A. |
533 | * There are two complications: lines can't be broken in the middle | 533 | * There are two complications: lines can't be broken in the middle |
534 | * of an encoded =XX, and there might be line breaks already | 534 | * of an encoded =XX, and there might be line breaks already |
535 | \*-------------------------------------------------------------------------*/ | 535 | \*-------------------------------------------------------------------------*/ |
536 | static int mime_global_qpfmt(lua_State *L) | 536 | static int mime_global_qpwrp(lua_State *L) |
537 | { | 537 | { |
538 | size_t size = 0; | 538 | size_t size = 0; |
539 | int left = (int) luaL_checknumber(L, 1); | 539 | int left = (int) luaL_checknumber(L, 1); |
diff --git a/src/mime.lua b/src/mime.lua index 0251f6e..30c6b38 100644 --- a/src/mime.lua +++ b/src/mime.lua | |||
@@ -19,7 +19,7 @@ local wt = {} | |||
19 | local function choose(table) | 19 | local function choose(table) |
20 | return function(method, ...) | 20 | return function(method, ...) |
21 | local f = table[method or "nil"] | 21 | local f = table[method or "nil"] |
22 | if not f then return nil, "unknown method (" .. tostring(method) .. ")" | 22 | if not f then error("unknown method (" .. tostring(method) .. ")", 3) |
23 | else return f(unpack(arg)) end | 23 | else return f(unpack(arg)) end |
24 | end | 24 | end |
25 | end | 25 | end |
@@ -37,7 +37,15 @@ end | |||
37 | -- function that choose the encoding, decoding or wrap algorithm | 37 | -- function that choose the encoding, decoding or wrap algorithm |
38 | encode = choose(et) | 38 | encode = choose(et) |
39 | decode = choose(dt) | 39 | decode = choose(dt) |
40 | wrap = choose(wt) | 40 | |
41 | -- the wrap filter has default parameters | ||
42 | local cwt = choose(wt) | ||
43 | function wrap(...) | ||
44 | if not arg[1] or type(arg[1]) ~= "string" then | ||
45 | table.insert(arg, 1, "base64") | ||
46 | end | ||
47 | return cwt(unpack(arg)) | ||
48 | end | ||
41 | 49 | ||
42 | -- define the encoding algorithms | 50 | -- define the encoding algorithms |
43 | et['base64'] = function() | 51 | et['base64'] = function() |
@@ -58,15 +66,14 @@ dt['quoted-printable'] = function() | |||
58 | end | 66 | end |
59 | 67 | ||
60 | -- define the wrap algorithms | 68 | -- define the wrap algorithms |
61 | wt['character'] = function(length) | 69 | wt['base64'] = function(length, marker) |
62 | length = length or 76 | 70 | length = length or 76 |
63 | return cicle(fmt, length, length) | 71 | return cicle(wrp, length, length, marker) |
64 | end | 72 | end |
65 | wt['base64'] = wt['character'] | ||
66 | 73 | ||
67 | wt['quoted-printable'] = function(length) | 74 | wt['quoted-printable'] = function(length) |
68 | length = length or 76 | 75 | length = length or 76 |
69 | return cicle(qpfmt, length, length) | 76 | return cicle(qpwrp, length, length) |
70 | end | 77 | end |
71 | 78 | ||
72 | -- define the end-of-line translation function | 79 | -- define the end-of-line translation function |
diff --git a/test/httptest.lua b/test/httptest.lua index 8bf3980..c9a74a8 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
@@ -12,7 +12,7 @@ socket.http.TIMEOUT = 5 | |||
12 | 12 | ||
13 | local t = socket.time() | 13 | local t = socket.time() |
14 | 14 | ||
15 | host = host or "diego.student.dyn.cs.princeton.edu" | 15 | host = host or "diego-interface2.student.dyn.CS.Princeton.EDU" |
16 | proxy = proxy or "http://localhost:3128" | 16 | proxy = proxy or "http://localhost:3128" |
17 | prefix = prefix or "/luasocket-test" | 17 | prefix = prefix or "/luasocket-test" |
18 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | 18 | cgiprefix = cgiprefix or "/luasocket-test-cgi" |
diff --git a/test/mimetest.lua b/test/mimetest.lua index aa2772c..81814de 100644 --- a/test/mimetest.lua +++ b/test/mimetest.lua | |||
@@ -4,7 +4,7 @@ local qptest = "qptest.bin" | |||
4 | local eqptest = "qptest.bin2" | 4 | local eqptest = "qptest.bin2" |
5 | local dqptest = "qptest.bin3" | 5 | local dqptest = "qptest.bin3" |
6 | 6 | ||
7 | local b64test = "luasocket.exe" | 7 | local b64test = "luasocket" |
8 | local eb64test = "b64test.bin" | 8 | local eb64test = "b64test.bin" |
9 | local db64test = "b64test.bin2" | 9 | local db64test = "b64test.bin2" |
10 | 10 | ||
@@ -155,10 +155,10 @@ local function encode_b64test() | |||
155 | local e2 = socket.mime.encode("base64") | 155 | local e2 = socket.mime.encode("base64") |
156 | local e3 = socket.mime.encode("base64") | 156 | local e3 = socket.mime.encode("base64") |
157 | local e4 = socket.mime.encode("base64") | 157 | local e4 = socket.mime.encode("base64") |
158 | local sp4 = socket.mime.wrap("character") | 158 | local sp4 = socket.mime.wrap() |
159 | local sp3 = socket.mime.wrap("character", 59) | 159 | local sp3 = socket.mime.wrap(59) |
160 | local sp2 = socket.mime.wrap("character", 30) | 160 | local sp2 = socket.mime.wrap("base64", 30) |
161 | local sp1 = socket.mime.wrap("character", 27) | 161 | local sp1 = socket.mime.wrap(27) |
162 | local chain = socket.mime.chain(e1, sp1, e2, sp2, e3, sp3, e4, sp4) | 162 | local chain = socket.mime.chain(e1, sp1, e2, sp2, e3, sp3, e4, sp4) |
163 | transform(b64test, eb64test, chain) | 163 | transform(b64test, eb64test, chain) |
164 | end | 164 | end |
diff --git a/test/testclnt.lua b/test/testclnt.lua index beb0157..5f366b2 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
@@ -378,7 +378,7 @@ end | |||
378 | 378 | ||
379 | ------------------------------------------------------------------------ | 379 | ------------------------------------------------------------------------ |
380 | function accept_errors() | 380 | function accept_errors() |
381 | io.write("not listenning: ") | 381 | io.write("not listening: ") |
382 | local d, e = socket.bind("*", 0) | 382 | local d, e = socket.bind("*", 0) |
383 | assert(d, e); | 383 | assert(d, e); |
384 | local c, e = socket.tcp(); | 384 | local c, e = socket.tcp(); |
@@ -392,7 +392,7 @@ function accept_errors() | |||
392 | assert(c, e); | 392 | assert(c, e); |
393 | d:setfd(c:getfd()) | 393 | d:setfd(c:getfd()) |
394 | local r, e = d:accept() | 394 | local r, e = d:accept() |
395 | assert(not r and e == "not supported", e) | 395 | assert(not r and e == "not supported" or e == "not listening", e) |
396 | print("ok") | 396 | print("ok") |
397 | end | 397 | end |
398 | 398 | ||