2 Commits

Author SHA1 Message Date
6a646f62a6 Merge 4956347952 into 58c76080a0 2025-02-28 19:28:41 -03:00
4956347952 Add option for SO_EXCLUSIVEADDRUSE 2025-02-27 15:40:35 -06:00
8 changed files with 95 additions and 45 deletions

View File

@ -25,10 +25,8 @@ jobs:
uses: luarocks/gh-actions-lua@v10
with:
luaVersion: ${{ matrix.luaVersion }}
buildCache: false
- name: Setup luarocks
# master branch until tagged release has luajit & msvcrt fixes
uses: luarocks/gh-actions-luarocks@master
uses: luarocks/gh-actions-luarocks@v5
- name: Make and install
run: |
luarocks make -- luasocket-scm-3.rockspec

View File

@ -37,30 +37,70 @@ Installation">
<!-- installation ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<h2>Installation via luarocks</h2>
<h2>Installation</h2>
<p> Here we describe the standard distribution. If the
standard doesn't meet your needs, we refer you to the Lua
discussion list, where any question about the package scheme
will likely already have been answered. </p>
<h3>Directory structure</h3>
<p>LuaSocket can be easily installed using <a href="https://luarocks.org/" target="_blank">LuaRocks</a>, the Lua package manager.</p>
<p> On Unix systems, the standard distribution uses two base
directories, one for system dependent files, and another for system
independent files. Let's call these directories <tt>&lt;CDIR&gt;</tt>
and <tt>&lt;LDIR&gt;</tt>, respectively.
For example, in my laptp, Lua&nbsp;5.1 is configured to
use '<tt>/usr/local/lib/lua/5.1</tt>' for
<tt>&lt;CDIR&gt;</tt> and '<tt>/usr/local/share/lua/5.1</tt>' for
<tt>&lt;LDIR&gt;</tt>. On Windows, <tt>&lt;CDIR&gt;</tt>
usually points to the directory where the Lua executable is
found, and <tt>&lt;LDIR&gt;</tt> points to a
<tt>lua/</tt> directory inside <tt>&lt;CDIR&gt;</tt>. (These
settings can be overridden by environment variables
<tt>LUA_PATH</tt> and <tt>LUA_CPATH</tt>. See the Lua
documentation for details.) Here is the standard LuaSocket
distribution directory structure:</p>
<h3>Installing via LuaRocks</h3>
<p>Run the following command in your terminal:</p>
<pre class=example>
luarocks install luasocket
&lt;LDIR&gt;/ltn12.lua
&lt;LDIR&gt;/socket.lua
&lt;CDIR&gt;/socket/core.dll
&lt;LDIR&gt;/socket/http.lua
&lt;LDIR&gt;/socket/tp.lua
&lt;LDIR&gt;/socket/ftp.lua
&lt;LDIR&gt;/socket/smtp.lua
&lt;LDIR&gt;/socket/url.lua
&lt;LDIR&gt;/mime.lua
&lt;CDIR&gt;/mime/core.dll
</pre>
<h3>Verification</h3>
<p>To verify that LuaSocket is installed correctly, open Lua and run:</p>
<pre class=example><code>
local socket = require("socket")
print(socket._VERSION)
</code></pre>
<p> Naturally, on Unix systems, <tt>core.dll</tt>
would be replaced by <tt>core.so</tt>.
</p>
<p>If you see output like <strong>LuaSocket 3.0</strong>, the installation was successful.</p>
<h3>Using LuaSocket</h3>
<h3>More Information</h3>
<p>For more details, visit the <a href="https://github.com/lunarmodules/luasocket" target="_blank">LuaSocket GitHub repository</a>.</p>
<p> With the above setup, and an interpreter with shared library support,
it should be easy to use LuaSocket. Just fire the interpreter and use the
<tt>require</tt> function to gain access to whatever module you need:</p>
<pre class=example>
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
&gt; socket = require("socket")
&gt; print(socket._VERSION)
--&gt; LuaSocket 3.1.0
</pre>
<p> Each module loads their dependencies automatically, so you only need to
load the modules you directly depend upon: </p>
<pre class=example>
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
&gt; http = require("socket.http")
&gt; print(http.request("http://www.impa.br/~diego/software/luasocket"))
--&gt; homepage gets dumped to terminal
</pre>
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

View File

@ -10,7 +10,7 @@
# print print the build settings
PLAT?= linux
PLATS= macosx linux win32 win64 mingw freebsd solaris ucrt64
PLATS= macosx linux win32 win64 mingw freebsd solaris
all: $(PLAT)

View File

@ -74,13 +74,6 @@ LUAPREFIX_mingw?=/usr
CDIR_mingw?=lua/$(LUAV)
LDIR_mingw?=lua/$(LUAV)/lua
# where lua headers are found for ucrt64 builds
# LUAINC_ucrt64:
LUAINC_ucrt64?=/ucrt64/include
LUALIB_ucrt64?=/ucrt64/bin/lua$(subst .,,$(LUAV)).dll
LUAPREFIX_ucrt64?=/ucrt64
CDIR_ucrt64?=lib/lua/$(LUAV)
LDIR_ucrt64?=share/lua/$(LUAV)
# LUAINC_win32:
# LUALIB_win32:
@ -160,7 +153,7 @@ print:
#------
# Supported platforms
#
PLATS= macosx linux win32 win64 mingw solaris ucrt64
PLATS= macosx linux win32 win64 mingw solaris
#------
# Compiler and linker settings
@ -226,21 +219,6 @@ LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o
LD_mingw=gcc
SOCKET_mingw=wsocket.o
#------
# Compiler and linker settings
# for ucrt64
SO_ucrt64=dll
O_ucrt64=o
CC_ucrt64=gcc
DEF_ucrt64= -DLUASOCKET_$(DEBUG) \
-DWINVER=0x0501
CFLAGS_ucrt64= -I$(LUAINC) $(DEF) -Wall -O2 -fno-common
# \
-fvisibility=hidden
LDFLAGS_ucrt64= $(LUALIB) -shared -Wl,-s -lws2_32 -o
LD_ucrt64=gcc
SOCKET_ucrt64=wsocket.o
#------
# Compiler and linker settings
@ -406,9 +384,6 @@ linux:
mingw:
$(MAKE) all PLAT=mingw
ucrt64:
$(MAKE) all PLAT=ucrt64
solaris:
$(MAKE) all-unix PLAT=solaris

View 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)

View File

@ -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);

View 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

View 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},