mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-13 22:24:28 +02:00
Compare commits
20 Commits
hjelmeland
...
1a3236dd0b
Author | SHA1 | Date | |
---|---|---|---|
1a3236dd0b | |||
4956347952 | |||
66cdeca663 | |||
676e5f3501 | |||
4dad084cfd | |||
1fad162690 | |||
e3ca4a767a | |||
93eef5015e | |||
23241717bf | |||
98be8d9fc1 | |||
fa69770e52 | |||
13f2b3c663 | |||
453a5207ed | |||
de359ea408 | |||
c93f9154e1 | |||
8a5368b659 | |||
22b8202d70 | |||
3a817a56eb | |||
7eaf648056 | |||
bef62aeb50 |
@ -55,7 +55,7 @@ protocol. For that, check the implementation.
|
||||
|
||||
<p>
|
||||
To really benefit from this module, a good understanding of
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">
|
||||
LTN012, Filters sources and sinks</a> is necessary.
|
||||
</p>
|
||||
|
||||
@ -122,7 +122,7 @@ expects at least the fields <tt>host</tt>, <tt>sink</tt>, and one of
|
||||
<tt>argument</tt> or <tt>path</tt> (<tt>argument</tt> takes
|
||||
precedence). <tt>Host</tt> is the server to connect to. <tt>Sink</tt> is
|
||||
the <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
sink that will receive the downloaded data. <tt>Argument</tt> or
|
||||
<tt>path</tt> give the target path to the resource in the server. The
|
||||
optional arguments are the following:
|
||||
@ -136,7 +136,7 @@ authentication. Defaults to "<tt>ftp:anonymous@anonymous.org</tt>";</li>
|
||||
<li><tt>type</tt>: The transfer mode. Can take values "<tt>i</tt>" or
|
||||
"<tt>a</tt>". Defaults to whatever is the server default;</li>
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
pump step function used to pass data from the
|
||||
server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;</li>
|
||||
<li><tt>create</tt>: An optional function to be used instead of
|
||||
@ -206,7 +206,7 @@ expects at least the fields <tt>host</tt>, <tt>source</tt>, and one of
|
||||
<tt>argument</tt> or <tt>path</tt> (<tt>argument</tt> takes
|
||||
precedence). <tt>Host</tt> is the server to connect to. <tt>Source</tt> is
|
||||
the <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
source that will provide the contents to be uploaded.
|
||||
<tt>Argument</tt> or
|
||||
<tt>path</tt> give the target path to the resource in the server. The
|
||||
@ -221,7 +221,7 @@ authentication. Defaults to "<tt>ftp:anonymous@anonymous.org</tt>";</li>
|
||||
<li><tt>type</tt>: The transfer mode. Can take values "<tt>i</tt>" or
|
||||
"<tt>a</tt>". Defaults to whatever is the server default;</li>
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
pump step function used to pass data from the
|
||||
server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;</li>
|
||||
<li><tt>create</tt>: An optional function to be used instead of
|
||||
|
@ -52,7 +52,7 @@ implementation conforms to the HTTP/1.1 standard,
|
||||
The module exports functions that provide HTTP functionality in different
|
||||
levels of abstraction. From the simple
|
||||
string oriented requests, through generic
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> based, down to even lower-level if you bother to look through the source code.
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> based, down to even lower-level if you bother to look through the source code.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@ -144,7 +144,7 @@ http.<b>request{</b><br>
|
||||
The request function has two forms. The simple form downloads
|
||||
a URL using the <tt>GET</tt> or <tt>POST</tt> method and is based
|
||||
on strings. The generic form performs any HTTP method and is
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> based.
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> based.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
@ -158,7 +158,7 @@ in the <tt>url</tt>. Otherwise, it performs a <tt>GET</tt> in the
|
||||
<p class="parameters">
|
||||
If the first argument is instead a table, the most important fields are
|
||||
the <tt>url</tt> and the <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
<tt>sink</tt> that will receive the downloaded content.
|
||||
Any part of the <tt>url</tt> can be overridden by including
|
||||
the appropriate field in the request table.
|
||||
@ -172,13 +172,13 @@ following:
|
||||
<li><tt>method</tt>: The HTTP request method. Defaults to "GET";</li>
|
||||
<li><tt>headers</tt>: Any additional HTTP headers to send with the request;</li>
|
||||
<li><tt>source</tt>: <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
source to provide the request body. If there
|
||||
is a body, you need to provide an appropriate "<tt>content-length</tt>"
|
||||
request header field, or the function will attempt to send the body as
|
||||
"<tt>chunked</tt>" (something few servers support). Defaults to the empty source;</li>
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
pump step function used to move data.
|
||||
Defaults to the LTN12 <tt>pump.step</tt> function.</li>
|
||||
<li><tt>proxy</tt>: The URL of a proxy server to use. Defaults to no proxy;</li>
|
||||
|
@ -89,7 +89,7 @@ it should be easy to use LuaSocket. Just fire the interpreter and use the
|
||||
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
|
||||
> socket = require("socket")
|
||||
> print(socket._VERSION)
|
||||
--> LuaSocket 3.0.0
|
||||
--> LuaSocket 3.1.0
|
||||
</pre>
|
||||
|
||||
<p> Each module loads their dependencies automatically, so you only need to
|
||||
|
@ -40,7 +40,7 @@ Pump, Support, Library">
|
||||
<h2 id="ltn12">LTN12</h2>
|
||||
|
||||
<p> The <tt>ltn12</tt> namespace implements the ideas described in
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">
|
||||
LTN012, Filters sources and sinks</a>. This manual simply describes the
|
||||
functions. Please refer to the LTN for a deeper explanation of the
|
||||
functionality provided by this module.
|
||||
|
@ -54,7 +54,7 @@ MIME is described mainly in
|
||||
<p>
|
||||
All functionality provided by the MIME module
|
||||
follows the ideas presented in
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">
|
||||
LTN012, Filters sources and sinks</a>.
|
||||
</p>
|
||||
|
||||
|
@ -57,7 +57,7 @@ of the MIME standard, but described mainly
|
||||
in <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a>.</p>
|
||||
|
||||
<p> In the description below, good understanding of <a
|
||||
href="http://lua-users.org/wiki/FiltersSourcesAndSinks"> LTN012, Filters
|
||||
href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md"> LTN012, Filters
|
||||
sources and sinks</a> and the <a href="mime.html">MIME</a> module is
|
||||
assumed. In fact, the SMTP module was the main reason for their
|
||||
creation. </p>
|
||||
@ -122,7 +122,7 @@ smtp.<b>message(</b>mesgt<b>)</b>
|
||||
|
||||
<p class="description">
|
||||
Returns a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep).
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep).
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
@ -155,7 +155,7 @@ multipart-mesgt = {<br>
|
||||
For a simple message, all that is needed is a set of <tt>headers</tt>
|
||||
and the <tt>body</tt>. The message <tt>body</tt> can be given as a string
|
||||
or as a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
source. For multipart messages, the body is a table that
|
||||
recursively defines each part as an independent message, plus an optional
|
||||
<tt>preamble</tt> and <tt>epilogue</tt>.
|
||||
@ -163,7 +163,7 @@ recursively defines each part as an independent message, plus an optional
|
||||
|
||||
<p class="return">
|
||||
The function returns a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
source that produces the
|
||||
message contents as defined by <tt>mesgt</tt>, chunk by chunk.
|
||||
Hopefully, the following
|
||||
@ -264,7 +264,7 @@ The sender is given by the e-mail address in the <tt>from</tt> field.
|
||||
address, or a string
|
||||
in case there is just one recipient.
|
||||
The contents of the message are given by a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
<tt>source</tt>. Several arguments are optional:
|
||||
</p>
|
||||
<ul>
|
||||
@ -276,7 +276,7 @@ methods if supported by the server (both are unsafe);</li>
|
||||
<li> <tt>domain</tt>: Domain name used to greet the server; Defaults to the
|
||||
local machine host name;</li>
|
||||
<li> <tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
pump step function used to pass data from the
|
||||
source to the server. Defaults to the LTN12 <tt>pump.step</tt> function;</li>
|
||||
<li><tt>create</tt>: An optional function to be used instead of
|
||||
@ -308,7 +308,7 @@ Only recipients specified in the <tt>rcpt</tt> list will receive a copy of the
|
||||
message. Each recipient of an SMTP mail message receives a copy of the
|
||||
message body along with the headers, and nothing more. The headers
|
||||
<em>are</em> part of the message and should be produced by the
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
<tt>source</tt> function. The <tt>rcpt</tt> list is <em>not</em>
|
||||
part of the message and will not be sent to anyone.
|
||||
</p>
|
||||
|
@ -164,6 +164,9 @@ Creates and returns a <em>clean</em>
|
||||
<a href="#try"><tt>try</tt></a>
|
||||
function that allows for cleanup before the exception
|
||||
is raised.
|
||||
This implements the ideas described in
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn013.md">
|
||||
LTN012, Using finalized exceptions</a>.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
@ -207,6 +210,9 @@ Converts a function that throws exceptions into a safe function. This
|
||||
function only catches exceptions thrown by the <a href="#try"><tt>try</tt></a>
|
||||
and <a href="#newtry"><tt>newtry</tt></a> functions. It does not catch normal
|
||||
Lua errors.
|
||||
This implements the ideas described in
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn013.md">
|
||||
LTN012, Using finalized exceptions</a>.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
@ -305,7 +311,7 @@ socket.<b>sink(</b>mode, socket<b>)</b>
|
||||
|
||||
<p class="description">
|
||||
Creates an
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
sink from a stream socket object.
|
||||
</p>
|
||||
|
||||
@ -380,7 +386,7 @@ socket.<b>source(</b>mode, socket [, length]<b>)</b>
|
||||
|
||||
<p class="description">
|
||||
Creates an
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
||||
source from a stream socket object.
|
||||
</p>
|
||||
|
||||
@ -425,6 +431,9 @@ socket.<b>try(</b>ret<sub>1</sub> [, ret<sub>2</sub> ... ret<sub>N</sub>]<b>)</b
|
||||
Throws an exception in case <tt>ret<sub>1</sub></tt> is falsy, using
|
||||
<tt>ret<sub>2</sub></tt> as the error message. The exception is supposed to be caught
|
||||
by a <a href="#protect"><tt>protect</tt></a>ed function only.
|
||||
This implements the ideas described in
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn013.md">
|
||||
LTN012, Using finalized exceptions</a>.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
|
@ -149,8 +149,8 @@ wild-card address).
|
||||
<!-- gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="gettimeout">
|
||||
connected:<b>settimeout(</b>value<b>)</b><br>
|
||||
unconnected:<b>settimeout(</b>value<b>)</b>
|
||||
connected:<b>gettimeout()</b><br>
|
||||
unconnected:<b>gettimeout()</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
|
@ -69,6 +69,7 @@ local function make_plat(plat)
|
||||
["socket.smtp"] = "src/smtp.lua",
|
||||
ltn12 = "src/ltn12.lua",
|
||||
socket = "src/socket.lua",
|
||||
mbox = "src/mbox.lua",
|
||||
mime = "src/mime.lua"
|
||||
}
|
||||
if plat == "unix"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#--------------------------------------------------------------------------
|
||||
# Distribution makefile
|
||||
#--------------------------------------------------------------------------
|
||||
DIST = luasocket-3.0.0
|
||||
DIST = luasocket-3.1.0
|
||||
|
||||
TEST = \
|
||||
test/README \
|
||||
|
0
mime.vcxproj
Executable file → Normal file
0
mime.vcxproj
Executable file → Normal file
0
socket.vcxproj
Executable file → Normal file
0
socket.vcxproj
Executable file → Normal file
19
src/http.lua
19
src/http.lua
@ -54,7 +54,7 @@ local function receiveheaders(sock, headers)
|
||||
while line ~= "" do
|
||||
-- get field-name and value
|
||||
name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)"))
|
||||
if not (name and value) then return nil, "malformed reponse headers" end
|
||||
if not (name and value) then return nil, "malformed response headers" end
|
||||
name = string.lower(name)
|
||||
-- get next line (value might be folded)
|
||||
line, err = sock:receive()
|
||||
@ -62,7 +62,7 @@ local function receiveheaders(sock, headers)
|
||||
-- unfold any folded values
|
||||
while string.find(line, "^%s") do
|
||||
value = value .. line
|
||||
line = sock:receive()
|
||||
line, err = sock:receive()
|
||||
if err then return nil, err end
|
||||
end
|
||||
-- save pair in table
|
||||
@ -81,7 +81,7 @@ socket.sourcet["http-chunked"] = function(sock, headers)
|
||||
dirty = function() return sock:dirty() end
|
||||
}, {
|
||||
__call = function()
|
||||
-- get chunk size, skip extention
|
||||
-- get chunk size, skip extension
|
||||
local line, err = sock:receive()
|
||||
if err then return nil, err end
|
||||
local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
|
||||
@ -219,9 +219,11 @@ local function adjustproxy(reqt)
|
||||
local proxy = reqt.proxy or _M.PROXY
|
||||
if proxy then
|
||||
proxy = url.parse(proxy)
|
||||
return proxy.host, proxy.port or 3128
|
||||
proxy.port = proxy.port or 3128
|
||||
proxy.create = SCHEMES[proxy.scheme].create(reqt)
|
||||
return proxy.host, proxy.port, proxy.create
|
||||
else
|
||||
return reqt.host, reqt.port
|
||||
return reqt.host, reqt.port, reqt.create
|
||||
end
|
||||
end
|
||||
|
||||
@ -279,7 +281,7 @@ local function adjustrequest(reqt)
|
||||
if not (host and host ~= "") then
|
||||
socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'")
|
||||
end
|
||||
-- compute uri if user hasn't overriden
|
||||
-- compute uri if user hasn't overridden
|
||||
nreqt.uri = reqt.uri or adjusturi(nreqt)
|
||||
-- adjust headers in request
|
||||
nreqt.headers = adjustheaders(nreqt)
|
||||
@ -291,7 +293,10 @@ local function adjustrequest(reqt)
|
||||
end
|
||||
|
||||
-- ajust host and port if there is a proxy
|
||||
nreqt.host, nreqt.port = adjustproxy(nreqt)
|
||||
local proxy_create
|
||||
nreqt.host, nreqt.port, proxy_create = adjustproxy(nreqt)
|
||||
if not reqt.create then nreqt.create = proxy_create end
|
||||
|
||||
return nreqt
|
||||
end
|
||||
|
||||
|
2
src/inet.c
Executable file → Normal file
2
src/inet.c
Executable file → Normal file
@ -290,7 +290,7 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
|
||||
return 2;
|
||||
}
|
||||
lua_pushstring(L, name);
|
||||
lua_pushstring(L, port);
|
||||
lua_pushinteger(L, (int) strtol(port, (char **) NULL, 10));
|
||||
switch (family) {
|
||||
case AF_INET: lua_pushliteral(L, "inet"); break;
|
||||
case AF_INET6: lua_pushliteral(L, "inet6"); break;
|
||||
|
0
src/luasocket.c
Executable file → Normal file
0
src/luasocket.c
Executable file → Normal file
@ -10,7 +10,7 @@
|
||||
/*-------------------------------------------------------------------------* \
|
||||
* Current socket library version
|
||||
\*-------------------------------------------------------------------------*/
|
||||
#define LUASOCKET_VERSION "LuaSocket 3.0.0"
|
||||
#define LUASOCKET_VERSION "LuaSocket 3.1.0"
|
||||
#define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab"
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
|
4
src/makefile
Executable file → Normal file
4
src/makefile
Executable file → Normal file
@ -1,6 +1,6 @@
|
||||
# luasocket src/makefile
|
||||
#
|
||||
# Definitions in this section can be overriden on the command line or in the
|
||||
# Definitions in this section can be overridden on the command line or in the
|
||||
# environment.
|
||||
#
|
||||
# These are equivalent:
|
||||
@ -272,7 +272,7 @@ SOCKET_win64=wsocket.obj
|
||||
#
|
||||
SO=$(SO_$(PLAT))
|
||||
O=$(O_$(PLAT))
|
||||
SOCKET_V=3.0.0
|
||||
SOCKET_V=3.1.0
|
||||
MIME_V=1.0.3
|
||||
SOCKET_SO=socket-$(SOCKET_V).$(SO)
|
||||
MIME_SO=mime-$(MIME_V).$(SO)
|
||||
|
0
src/mime.c
Executable file → Normal file
0
src/mime.c
Executable file → Normal file
@ -93,6 +93,26 @@ int opt_get_reuseaddr(lua_State *L, p_socket ps)
|
||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
/* enables reuse of local address */
|
||||
int opt_set_exclusiveaddruse(lua_State* L, p_socket ps)
|
||||
{
|
||||
#ifndef SO_EXCLUSIVEADDRUSE
|
||||
return luaL_error(L, "SO_EXCLUSIVEADDRUSE is not supported on this operating system");
|
||||
#else
|
||||
return opt_setboolean(L, ps, SOL_SOCKET, SO_EXCLUSIVEADDRUSE);
|
||||
#endif
|
||||
}
|
||||
|
||||
int opt_get_exclusiveaddruse(lua_State* L, p_socket ps)
|
||||
{
|
||||
#ifndef SO_EXCLUSIVEADDRUSE
|
||||
return luaL_error(L, "SO_EXCLUSIVEADDRUSE is not supported on this operating system");
|
||||
#else
|
||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_EXCLUSIVEADDRUSE);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
/* enables reuse of local port */
|
||||
int opt_set_reuseport(lua_State *L, p_socket ps)
|
||||
|
@ -28,6 +28,11 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps);
|
||||
int opt_set_reuseaddr(lua_State *L, p_socket ps);
|
||||
int opt_get_reuseaddr(lua_State *L, p_socket ps);
|
||||
|
||||
#ifdef SO_EXCLUSIVEADDRUSE
|
||||
int opt_set_exclusiveaddruse(lua_State* L, p_socket ps);
|
||||
int opt_get_exclusiveaddruse(lua_State* L, p_socket ps);
|
||||
#endif
|
||||
|
||||
int opt_set_reuseport(lua_State *L, p_socket ps);
|
||||
int opt_get_reuseport(lua_State *L, p_socket ps);
|
||||
|
||||
|
@ -225,7 +225,7 @@ local function adjust_headers(mesgt)
|
||||
lower["date"] = lower["date"] or
|
||||
os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or _M.ZONE)
|
||||
lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
|
||||
-- this can't be overriden
|
||||
-- this can't be overridden
|
||||
lower["mime-version"] = "1.0"
|
||||
return lower
|
||||
end
|
||||
|
0
src/socket.h
Executable file → Normal file
0
src/socket.h
Executable file → Normal file
@ -74,6 +74,9 @@ static t_opt optget[] = {
|
||||
{"bindtodevice", opt_get_bindtodevice},
|
||||
{"keepalive", opt_get_keepalive},
|
||||
{"reuseaddr", opt_get_reuseaddr},
|
||||
#ifdef SO_EXCLUSIVEADDRUSE
|
||||
{"exclusiveaddruse", opt_get_exclusiveaddruse},
|
||||
#endif
|
||||
{"reuseport", opt_get_reuseport},
|
||||
{"tcp-nodelay", opt_get_tcp_nodelay},
|
||||
#ifdef TCP_KEEPIDLE
|
||||
@ -96,6 +99,9 @@ static t_opt optset[] = {
|
||||
{"bindtodevice", opt_set_bindtodevice},
|
||||
{"keepalive", opt_set_keepalive},
|
||||
{"reuseaddr", opt_set_reuseaddr},
|
||||
#ifdef SO_EXCLUSIVEADDRUSE
|
||||
{"exclusiveaddruse", opt_set_exclusiveaddruse},
|
||||
#endif
|
||||
{"reuseport", opt_set_reuseport},
|
||||
{"tcp-nodelay", opt_set_tcp_nodelay},
|
||||
#ifdef TCP_KEEPIDLE
|
||||
|
6
src/udp.c
Executable file → Normal file
6
src/udp.c
Executable file → Normal file
@ -74,6 +74,9 @@ static t_opt optset[] = {
|
||||
{"dontroute", opt_set_dontroute},
|
||||
{"broadcast", opt_set_broadcast},
|
||||
{"reuseaddr", opt_set_reuseaddr},
|
||||
#ifdef SO_EXCLUSIVEADDRUSE
|
||||
{"exclusiveaddruse", opt_set_exclusiveaddruse},
|
||||
#endif
|
||||
{"reuseport", opt_set_reuseport},
|
||||
{"ip-multicast-if", opt_set_ip_multicast_if},
|
||||
{"ip-multicast-ttl", opt_set_ip_multicast_ttl},
|
||||
@ -96,6 +99,9 @@ static t_opt optget[] = {
|
||||
{"dontroute", opt_get_dontroute},
|
||||
{"broadcast", opt_get_broadcast},
|
||||
{"reuseaddr", opt_get_reuseaddr},
|
||||
#ifdef SO_EXCLUSIVEADDRUSE
|
||||
{"exclusiveaddruse", opt_get_exclusiveaddruse},
|
||||
#endif
|
||||
{"reuseport", opt_get_reuseport},
|
||||
{"ip-multicast-if", opt_get_ip_multicast_if},
|
||||
{"ip-multicast-loop", opt_get_ip_multicast_loop},
|
||||
|
@ -16,13 +16,6 @@
|
||||
|
||||
#define UNIXDGRAM_DATAGRAMSIZE 8192
|
||||
|
||||
/* provide a SUN_LEN macro if sys/un.h doesn't (e.g. Android) */
|
||||
#ifndef SUN_LEN
|
||||
#define SUN_LEN(ptr) \
|
||||
((size_t) (((struct sockaddr_un *) 0)->sun_path) \
|
||||
+ strlen ((ptr)->sun_path))
|
||||
#endif
|
||||
|
||||
/*=========================================================================*\
|
||||
* Internal function prototypes
|
||||
\*=========================================================================*/
|
||||
@ -42,8 +35,8 @@ static int meth_receivefrom(lua_State *L);
|
||||
static int meth_sendto(lua_State *L);
|
||||
static int meth_getsockname(lua_State *L);
|
||||
|
||||
static const char *unixdgram_tryconnect(p_unix un, const char *path);
|
||||
static const char *unixdgram_trybind(p_unix un, const char *path);
|
||||
static const char *unixdgram_tryconnect(p_unix un, const char *path, size_t len);
|
||||
static const char *unixdgram_trybind(p_unix un, const char *path, size_t len);
|
||||
|
||||
/* unixdgram object methods */
|
||||
static luaL_Reg unixdgram_methods[] = {
|
||||
@ -133,13 +126,12 @@ static int meth_send(lua_State *L)
|
||||
static int meth_sendto(lua_State *L)
|
||||
{
|
||||
p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1);
|
||||
size_t count, sent = 0;
|
||||
size_t count, sent, len = 0;
|
||||
const char *data = luaL_checklstring(L, 2, &count);
|
||||
const char *path = luaL_checkstring(L, 3);
|
||||
const char *path = luaL_checklstring(L, 3, &len);
|
||||
p_timeout tm = &un->tm;
|
||||
int err;
|
||||
struct sockaddr_un remote;
|
||||
size_t len = strlen(path);
|
||||
|
||||
if (len >= sizeof(remote.sun_path)) {
|
||||
lua_pushnil(L);
|
||||
@ -148,7 +140,7 @@ static int meth_sendto(lua_State *L)
|
||||
}
|
||||
|
||||
memset(&remote, 0, sizeof(remote));
|
||||
strcpy(remote.sun_path, path);
|
||||
memcpy(remote.sun_path, path, len);
|
||||
remote.sun_family = AF_UNIX;
|
||||
timeout_markstart(tm);
|
||||
#ifdef UNIX_HAS_SUN_LEN
|
||||
@ -264,18 +256,22 @@ static int meth_dirty(lua_State *L) {
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Binds an object to an address
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static const char *unixdgram_trybind(p_unix un, const char *path) {
|
||||
static const char *unixdgram_trybind(p_unix un, const char *path, size_t len) {
|
||||
struct sockaddr_un local;
|
||||
size_t len = strlen(path);
|
||||
int err;
|
||||
if (len >= sizeof(local.sun_path)) return "path too long";
|
||||
memset(&local, 0, sizeof(local));
|
||||
strcpy(local.sun_path, path);
|
||||
memcpy(local.sun_path, path, len);
|
||||
local.sun_family = AF_UNIX;
|
||||
size_t addrlen = SUN_LEN(&local);
|
||||
#ifdef UNIX_HAS_SUN_LEN
|
||||
local.sun_len = addrlen + 1;
|
||||
local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len)
|
||||
+ len + 1;
|
||||
err = socket_bind(&un->sock, (SA *) &local, local.sun_len);
|
||||
|
||||
#else
|
||||
err = socket_bind(&un->sock, (SA *) &local,
|
||||
sizeof(local.sun_family) + len);
|
||||
#endif
|
||||
int err = socket_bind(&un->sock, (SA *) &local, addrlen);
|
||||
if (err != IO_DONE) socket_destroy(&un->sock);
|
||||
return socket_strerror(err);
|
||||
}
|
||||
@ -283,8 +279,9 @@ static const char *unixdgram_trybind(p_unix un, const char *path) {
|
||||
static int meth_bind(lua_State *L)
|
||||
{
|
||||
p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1);
|
||||
const char *path = luaL_checkstring(L, 2);
|
||||
const char *err = unixdgram_trybind(un, path);
|
||||
size_t len;
|
||||
const char *path = luaL_checklstring(L, 2, &len);
|
||||
const char *err = unixdgram_trybind(un, path, len);
|
||||
if (err) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, err);
|
||||
@ -313,20 +310,23 @@ static int meth_getsockname(lua_State *L)
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Turns a master unixdgram object into a client object.
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static const char *unixdgram_tryconnect(p_unix un, const char *path)
|
||||
static const char *unixdgram_tryconnect(p_unix un, const char *path, size_t len)
|
||||
{
|
||||
struct sockaddr_un remote;
|
||||
size_t len = strlen(path);
|
||||
int err;
|
||||
if (len >= sizeof(remote.sun_path)) return "path too long";
|
||||
memset(&remote, 0, sizeof(remote));
|
||||
strcpy(remote.sun_path, path);
|
||||
memcpy(remote.sun_path, path, len);
|
||||
remote.sun_family = AF_UNIX;
|
||||
timeout_markstart(&un->tm);
|
||||
size_t addrlen = SUN_LEN(&remote);
|
||||
#ifdef UNIX_HAS_SUN_LEN
|
||||
remote.sun_len = addrlen + 1;
|
||||
remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len)
|
||||
+ len + 1;
|
||||
err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm);
|
||||
#else
|
||||
err = socket_connect(&un->sock, (SA *) &remote,
|
||||
sizeof(remote.sun_family) + len, &un->tm);
|
||||
#endif
|
||||
int err = socket_connect(&un->sock, (SA *) &remote, addrlen, &un->tm);
|
||||
if (err != IO_DONE) socket_destroy(&un->sock);
|
||||
return socket_strerror(err);
|
||||
}
|
||||
@ -334,8 +334,9 @@ static const char *unixdgram_tryconnect(p_unix un, const char *path)
|
||||
static int meth_connect(lua_State *L)
|
||||
{
|
||||
p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1);
|
||||
const char *path = luaL_checkstring(L, 2);
|
||||
const char *err = unixdgram_tryconnect(un, path);
|
||||
size_t len;
|
||||
const char *path = luaL_checklstring(L, 2, &len);
|
||||
const char *err = unixdgram_tryconnect(un, path, len);
|
||||
if (err) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, err);
|
||||
|
@ -33,8 +33,8 @@ static int meth_getstats(lua_State *L);
|
||||
static int meth_setstats(lua_State *L);
|
||||
static int meth_getsockname(lua_State *L);
|
||||
|
||||
static const char *unixstream_tryconnect(p_unix un, const char *path);
|
||||
static const char *unixstream_trybind(p_unix un, const char *path);
|
||||
static const char *unixstream_tryconnect(p_unix un, const char *path, size_t len);
|
||||
static const char *unixstream_trybind(p_unix un, const char *path, size_t len);
|
||||
|
||||
/* unixstream object methods */
|
||||
static luaL_Reg unixstream_methods[] = {
|
||||
@ -181,13 +181,12 @@ static int meth_accept(lua_State *L) {
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Binds an object to an address
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static const char *unixstream_trybind(p_unix un, const char *path) {
|
||||
static const char *unixstream_trybind(p_unix un, const char *path, size_t len) {
|
||||
struct sockaddr_un local;
|
||||
size_t len = strlen(path);
|
||||
int err;
|
||||
if (len >= sizeof(local.sun_path)) return "path too long";
|
||||
memset(&local, 0, sizeof(local));
|
||||
strcpy(local.sun_path, path);
|
||||
memcpy(local.sun_path, path, len);
|
||||
local.sun_family = AF_UNIX;
|
||||
#ifdef UNIX_HAS_SUN_LEN
|
||||
local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len)
|
||||
@ -204,8 +203,9 @@ static const char *unixstream_trybind(p_unix un, const char *path) {
|
||||
|
||||
static int meth_bind(lua_State *L) {
|
||||
p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1);
|
||||
const char *path = luaL_checkstring(L, 2);
|
||||
const char *err = unixstream_trybind(un, path);
|
||||
size_t len;
|
||||
const char *path = luaL_checklstring(L, 2, &len);
|
||||
const char *err = unixstream_trybind(un, path, len);
|
||||
if (err) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, err);
|
||||
@ -234,14 +234,13 @@ static int meth_getsockname(lua_State *L)
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Turns a master unixstream object into a client object.
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static const char *unixstream_tryconnect(p_unix un, const char *path)
|
||||
static const char *unixstream_tryconnect(p_unix un, const char *path, size_t len)
|
||||
{
|
||||
struct sockaddr_un remote;
|
||||
int err;
|
||||
size_t len = strlen(path);
|
||||
if (len >= sizeof(remote.sun_path)) return "path too long";
|
||||
memset(&remote, 0, sizeof(remote));
|
||||
strcpy(remote.sun_path, path);
|
||||
memcpy(remote.sun_path, path, len);
|
||||
remote.sun_family = AF_UNIX;
|
||||
timeout_markstart(&un->tm);
|
||||
#ifdef UNIX_HAS_SUN_LEN
|
||||
@ -259,8 +258,9 @@ static const char *unixstream_tryconnect(p_unix un, const char *path)
|
||||
static int meth_connect(lua_State *L)
|
||||
{
|
||||
p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1);
|
||||
const char *path = luaL_checkstring(L, 2);
|
||||
const char *err = unixstream_tryconnect(un, path);
|
||||
size_t len;
|
||||
const char *path = luaL_checklstring(L, 2, &len);
|
||||
const char *err = unixstream_tryconnect(un, path, len);
|
||||
if (err) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, err);
|
||||
|
@ -152,7 +152,7 @@ function _M.parse(url, default)
|
||||
url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
|
||||
function(s) parsed.scheme = s; return "" end)
|
||||
-- get authority
|
||||
url = string.gsub(url, "^//([^/]*)", function(n)
|
||||
url = string.gsub(url, "^//([^/%?#]*)", function(n)
|
||||
parsed.authority = n
|
||||
return ""
|
||||
end)
|
||||
|
2
src/wsocket.c
Executable file → Normal file
2
src/wsocket.c
Executable file → Normal file
@ -262,6 +262,7 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got,
|
||||
if (err != WSAEWOULDBLOCK) {
|
||||
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
||||
prev = err;
|
||||
continue;
|
||||
}
|
||||
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
||||
}
|
||||
@ -291,6 +292,7 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
||||
if (err != WSAEWOULDBLOCK) {
|
||||
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
||||
prev = err;
|
||||
continue;
|
||||
}
|
||||
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
||||
}
|
||||
|
Reference in New Issue
Block a user