2 Commits

Author SHA1 Message Date
62e3578bfd Merge 39a8b34e4a into e3ca4a767a 2024-05-24 13:28:58 +03:00
39a8b34e4a fix for slow tcp connect in non blocking mode 2016-09-19 14:55:09 +02:00
18 changed files with 74 additions and 49 deletions

View File

@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ]
platform: [ "ubuntu-22.04", "macos-14", "windows-2022" ]
platform: [ "ubuntu-22.04", "macos-11", "windows-2022" ]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
@ -22,13 +22,11 @@ jobs:
if: ${{ startsWith(matrix.platform, 'windows') && !startsWith(matrix.luaVersion, 'luajit') }}
uses: ilammy/msvc-dev-cmd@v1
- name: Setup lua
uses: luarocks/gh-actions-lua@v10
uses: leso-kn/gh-actions-lua@v11-staging
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: hishamhm/gh-actions-luarocks@master
- name: Make and install
run: |
luarocks make -- luasocket-scm-3.rockspec

0
Lua.props Normal file → Executable file
View File

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

@ -149,8 +149,8 @@ wild-card address).
<!-- gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class="name" id="gettimeout">
connected:<b>gettimeout()</b><br>
unconnected:<b>gettimeout()</b>
connected:<b>settimeout(</b>value<b>)</b><br>
unconnected:<b>settimeout(</b>value<b>)</b>
</p>
<p class="description">

2
makefile Normal file → Executable file
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)

0
mime.vcxproj Normal file → Executable file
View File

0
socket.vcxproj Normal file → Executable file
View File

0
src/inet.c Normal file → Executable file
View File

0
src/luasocket.c Normal file → Executable file
View File

27
src/makefile Normal file → Executable file
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

0
src/mime.c Normal file → Executable file
View File

0
src/socket.h Normal file → Executable file
View File

0
src/udp.c Normal file → Executable file
View File

12
src/wsocket.c Normal file → Executable file
View File

@ -127,7 +127,19 @@ int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {
if (connect(*ps, addr, len) == 0) return IO_DONE;
/* make sure the system is trying to connect */
err = WSAGetLastError();
if (err == WSAEISCONN) return IO_DONE; // already connected?
// hotfix for nonblocking, slow TCP connections not returning instantly
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms737625(v=vs.85).aspx
// "Note In order to preserve backward compatibility, this error is reported as WSAEINVAL to Windows Sockets 1.1 applications that link to either Winsock.dll or Wsock32.dll."
// The only other valid reason to get WSAINVAL is that: The parameter s is a listening socket. So we hope that doesn't happen here.
if (err == WSAEINVAL) {
return WSAEALREADY;
}
if (err != WSAEWOULDBLOCK && err != WSAEINPROGRESS) return err;
/* zero timeout case optimization */
if (timeout_iszero(tm)) return IO_TIMEOUT;
/* we wait until something happens */

0
vc32.bat Normal file → Executable file
View File

0
vc64.bat Normal file → Executable file
View File

0
win32.cmd Normal file → Executable file
View File

0
win64.cmd Normal file → Executable file
View File