Working on the manual...

Making better tests for error messages.
Changed a few names.
Moved gethostname to inet.c.
This commit is contained in:
Diego Nehab 2004-01-24 02:47:24 +00:00
parent 0c9f420a35
commit 62a4c505e4
21 changed files with 341 additions and 315 deletions

6
TODO
View File

@ -1,4 +1,5 @@
manual manual
check all occurences of it's
add shutdown add shutdown
add gethostname add gethostname
the need of a content-length header in the post method... the need of a content-length header in the post method...
@ -22,6 +23,11 @@ tests
checar garbage collection checar garbage collection
check for interrupts check for interrupts
close has to block...
fmt is not a good name
change wrap() to accept a number and default to "character"
move gethostname to dns table
get rid of _cb in name of functions?
trust character constants in mime.c? noooooo. trust character constants in mime.c? noooooo.
smtp.lua needs stuff filter smtp.lua needs stuff filter

View File

@ -45,113 +45,72 @@ callback mechanism outlined below.
</p> </p>
<p> <p>
Instead of returning the entire contents of an entity Instead of returning the received contents
as strings to the Lua application, the library allows the user to as a big to the Lua application, the library allows the user to
provide a <em>receive callback</em> that will be called with successive provide a <em>receive callback</em> that will be called with successive
chunks of data, as the data becomes available. Conversely, the <em>send chunks of data, as the data becomes available. Conversely, the <em>send
callbacks</em> can be used when the application wants to incrementally callback</em> mechanism can be used when the application wants to incrementally provide LuaSocket with the data to be sent.
provide LuaSocket with the data to be sent.
</p> </p>
<!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=receive_cb> <p class=name id=receive>
ret, err_or_f = <b>receive_cb(</b>chunk, err<b>)</b> <b>receive_cb(</b>chunk, err<b>)</b>
</p> </p>
<p class=description> <p class=description>
The callback provided by the user will be repeatedly called by the A receive callback will be repeatedly called by
library whenever new data is available. Each time it is called, the LuaSocket wheneve new data is available. Each time it is called, the
callback receives successive chunks of downloaded data. callback receives successive chunks of downloaded data.
</p> </p>
<p class=parameters> <p class=parameters>
<tt>Chunk</tt> contains the current chunk of data. <tt>Chunk</tt> contains the latest downloaded chunk of data.
When the transmission is over, the function is called with an When the transmission is over, the function is called with an
empty string (i.e.&nbsp;<tt>""</tt>) as the <tt>chunk</tt>. empty string (i.e.&nbsp;<tt>""</tt>) in <tt>chunk</tt>.
If an error occurs, the function receives <tt>nil</tt> If an error occurs, the function receives a <b><tt>nil</tt></b>
as <tt>chunk</tt> and an error message in <tt>err</tt>. <tt>chunk</tt> and an error message in <tt>err</tt>.
</p> </p>
<p class=return> <p class=return>
The callback can abort transmission by returning <tt>nil</tt> as its first The callback can abort transmission by returning <b><tt>nil</tt></b> as its first
return value, and an optional error message as the return value, and an optional error message as the
second return value. If the application wants to continue receiving second return value. To continue receiving
data, the function should return non-<tt>nil</tt> as it's first return data, the function should return non-<b><tt>nil</tt></b> as its first return
value. In this case, the function can optionally return a value. Optionally, in this case, it may return a
new callback function, to replace itself, as the second return value. second return value, with a new callback function to take its place.
</p>
<p class=note>
Note: The <tt>callback</tt> module provides several standard receive callbacks, including the following:
</p>
<pre class=example>
function receive.concat(concat)
concat = concat or socket.concat.create()
local callback = function(chunk, err)
-- if not finished, add chunk
if chunk and chunk ~= "" then
concat:addstring(chunk)
return 1
end
end
return callback, concat
end
</pre>
<p class=note>
This function creates a new receive callback that concatenates all
received chunks into a the same concat object, which can later be
queried for its contents.
</p> </p>
<!-- send_cb ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- send_cb ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name> <p class=name id=send>
chunk, err_or_r = <b>send_cb()</b> <b>send_cb()</b>
</p> </p>
<p class=description> <p class=description>
The callback provided by the user will be repeatedly called whenever the A send callback will be called whenever LuaSocket
library needs more data to be sent. needs more data to be sent.
</p> </p>
<p class=return> <p class=return>
Each time the callback is called, it should return the next chunk of data. It Each time the callback is called, it should return the next chunk of data. It
can optionally return, as it's second return value, a new callback to replace can optionally return, as it's second return value, a new callback to replace
itself. The callback can abort the process at any time by returning itself. The callback can abort the process at any time by returning
<tt>nil</tt> followed by an optional error message. <b><tt>nil</tt></b> followed by an optional error message.
</p> </p>
<p class=note>
Note: Below is the implementation of the <tt>callback.send.file</tt>
function. Given an open file handle, it returns a send callback that will send the contents of that file, chunk by chunk.
</p>
<pre class=example>
function send.file(file, io_err)
-- if successful, return the callback that reads from the file
if file then
return function()
-- send next block of data
return (file:read(BLOCKSIZE)) or ""
end
-- else, return a callback that just aborts the transfer
else return fail(io_err or "unable to open file") end
end
</pre>
<!-- predefined +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- predefined +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<h2 id=predefined>Predefined Callbacks</h2> <h2 id=predefined>Predefined Callbacks</h2>
<p> <p>
The module <tt>callback.lua</tt> provides several predefined callbacks to The Callback module provides several predefined callbacks to
perform the most common input/output operations. Callbacks are provided perform the most common input/output operations. Callbacks are provided
that send and receive contents of files and strings. Furthermore, that send and receive contents of files and strings. Furthermore,
composition functions are provided to chain callbacks with filters, such as composition functions are provided to chain callbacks with filters, such as
the filters defined in the <tt>mime.lua</tt> module. the filters defined in the <a href=mime.html>MIME</a> module.
Together, these two modules provide a powerful interface to send and
receive information.
</p> </p>
<!-- send.file ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- send.file ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@ -161,15 +120,16 @@ the filters defined in the <tt>mime.lua</tt> module.
</p> </p>
<p class=description> <p class=description>
This function creates a send callback that will return the contents This function creates a send callback that returns the contents
of a the file, until the file has been entirely sent. When done, the of a file, chunk by chunk, until the file has been entirely sent.
callback closes the file. When done, the callback closes the file.
</p> </p>
<p class=parameters> <p class=parameters>
<tt>File</tt> is a file open for reading. If <tt>file</tt> is <tt>File</tt> is a file opened for reading. If <tt>file</tt> is
<tt>nil</tt>, <tt>io_err</tt> can contain an error message and the <b><tt>nil</tt></b>, <tt>io_err</tt> can contain an error message. In this
returned callback just aborts transmission with the error message. case, the function returns a callback that just aborts
transmission with the error message.
</p> </p>
<p class=return> <p class=return>
@ -177,14 +137,14 @@ Returns a send callback for the file.
</p> </p>
<p class=note> <p class=note>
Note: The function is designed so that it directly accepts the return Note: This function is designed so that it directly accepts the return
values of the <tt>io.open</tt> function. values of the <tt>io.open</tt> function.
</p> </p>
<!-- send.string ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- send.string ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=send.string> <p class=name id=send.string>
<b>send.string(</b>str<b>)</b> <b>send.string(</b>str, err<b>)</b>
</p> </p>
<p class=description> <p class=description>
@ -194,28 +154,32 @@ the contents of a string.
<p class=parameters> <p class=parameters>
<tt>Str</tt> is the string to be sent. <tt>Str</tt> is the string to be sent.
<!--
If <tt>str</tt> is
<b><tt>nil</tt></b>, <tt>err</tt> can optionally contain an error message.
-->
</p> </p>
<p class=return> <p class=return>
Returns a send callback for the string, or <tt>nil</tt> if the string is Returns a send callback for the string, or <b><tt>nil</tt></b> if the string is
<tt>nil</tt>. <b><tt>nil</tt></b>.
</p> </p>
<p class=note> <p class=note>
Note: If any function in the LuaSocket API receives a <tt>nil</tt> Note: A <tt>nil</tt></b>
send callback, it assumes there is nothing to be sent. send callback is equivalent to a callback that returns the empty string.
</p> </p>
<!-- send.chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- send.chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=send.string> <p class=name id=send.chain>
<b>send.chain(</b>send_cb, filter<b>)</b> <b>send.chain(</b>send_cb, filter<b>)</b>
</p> </p>
<p class=description> <p class=description>
This function creates a send callback that will send This function creates a send callback that will filter
all data that it gets from another callback, all the data it receives from another send callback, before
after passing the data through a filter. sending it through.
</p> </p>
<p class=parameters> <p class=parameters>
@ -226,7 +190,29 @@ after passing the data through a filter.
Returns a callback chained with the filter. Returns a callback chained with the filter.
</p> </p>
(write a note!) <p class=note>
Note: Several filters are defined in the <a href=mime.html>MIME</a>
module. Below is an example that creates a send callback that sends
a file's contents encoded in the Base64 transfer content encoding.
</p>
<pre class=example>
send_cb = socket.callback.send.chain(
socket.callback.send.file(io.open("input.bin"))
socket.mime.chain(
socket.mime.encode("base64"),
socket.mime.wrap("base64")
)
)
</pre>
<p class=note>
The call to <a href=mime.html#chain><tt>socket.mime.chain</tt></a>
creates a chained filter that encodes it's input and then breaks it
into lines. The call to <tt>socket.callback.chain</tt> creates a chained
send callback that reads the file from disk and passes it through the
filter before sending it.
</p>
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

View File

@ -59,7 +59,7 @@ Applies the Base 64 content coding to a string.
<p class=parameters> <p class=parameters>
<tt>Content</tt> is the string to be encoded. <tt>Content</tt> is the string to be encoded.
If <tt>single</tt> is set to anything If <tt>single</tt> is set to anything
but <tt>nil</tt>, the output is returned as a single but <b><tt>nil</tt></b>, the output is returned as a single
line, otherwise the function splits the content into 76 character long line, otherwise the function splits the content into 76 character long
lines after encoding. lines after encoding.
</p> </p>

View File

@ -70,7 +70,7 @@ Converts from IP address to host name.
<p class=return> <p class=return>
The function a string with the canonic host name of the given The function a string with the canonic host name of the given
<tt>address</tt>, followed by a table with all information returned by <tt>address</tt>, followed by a table with all information returned by
the resolver. In case of error, the function returns <tt>nil</tt> the resolver. In case of error, the function returns <b><tt>nil</tt></b>
followed by an error message. followed by an error message.
</p> </p>
@ -92,7 +92,7 @@ Converts from host name to IP address.
<p class=return> <p class=return>
Returns a string with the first IP address found for <tt>address</tt>, Returns a string with the first IP address found for <tt>address</tt>,
followed by a table with all information returned by the resolver. followed by a table with all information returned by the resolver.
In case of error, the function returns <tt>nil</tt> followed by an error In case of error, the function returns <b><tt>nil</tt></b> followed by an error
message. message.
</p> </p>

View File

@ -88,7 +88,7 @@ determines the transfer type. If <tt>&lt;path&gt;</tt> ends with a
<p class=return> <p class=return>
If successful, the function returns If successful, the function returns
the file content as a string. In case of error, the function returns the file content as a string. In case of error, the function returns
<tt>nil</tt> and an error message describing the error. <b><tt>nil</tt></b> and an error message describing the error.
</p> </p>
<pre class=example> <pre class=example>
@ -165,7 +165,7 @@ function tries to log in as '<tt>anonymous</tt>'.
<p class=return> <p class=return>
If successful, the function returns 1. In case of error, the If successful, the function returns 1. In case of error, the
function returns <tt>nil</tt> followed by a string describing the error. function returns <b><tt>nil</tt></b> followed by a string describing the error.
</p> </p>
<pre class=example> <pre class=example>

View File

@ -203,7 +203,7 @@ request message. If authentication information is provided, the function
uses the Basic Authentication Scheme (see <a href="#authentication">note</a>) uses the Basic Authentication Scheme (see <a href="#authentication">note</a>)
to retrieve the document. <tt>User</tt> and <tt>password</tt> provided to retrieve the document. <tt>User</tt> and <tt>password</tt> provided
explicitly override those given by the <tt>url</tt>. The <tt>stay</tt> explicitly override those given by the <tt>url</tt>. The <tt>stay</tt>
parameter, when set to anything but <tt>nil</tt>, prevents the function parameter, when set to anything but <b><tt>nil</tt></b>, prevents the function
from automatically following 301 or 302 server redirect messages. from automatically following 301 or 302 server redirect messages.
</p> </p>
@ -333,7 +333,7 @@ Authentication Scheme (see <a href="#authentication">note</a>) to
retrieve the document. <tt>Request.user</tt> and retrieve the document. <tt>Request.user</tt> and
<tt>request.password</tt> override those given by the <tt>request.password</tt> override those given by the
<tt>request.url</tt>. The <tt>request.stay</tt> parameter, when set to <tt>request.url</tt>. The <tt>request.stay</tt> parameter, when set to
anything but <tt>nil</tt>, prevents the function from automatically anything but <b><tt>nil</tt></b>, prevents the function from automatically
following 301 or 302 server redirect messages. following 301 or 302 server redirect messages.
</p> </p>

View File

@ -1,11 +1,19 @@
body { margin-left: 1em; margin-right: 1em; } body {
margin-left: 1em;
margin-right: 1em;
font-family: "Verdana";
}
tt {
font-family: "Andale Mono", monospace;
}
h1, h2, h3, h4 { margin-left: 0em; } h1, h2, h3, h4 { margin-left: 0em; }
p { margin-left: 1em; } p { margin-left: 1em; }
p.name { p.name {
font-family: monospace; font-family: "Andale Mono", monospace;
padding-top: 1em; padding-top: 1em;
margin-left: 0em; margin-left: 0em;
} }
@ -18,6 +26,8 @@ pre.example {
background: #ccc; background: #ccc;
padding: 1em; padding: 1em;
margin-left: 1em; margin-left: 1em;
font-family: "Andale Mono", monospace;
font-size: small;
} }
hr { hr {

View File

@ -35,155 +35,173 @@
<h2>Reference</h2> <h2>Reference</h2>
<!-- tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- callback +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<table summary="TCP Index" class=index width=100%> <blockquote>
<colgroup> <col width="50%"> <col width="50%"> </colgroup> <a href="callback.html">Callbacks (socket.callback)</a>
<tr> <blockquote>
<td><ul> <a href="callback.html#send">send</a>:
<li><a href="tcp.html">TCP (socket.tcp)</a> <a href="callback.html#send.chain">chain</a>,
<ul> <a href="callback.html#send.file">file</a>,
<li><a href="tcp.html#accept">accept</a> <a href="callback.html#send.string">string</a>.
<li><a href="tcp.html#bind">bind</a> </blockquote>
<li><a href="tcp.html#close">close</a> <blockquote>
<li><a href="tcp.html#connect">connect</a> <a href="callback.html#receive">receive</a>:
<li><a href="tcp.html#getpeername">getpeername</a> <a href="callback.html#receive.chain">chain</a>,
</ul> <a href="callback.html#receive.file">file</a>,
</ul></td> <a href="callback.html#receive.concat">concat</a>.
<td valign=top><ul> </blockquote>
<li><a href="tcp.html#getsockname">getsockname</a> </blockquote>
<li><a href="tcp.html#receive">receive</a>
<li><a href="tcp.html#send">send</a>
<li><a href="tcp.html#setoption">setoption</a>
<li><a href="tcp.html#settimeout">settimeout</a>
</ul></td>
</tr>
</table> </table>
<hr> <!-- dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<blockquote>
<a href="dns.html">DNS services (socket.dns)</a>
<blockquote>
<a href="dns.html#toip">toip</a>,
<a href="dns.html#tohostname">tohostname</a>,
<a href="dns.html#gethostname">gethostname</a>.
</blockquote>
</blockquote>
<!-- ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<blockquote>
<a href="ftp.html">FTP (socket.ftp)</a>
<blockquote>
<a href="ftp.html#get">get</a>,
<a href="ftp.html#get_cb">get_cb</a>,
<a href="ftp.html#put">put</a>,
<a href="ftp.html#put_cb">put_cb</a>.
</blockquote>
</blockquote>
<!-- misc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<blockquote>
<a href="global.html">Globals (socket)</a>
<blockquote>
<a href="global.html#bind">bind</a>,
<a href="global.html#callback">callback</a>,
<a href="global.html#concat">concat</a>,
<a href="global.html#connect">connect</a>,
<a href="global.html#debug">debug</a>,
<a href="global.html#dns">dns</a>,
<a href="global.html#ftp">ftp</a>,
<a href="global.html#http">http</a>,
<a href="global.html#mime">mime</a>,
<a href="global.html#select">select</a>,
<a href="global.html#sleep">sleep</a>,
<a href="global.html#smtp">smtp</a>,
<a href="global.html#time">time</a>,
<a href="global.html#tcp">tcp</a>.
<a href="global.html#udp">udp</a>,
<a href="global.html#url">url</a>,
<a href="global.html#version">version</a>.
</blockquote>
</blockquote>
</table>
<!-- http +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<blockquote>
<a href="http.html">HTTP (socket.http)</a>
<blockquote>
<a href="http.html#get">get</a>,
<a href="http.html#post">post</a>,
<a href="http.html#request">request</a>,
<a href="http.html#request_cb">request_cb</a>.
</blockquote>
</blockquote>
<!-- mime +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<blockquote>
<a href="mime.html">MIME (socket.mime) </a>
<blockquote>
<a href="mime.html#filters">filters</a>:
<a href="mime.html#decode">canonic</a>,
<a href="mime.html#chain">chain</a>,
<a href="mime.html#decode">decode</a>,
<a href="mime.html#encode">encode</a>,
<a href="mime.html#wrap">wrap</a>.
</blockquote>
<blockquote>
<a href="mime.html#low-level">low-level</a>:
<a href="mime.html#b64">b64</a>,
<a href="mime.html#unb64">unb64</a>,
<a href="mime.html#eol">eol</a>,
<a href="mime.html#qp">qp</a>,
<a href="mime.html#unqp">unqp</a>,
<a href="mime.html#wrp">wrp</a>,
<a href="mime.html#qpwrp">qpwrp</a>.
</blockquote>
</blockquote>
<!-- smtp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<blockquote>
<a href="smtp.html">SMTP (socket.smtp)</a>
<blockquote>
<a href="smtp.html#mail">mail</a>
</blockquote>
</blockquote>
<!-- tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<blockquote>
<a href="tcp.html">TCP (socket.tcp)</a>
<blockquote>
<a href="tcp.html#accept">accept</a>,
<a href="tcp.html#bind">bind</a>,
<a href="tcp.html#close">close</a>,
<a href="tcp.html#connect">connect</a>,
<a href="tcp.html#getpeername">getpeername</a>,
<a href="tcp.html#getsockname">getsockname</a>,
<a href="tcp.html#receive">receive</a>,
<a href="tcp.html#send">send</a>,
<a href="tcp.html#setoption">setoption</a>,
<a href="tcp.html#settimeout">settimeout</a>,
<a href="tcp.html#shutdown">shutdown</a>.
</blockquote>
</blockquote>
<!-- udp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- udp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<table summary="UDP Index" class=index width=100%> <blockquote>
<colgroup> <col width="50%"> <col width="50%"> </colgroup> <a href="udp.html">UDP (socket.udp)</a>
<tr> <blockquote>
<td><ul> <a href="udp.html#close">close</a>,
<li><a href="udp.html">UDP (socket.udp)</a> <a href="udp.html#getpeername">getpeername</a>,
<ul> <a href="udp.html#getsockname">getsockname</a>,
<li><a href="udp.html#close">close</a> <a href="udp.html#receive">receive</a>,
<li><a href="udp.html#getpeername">getpeername</a> <a href="udp.html#receivefrom">receivefrom</a>,
<li><a href="udp.html#getsockname">getsockname</a> <a href="udp.html#send">send</a>,
<li><a href="udp.html#receive">receive</a> <a href="udp.html#sendto">sendto</a>,
<li><a href="udp.html#receivefrom">receivefrom</a> <a href="udp.html#setpeername">setpeername</a>,
</ul> <a href="udp.html#setsockname">setsockname</a>,
</ul></td> <a href="udp.html#setoption">setoption</a>,
<td><ul> <a href="udp.html#settimeout">settimeout</a>,
<li><a href="udp.html#send">send</a> <a href="udp.html#settimeout">shutdown</a>.
<li><a href="udp.html#sendto">sendto</a> </blockquote>
<li><a href="udp.html#setpeername">setpeername</a> </blockquote>
<li><a href="udp.html#setsockname">setsockname</a>
<li><a href="udp.html#setoption">setoption</a>
<li><a href="udp.html#settimeout">settimeout</a>
</ul></td>
</tr>
</table>
<hr> <!-- url ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- http & ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <blockquote>
<a href="url.html">URL (socket.url) </a>
<table summary="HTTP and FTP Index" class=index width=100%> <blockquote>
<colgroup> <col width="50%"> <col width="50%"> </colgroup> <a href="url.html#absolute">absolute</a>,
<tr> <a href="url.html#build">build</a>,
<td valign=top><ul> <a href="url.html#build_path">build_path</a>,
<li><a href="http.html">HTTP (socket.http)</a> <a href="url.html#quote">quote</a>,
<ul> <a href="url.html#parse">parse</a>,
<li><a href="http.html#get">get</a> <a href="url.html#parse_path">parse_path</a>,
<li><a href="http.html#post">post</a> <a href="url.html#quote">unquote</a>.
<li><a href="http.html#request">request</a> </blockquote>
<li><a href="http.html#request_cb">request_cb</a> </blockquote>
</ul>
</ul></td>
<td valign=top><ul>
<li><a href="ftp.html">FTP (socket.ftp)</a>
<ul>
<li><a href="ftp.html#get">get</a>
<li><a href="ftp.html#get_cb">get_cb</a>
<li><a href="ftp.html#put">put</a>
<li><a href="ftp.html#put_cb">put_cb</a>
</ul>
</ul></td>
</tr>
</table>
<hr>
<!-- http & ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<table summary="Streaming Index" class=index width=100%>
<colgroup> <col width="50%"> <col width="50%"> </colgroup>
<tr><td valign=top><ul>
<li><a href="stream.html">Streaming with Callbacks</a>
<ul>
<li><a href="stream.html#receive_cb">receive_cb</a>
<li><a href="stream.html#send_cb">send_cb</a>
</ul>
</ul></td></tr>
</table>
<hr>
<!-- smtp & dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<table summary="SMTP and DNS Index" class=index width=100%>
<colgroup> <col width="50%"> <col width="50%"> </colgroup>
<tr>
<td><ul>
<li><a href="smtp.html">SMTP (socket.smtp)</a>
<ul>
<li> <a href="smtp.html#mail">mail</a>
</ul>
</ul></td>
<td><ul>
<li><a href="dns.html">DNS services (socket.dns)</a>
<ul>
<li><a href="dns.html#toip">toip</a>
<li><a href="dns.html#tohostname">tohostname</a>
</ul>
</ul></td>
</tr>
</table>
<hr>
<!-- url & code ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<table summary="URL and Code Index" class=index width=100%>
<colgroup> <col width="50%"> <col width="50%"> </colgroup>
<tr>
<td valign=top><ul>
<li><a href="url.html">URL (socket.url) </a>
<ul>
<li> <a href="url.html#absolute">absolute</a>
<li> <a href="url.html#build">build</a>
<li> <a href="url.html#build_path">build_path</a>
<li> <a href="url.html#parse">parse</a>
<li> <a href="url.html#parse_path">parse_path</a>
</ul>
</ul></td>
<td valign=top><ul>
<li> <a href="code.html">Code (socket.code) </a>
<ul>
<li> <a href="code.html#base64">base64</a>
<li> <a href="code.html#unbase64">unbase64</a>
<li> <a href="code.html#escape">escape</a>
<li> <a href="code.html#unescape">unescape</a>
<li> <a href="code.html#hexa">hexa</a>
<li> <a href="code.html#unhexa">unhexa</a>
</ul>
</ul></td>
</tr>
</table>
<!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

View File

@ -105,7 +105,7 @@ and text <tt>body</tt>. The message is sent using the server
<p class=return> <p class=return>
If successful, the function returns 1. Otherwise, the function returns If successful, the function returns 1. Otherwise, the function returns
<tt>nil</tt> followed by an error message. <b><tt>nil</tt></b> followed by an error message.
</p> </p>
<p class=note> <p class=note>

View File

@ -69,15 +69,15 @@ callback receives successive chunks of downloaded data.
<tt>Chunk</tt> contains the current chunk of data. <tt>Chunk</tt> contains the current chunk of data.
When the transmission is over, the function is called with an When the transmission is over, the function is called with an
empty string (i.e.&nbsp;<tt>""</tt>) as the <tt>chunk</tt>. empty string (i.e.&nbsp;<tt>""</tt>) as the <tt>chunk</tt>.
If an error occurs, the function receives <tt>nil</tt> If an error occurs, the function receives <b><tt>nil</tt></b>
as <tt>chunk</tt> and an error message in <tt>err</tt>. as <tt>chunk</tt> and an error message in <tt>err</tt>.
</p> </p>
<p class=return> <p class=return>
The callback can abort transmission by returning <tt>nil</tt> as its first The callback can abort transmission by returning <b><tt>nil</tt></b> as its first
return value, and an optional error message as the return value, and an optional error message as the
second return value. If the application wants to continue receiving second return value. If the application wants to continue receiving
data, the function should return non-<tt>nil</tt> as it's first return data, the function should return non-<b><tt>nil</tt></b> as it's first return
value. In this case, the function can optionally return a value. In this case, the function can optionally return a
new callback function, to replace itself, as the second return value. new callback function, to replace itself, as the second return value.
</p> </p>
@ -121,7 +121,7 @@ library needs more data to be sent.
Each time the callback is called, it should return the next chunk of data. It Each time the callback is called, it should return the next chunk of data. It
can optionally return, as it's second return value, a new callback to replace can optionally return, as it's second return value, a new callback to replace
itself. The callback can abort the process at any time by returning itself. The callback can abort the process at any time by returning
<tt>nil</tt> followed by an optional error message. <b><tt>nil</tt></b> followed by an optional error message.
</p> </p>
<p class=note> <p class=note>

View File

@ -51,7 +51,7 @@ method.</p>
<p class=return> <p class=return>
In case of success, a new master object is returned. In case of error, In case of success, a new master object is returned. In case of error,
<tt>nil</tt> is returned, followed by an error message. <b><tt>nil</tt></b> is returned, followed by an error message.
</p> </p>
<!-- accept +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- accept +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@ -67,7 +67,7 @@ object and returns a client object representing that connection.
<p class=return> <p class=return>
If a connection is successfully initiated, a client object is returned. If a connection is successfully initiated, a client object is returned.
If a timeout condition is met, the method returns <tt>nil</tt> followed If a timeout condition is met, the method returns <b><tt>nil</tt></b> followed
by the error string '<tt>timeout</tt>'. by the error string '<tt>timeout</tt>'.
</p> </p>
@ -111,7 +111,7 @@ attempts connection, the connection is refused.
<p class=return> <p class=return>
In case of success, the method returns 1. In case of error, the In case of success, the method returns 1. In case of error, the
method returns <tt>nil</tt> followed by an error message. method returns <b><tt>nil</tt></b> followed by an error message.
</p> </p>
<p class=note> <p class=note>
@ -165,7 +165,7 @@ and <a href=#close><tt>close</tt></a>.
</p> </p>
<p class=return> <p class=return>
In case of error, the method returns <tt>nil</tt> followed by a string In case of error, the method returns <b><tt>nil</tt></b> followed by a string
describing the error. In case of success, the method returns 1. describing the error. In case of success, the method returns 1.
</p> </p>
@ -187,7 +187,7 @@ Returns information about the remote side of a connected client object.
<p class=return> <p class=return>
Returns a string with the IP address of the peer, followed by the Returns a string with the IP address of the peer, followed by the
port number that peer is using for the connection. port number that peer is using for the connection.
In case of error, the method returns <tt>nil</tt>. In case of error, the method returns <b><tt>nil</tt></b>.
</p> </p>
<p class=note> <p class=note>
@ -207,7 +207,7 @@ Returns the local address information associated to the object.
<p class=return> <p class=return>
The method returns a string with local IP address and a number with The method returns a string with local IP address and a number with
the port. In case of error, the method returns <tt>nil</tt>. the port. In case of error, the method returns <b><tt>nil</tt></b>.
</p> </p>
<p class=note> <p class=note>
@ -248,7 +248,7 @@ bytes from the socket.
<p class=return> <p class=return>
The method returns one value for each pattern, followed by a single The method returns one value for each pattern, followed by a single
error code that can be <tt>nil</tt> in case of success, the string error code that can be <b><tt>nil</tt></b> in case of success, the string
'<tt>closed</tt>' in case the connection was closed before the '<tt>closed</tt>' in case the connection was closed before the
transmission was completed or the string '<tt>timeout</tt>' in case transmission was completed or the string '<tt>timeout</tt>' in case
there was a timeout during the operation. there was a timeout during the operation.
@ -278,7 +278,7 @@ result to LuaSocket instead of passing several independent strings.
<p class=return> <p class=return>
The method returns the number of bytes accepted by the transport layer, The method returns the number of bytes accepted by the transport layer,
followed by an error code. The error code is <tt>nil</tt> if the operation followed by an error code. The error code is <b><tt>nil</tt></b> if the operation
completed with no errors, the string '<tt>closed</tt>' in case completed with no errors, the string '<tt>closed</tt>' in case
the connection was closed before the transmission was completed or the the connection was closed before the transmission was completed or the
string '<tt>timeout</tt>' in case there was a timeout during the string '<tt>timeout</tt>' in case there was a timeout during the
@ -288,7 +288,7 @@ operation.
<p class=note> <p class=note>
Note: The return values for the <tt>send</tt> method have been changed in Note: The return values for the <tt>send</tt> method have been changed in
LuaSocket 2.0! In previous versions, the method returned only the LuaSocket 2.0! In previous versions, the method returned only the
error message. Since returning <tt>nil</tt> in case of success goes error message. Since returning <b><tt>nil</tt></b> in case of success goes
against all other LuaSocket methods and functions, the against all other LuaSocket methods and functions, the
<tt>send</tt> method been changed for the sake of uniformity. <tt>send</tt> method been changed for the sake of uniformity.
</p> </p>
@ -330,7 +330,7 @@ considered broken and processes using the socket are notified.
</ul> </ul>
<p class=return> <p class=return>
The method returns 1 in case of success, or <tt>nil</tt> otherwise. The method returns 1 in case of success, or <b><tt>nil</tt></b> otherwise.
</p> </p>
<p class=note> <p class=note>
@ -374,7 +374,7 @@ a call.</li>
</ul> </ul>
<p class=parameters> <p class=parameters>
The <tt>nil</tt> timeout <tt>value</tt> allows operations to block The <b><tt>nil</tt></b> timeout <tt>value</tt> allows operations to block
indefinitely. Negative timeout values have the same effect. indefinitely. Negative timeout values have the same effect.
</p> </p>

View File

@ -52,7 +52,7 @@ is used to connect the object.
<p class="return"> <p class="return">
In case of success, a new unconnected UDP object In case of success, a new unconnected UDP object
returned. In case of error, <tt>nil</tt> is returned, followed by returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
an error message. an error message.
</p> </p>
@ -112,7 +112,7 @@ Returns the local address information associated to the object.
<p class="return"> <p class="return">
The method returns a string with local IP The method returns a string with local IP
address and a number with the port. In case of error, the method address and a number with the port. In case of error, the method
returns <tt>nil</tt>. returns <b><tt>nil</tt></b>.
</p> </p>
<p class="note"> <p class="note">
@ -150,7 +150,7 @@ maximum datagram size is used.
<p class="return"> <p class="return">
In case of success, the method return the In case of success, the method return the
received datagram. In case of timeout, the method returns received datagram. In case of timeout, the method returns
<tt>nil</tt> followed by the string '<tt>timeout</tt>'. <b><tt>nil</tt></b> followed by the string '<tt>timeout</tt>'.
</p> </p>
<!-- receivefrom +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- receivefrom +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@ -183,7 +183,7 @@ Beware that the maximum datagram size for UDP is 576 bytes.
<p class="return"> <p class="return">
If successful, the method returns 1. In case of If successful, the method returns 1. In case of
error, the method returns <tt>nil</tt> followed by the error, the method returns <b><tt>nil</tt></b> followed by the
'<tt>refused</tt>' message. '<tt>refused</tt>' message.
</p> </p>
@ -214,7 +214,7 @@ names are <em>not</em> allowed for performance reasons.
<p class="return"> <p class="return">
If successful, the method returns 1. In case of If successful, the method returns 1. In case of
error, the method returns <tt>nil</tt> followed by the error, the method returns <b><tt>nil</tt></b> followed by the
'<tt>refused</tt>' message. '<tt>refused</tt>' message.
</p> </p>
@ -258,7 +258,7 @@ case, the <tt>port</tt> argument is ignored.
<p class="return"> <p class="return">
In case of error the method returns In case of error the method returns
<tt>nil</tt> followed by an error message. In case of success, the <b><tt>nil</tt></b> followed by an error message. In case of success, the
method returns 1. method returns 1.
</p> </p>
@ -288,7 +288,7 @@ all local interfaces using the constant <tt>INADDR_ANY</tt>. If
<p class="return"> <p class="return">
If successful, the method returns 1. In case of If successful, the method returns 1. In case of
error, the method returns <tt>nil</tt> followed by an error error, the method returns <b><tt>nil</tt></b> followed by an error
message. message.
</p> </p>
@ -328,7 +328,7 @@ socket.</li>
<p class="return"> <p class="return">
The method returns 1 in case of success, or The method returns 1 in case of success, or
<tt>nil</tt> followed by an error message otherwise. <b><tt>nil</tt></b> followed by an error message otherwise.
</p> </p>
<p class="note"> <p class="note">
@ -356,7 +356,7 @@ give up and fail with an error code.
<p class="parameters"> <p class="parameters">
The amount of time to wait is specified as The amount of time to wait is specified as
the <tt>value</tt> parameter, in seconds. The <tt>nil</tt> timeout the <tt>value</tt> parameter, in seconds. The <b><tt>nil</tt></b> timeout
<tt>value</tt> allows operations to block indefinitely. Negative <tt>value</tt> allows operations to block indefinitely. Negative
timeout values have the same effect. timeout values have the same effect.
</p> </p>

View File

@ -148,7 +148,7 @@ component.
<p class=parameters> <p class=parameters>
<tt>Segments</tt> is a list of strings with the <tt>&lt;segment&gt;</tt> <tt>Segments</tt> is a list of strings with the <tt>&lt;segment&gt;</tt>
parts. If <tt>unsafe</tt> is anything but <tt>nil</tt>, reserved parts. If <tt>unsafe</tt> is anything but <b><tt>nil</tt></b>, reserved
characters are left untouched. characters are left untouched.
</p> </p>

View File

@ -1,6 +1,11 @@
local base64 = socket.mime.base64.encode() local convert
local split = socket.mime.split() if arg and arg[1] == '-d' then
local convert = socket.mime.chain(base64, split) convert = socket.mime.decode("base64")
else
local base64 = socket.mime.encode("base64")
local wrap = socket.mime.wrap()
convert = socket.mime.chain(base64, wrap)
end
while 1 do while 1 do
local chunk = io.read(4096) local chunk = io.read(4096)
io.write(convert(chunk)) io.write(convert(chunk))

View File

@ -19,11 +19,13 @@
static int inet_global_toip(lua_State *L); static int inet_global_toip(lua_State *L);
static int inet_global_tohostname(lua_State *L); static int inet_global_tohostname(lua_State *L);
static void inet_pushresolved(lua_State *L, struct hostent *hp); static void inet_pushresolved(lua_State *L, struct hostent *hp);
static int inet_global_gethostname(lua_State *L);
/* DNS functions */ /* DNS functions */
static luaL_reg func[] = { static luaL_reg func[] = {
{ "toip", inet_global_toip }, { "toip", inet_global_toip },
{ "tohostname", inet_global_tohostname }, { "tohostname", inet_global_tohostname },
{ "gethostname", inet_global_gethostname},
{ NULL, NULL} { NULL, NULL}
}; };
@ -101,6 +103,25 @@ static int inet_global_tohostname(lua_State *L)
return 2; return 2;
} }
/*-------------------------------------------------------------------------*\
* Gets the host name
\*-------------------------------------------------------------------------*/
static int inet_global_gethostname(lua_State *L)
{
char name[257];
name[256] = '\0';
if (gethostname(name, 256) < 0) {
lua_pushnil(L);
lua_pushstring(L, "gethostname failed");
return 2;
} else {
lua_pushstring(L, name);
return 1;
}
}
/*=========================================================================*\ /*=========================================================================*\
* Lua methods * Lua methods
\*=========================================================================*/ \*=========================================================================*/

View File

@ -38,15 +38,8 @@
/*=========================================================================*\ /*=========================================================================*\
* Declarations * Declarations
\*=========================================================================*/ \*=========================================================================*/
static int global_gethostname(lua_State *L);
static int base_open(lua_State *L); static int base_open(lua_State *L);
/* functions in library namespace */
static luaL_reg func[] = {
{"gethostname", global_gethostname},
{NULL, NULL}
};
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Setup basic stuff. * Setup basic stuff.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
@ -70,29 +63,9 @@ static int base_open(lua_State *L)
lua_pushstring(L, "LUASOCKET_LIBNAME"); lua_pushstring(L, "LUASOCKET_LIBNAME");
lua_pushstring(L, LUASOCKET_LIBNAME); lua_pushstring(L, LUASOCKET_LIBNAME);
lua_settable(L, LUA_GLOBALSINDEX); lua_settable(L, LUA_GLOBALSINDEX);
/* define library functions */
luaL_openlib(L, LUASOCKET_LIBNAME, func, 0);
lua_pop(L, 1);
return 0; return 0;
} }
/*-------------------------------------------------------------------------*\
* Gets the host name
\*-------------------------------------------------------------------------*/
static int global_gethostname(lua_State *L)
{
char name[257];
name[256] = '\0';
if (gethostname(name, 256) < 0) {
lua_pushnil(L);
lua_pushstring(L, "gethostname failed");
return 2;
} else {
lua_pushstring(L, name);
return 1;
}
}
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Initializes all library modules. * Initializes all library modules.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/

View File

@ -27,12 +27,12 @@ static const char EQCRLF[3] = {'=', CR, LF};
/*=========================================================================*\ /*=========================================================================*\
* Internal function prototypes. * Internal function prototypes.
\*=========================================================================*/ \*=========================================================================*/
static int mime_global_fmt(lua_State *L); static int mime_global_wrp(lua_State *L);
static int mime_global_b64(lua_State *L); static int mime_global_b64(lua_State *L);
static int mime_global_unb64(lua_State *L); static int mime_global_unb64(lua_State *L);
static int mime_global_qp(lua_State *L); static int mime_global_qp(lua_State *L);
static int mime_global_unqp(lua_State *L); static int mime_global_unqp(lua_State *L);
static int mime_global_qpfmt(lua_State *L); static int mime_global_qpwrp(lua_State *L);
static int mime_global_eol(lua_State *L); static int mime_global_eol(lua_State *L);
static void b64setup(UC *b64unbase); static void b64setup(UC *b64unbase);
@ -54,10 +54,10 @@ static luaL_reg func[] = {
{ "eol", mime_global_eol }, { "eol", mime_global_eol },
{ "qp", mime_global_qp }, { "qp", mime_global_qp },
{ "unqp", mime_global_unqp }, { "unqp", mime_global_unqp },
{ "qpfmt", mime_global_qpfmt }, { "qpwrp", mime_global_qpwrp },
{ "b64", mime_global_b64 }, { "b64", mime_global_b64 },
{ "unb64", mime_global_unb64 }, { "unb64", mime_global_unb64 },
{ "fmt", mime_global_fmt }, { "wrp", mime_global_wrp },
{ NULL, NULL } { NULL, NULL }
}; };
@ -127,13 +127,13 @@ static const char *optlstring(lua_State *L, int n, const char *v, size_t *l)
\*=========================================================================*/ \*=========================================================================*/
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Incrementaly breaks a string into lines * Incrementaly breaks a string into lines
* A, n = fmt(l, B, length, marker) * A, n = wrp(l, B, length, marker)
* A is a copy of B, broken into lines of at most 'length' bytes. * A is a copy of B, broken into lines of at most 'length' bytes.
* 'l' is how many bytes are left for the first line of B. * 'l' is how many bytes are left for the first line of B.
* 'n' is the number of bytes left in the last line of A. * 'n' is the number of bytes left in the last line of A.
* Marker is the end-of-line marker. * Marker is the end-of-line marker.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static int mime_global_fmt(lua_State *L) static int mime_global_wrp(lua_State *L)
{ {
size_t size = 0; size_t size = 0;
int left = (int) luaL_checknumber(L, 1); int left = (int) luaL_checknumber(L, 1);
@ -526,14 +526,14 @@ static int mime_global_unqp(lua_State *L)
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Incrementally breaks a quoted-printed string into lines * Incrementally breaks a quoted-printed string into lines
* A, n = qpfmt(l, B, length) * A, n = qpwrp(l, B, length)
* A is a copy of B, broken into lines of at most 'length' bytes. * A is a copy of B, broken into lines of at most 'length' bytes.
* 'l' is how many bytes are left for the first line of B. * 'l' is how many bytes are left for the first line of B.
* 'n' is the number of bytes left in the last line of A. * 'n' is the number of bytes left in the last line of A.
* There are two complications: lines can't be broken in the middle * There are two complications: lines can't be broken in the middle
* of an encoded =XX, and there might be line breaks already * of an encoded =XX, and there might be line breaks already
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static int mime_global_qpfmt(lua_State *L) static int mime_global_qpwrp(lua_State *L)
{ {
size_t size = 0; size_t size = 0;
int left = (int) luaL_checknumber(L, 1); int left = (int) luaL_checknumber(L, 1);

View File

@ -19,7 +19,7 @@ local wt = {}
local function choose(table) local function choose(table)
return function(method, ...) return function(method, ...)
local f = table[method or "nil"] local f = table[method or "nil"]
if not f then return nil, "unknown method (" .. tostring(method) .. ")" if not f then error("unknown method (" .. tostring(method) .. ")", 3)
else return f(unpack(arg)) end else return f(unpack(arg)) end
end end
end end
@ -37,7 +37,15 @@ end
-- function that choose the encoding, decoding or wrap algorithm -- function that choose the encoding, decoding or wrap algorithm
encode = choose(et) encode = choose(et)
decode = choose(dt) decode = choose(dt)
wrap = choose(wt)
-- the wrap filter has default parameters
local cwt = choose(wt)
function wrap(...)
if not arg[1] or type(arg[1]) ~= "string" then
table.insert(arg, 1, "base64")
end
return cwt(unpack(arg))
end
-- define the encoding algorithms -- define the encoding algorithms
et['base64'] = function() et['base64'] = function()
@ -58,15 +66,14 @@ dt['quoted-printable'] = function()
end end
-- define the wrap algorithms -- define the wrap algorithms
wt['character'] = function(length) wt['base64'] = function(length, marker)
length = length or 76 length = length or 76
return cicle(fmt, length, length) return cicle(wrp, length, length, marker)
end end
wt['base64'] = wt['character']
wt['quoted-printable'] = function(length) wt['quoted-printable'] = function(length)
length = length or 76 length = length or 76
return cicle(qpfmt, length, length) return cicle(qpwrp, length, length)
end end
-- define the end-of-line translation function -- define the end-of-line translation function

View File

@ -12,7 +12,7 @@ socket.http.TIMEOUT = 5
local t = socket.time() local t = socket.time()
host = host or "diego.student.dyn.cs.princeton.edu" host = host or "diego-interface2.student.dyn.CS.Princeton.EDU"
proxy = proxy or "http://localhost:3128" proxy = proxy or "http://localhost:3128"
prefix = prefix or "/luasocket-test" prefix = prefix or "/luasocket-test"
cgiprefix = cgiprefix or "/luasocket-test-cgi" cgiprefix = cgiprefix or "/luasocket-test-cgi"

View File

@ -4,7 +4,7 @@ local qptest = "qptest.bin"
local eqptest = "qptest.bin2" local eqptest = "qptest.bin2"
local dqptest = "qptest.bin3" local dqptest = "qptest.bin3"
local b64test = "luasocket.exe" local b64test = "luasocket"
local eb64test = "b64test.bin" local eb64test = "b64test.bin"
local db64test = "b64test.bin2" local db64test = "b64test.bin2"
@ -155,10 +155,10 @@ local function encode_b64test()
local e2 = socket.mime.encode("base64") local e2 = socket.mime.encode("base64")
local e3 = socket.mime.encode("base64") local e3 = socket.mime.encode("base64")
local e4 = socket.mime.encode("base64") local e4 = socket.mime.encode("base64")
local sp4 = socket.mime.wrap("character") local sp4 = socket.mime.wrap()
local sp3 = socket.mime.wrap("character", 59) local sp3 = socket.mime.wrap(59)
local sp2 = socket.mime.wrap("character", 30) local sp2 = socket.mime.wrap("base64", 30)
local sp1 = socket.mime.wrap("character", 27) local sp1 = socket.mime.wrap(27)
local chain = socket.mime.chain(e1, sp1, e2, sp2, e3, sp3, e4, sp4) local chain = socket.mime.chain(e1, sp1, e2, sp2, e3, sp3, e4, sp4)
transform(b64test, eb64test, chain) transform(b64test, eb64test, chain)
end end

View File

@ -378,7 +378,7 @@ end
------------------------------------------------------------------------ ------------------------------------------------------------------------
function accept_errors() function accept_errors()
io.write("not listenning: ") io.write("not listening: ")
local d, e = socket.bind("*", 0) local d, e = socket.bind("*", 0)
assert(d, e); assert(d, e);
local c, e = socket.tcp(); local c, e = socket.tcp();
@ -392,7 +392,7 @@ function accept_errors()
assert(c, e); assert(c, e);
d:setfd(c:getfd()) d:setfd(c:getfd())
local r, e = d:accept() local r, e = d:accept()
assert(not r and e == "not supported", e) assert(not r and e == "not supported" or e == "not listening", e)
print("ok") print("ok")
end end