mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-13 06:04:31 +02:00
Compare commits
2 Commits
master
...
f05a002a3a
Author | SHA1 | Date | |
---|---|---|---|
f05a002a3a | |||
610bea9c0f |
19
.github/workflows/build.yml
vendored
19
.github/workflows/build.yml
vendored
@ -8,34 +8,27 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Test ${{ matrix.luaVersion }} on ${{ matrix.platform }}
|
name: Test build on ${{ matrix.platform }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ]
|
luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ]
|
||||||
platform: [ "ubuntu-22.04", "macos-14", "windows-2022" ]
|
platform: [ "ubuntu-20.04", "macos-11" ] # "windows-2022" not supported by gh-actions-lua
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
- name: Setup ’msvc’
|
|
||||||
if: ${{ startsWith(matrix.platform, 'windows') && !startsWith(matrix.luaVersion, 'luajit') }}
|
|
||||||
uses: ilammy/msvc-dev-cmd@v1
|
|
||||||
- name: Setup ‘lua’
|
- name: Setup ‘lua’
|
||||||
uses: luarocks/gh-actions-lua@v10
|
uses: leafo/gh-actions-lua@v9
|
||||||
with:
|
with:
|
||||||
luaVersion: ${{ matrix.luaVersion }}
|
luaVersion: ${{ matrix.luaVersion }}
|
||||||
buildCache: false
|
|
||||||
- name: Setup ‘luarocks’
|
- name: Setup ‘luarocks’
|
||||||
# master branch until tagged release has luajit & msvcrt fixes
|
uses: leafo/gh-actions-luarocks@v4
|
||||||
uses: luarocks/gh-actions-luarocks@master
|
|
||||||
- name: Make and install
|
- name: Make and install
|
||||||
run: |
|
run: |
|
||||||
|
export DEBUG=DEBUG
|
||||||
luarocks make -- luasocket-scm-3.rockspec
|
luarocks make -- luasocket-scm-3.rockspec
|
||||||
env:
|
|
||||||
DEBUG: DEBUG
|
|
||||||
- name: Run regression tests
|
- name: Run regression tests
|
||||||
shell: bash
|
|
||||||
run: |
|
run: |
|
||||||
cd test
|
cd test
|
||||||
lua hello.lua
|
lua hello.lua
|
||||||
|
6
.github/workflows/luacheck.yml
vendored
6
.github/workflows/luacheck.yml
vendored
@ -5,9 +5,9 @@ on: [push, pull_request]
|
|||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
luacheck:
|
luacheck:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
- name: Luacheck
|
- name: Luacheck
|
||||||
uses: lunarmodules/luacheck@v1
|
uses: lunarmodules/luacheck@v0
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
# LuaSocket
|
# LuaSocket
|
||||||
|
|
||||||
|
|
||||||
[](https://github.com/lunarmodules/luasocket/actions?workflow=Build)
|
[](https://github.com/lunarmodules/luasocket/actions?workflow=Build)
|
||||||
[](https://github.com/lunarmodules/luasocket/actions?workflow=Luacheck)
|
[](https://github.com/lunarmodules/luasocket/actions?workflow=Luacheck)
|
||||||
[](https://github.com/lunarmodules/luasocket/releases)
|
[](https://github.com/lunarmodules/luasocket/releases)
|
||||||
[](https://luarocks.org/modules/lunarmodules/luasocket)
|
[](https://luarocks.org/modules/lunarmodules/luasocket)
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ protocol. For that, check the implementation.
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
To really benefit from this module, a good understanding of
|
To really benefit from this module, a good understanding of
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||||
LTN012, Filters sources and sinks</a> is necessary.
|
LTN012, Filters sources and sinks</a> is necessary.
|
||||||
</p>
|
</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
|
<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
|
precedence). <tt>Host</tt> is the server to connect to. <tt>Sink</tt> is
|
||||||
the <em>simple</em>
|
the <em>simple</em>
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
sink that will receive the downloaded data. <tt>Argument</tt> or
|
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
|
<tt>path</tt> give the target path to the resource in the server. The
|
||||||
optional arguments are the following:
|
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
|
<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>
|
"<tt>a</tt>". Defaults to whatever is the server default;</li>
|
||||||
<li><tt>step</tt>:
|
<li><tt>step</tt>:
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
pump step function used to pass data from the
|
pump step function used to pass data from the
|
||||||
server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;</li>
|
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
|
<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
|
<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
|
precedence). <tt>Host</tt> is the server to connect to. <tt>Source</tt> is
|
||||||
the <em>simple</em>
|
the <em>simple</em>
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
source that will provide the contents to be uploaded.
|
source that will provide the contents to be uploaded.
|
||||||
<tt>Argument</tt> or
|
<tt>Argument</tt> or
|
||||||
<tt>path</tt> give the target path to the resource in the server. The
|
<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
|
<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>
|
"<tt>a</tt>". Defaults to whatever is the server default;</li>
|
||||||
<li><tt>step</tt>:
|
<li><tt>step</tt>:
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
pump step function used to pass data from the
|
pump step function used to pass data from the
|
||||||
server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;</li>
|
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
|
<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
|
The module exports functions that provide HTTP functionality in different
|
||||||
levels of abstraction. From the simple
|
levels of abstraction. From the simple
|
||||||
string oriented requests, through generic
|
string oriented requests, through generic
|
||||||
<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.
|
<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.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -144,7 +144,7 @@ http.<b>request{</b><br>
|
|||||||
The request function has two forms. The simple form downloads
|
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
|
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
|
on strings. The generic form performs any HTTP method and is
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> based.
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> based.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="parameters">
|
<p class="parameters">
|
||||||
@ -158,7 +158,7 @@ in the <tt>url</tt>. Otherwise, it performs a <tt>GET</tt> in the
|
|||||||
<p class="parameters">
|
<p class="parameters">
|
||||||
If the first argument is instead a table, the most important fields are
|
If the first argument is instead a table, the most important fields are
|
||||||
the <tt>url</tt> and the <em>simple</em>
|
the <tt>url</tt> and the <em>simple</em>
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
<tt>sink</tt> that will receive the downloaded content.
|
<tt>sink</tt> that will receive the downloaded content.
|
||||||
Any part of the <tt>url</tt> can be overridden by including
|
Any part of the <tt>url</tt> can be overridden by including
|
||||||
the appropriate field in the request table.
|
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>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>headers</tt>: Any additional HTTP headers to send with the request;</li>
|
||||||
<li><tt>source</tt>: <em>simple</em>
|
<li><tt>source</tt>: <em>simple</em>
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
source to provide the request body. If there
|
source to provide the request body. If there
|
||||||
is a body, you need to provide an appropriate "<tt>content-length</tt>"
|
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
|
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>
|
"<tt>chunked</tt>" (something few servers support). Defaults to the empty source;</li>
|
||||||
<li><tt>step</tt>:
|
<li><tt>step</tt>:
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
pump step function used to move data.
|
pump step function used to move data.
|
||||||
Defaults to the LTN12 <tt>pump.step</tt> function.</li>
|
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>
|
<li><tt>proxy</tt>: The URL of a proxy server to use. Defaults to no proxy;</li>
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||||
"http://www.w3.org/TR/html4/strict.dtd">
|
"http://www.w3.org/TR/html4/strict.dtd">
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta name="description" content="LuaSocket: Introduction to the core">
|
<meta name="description" content="LuaSocket: Introduction to the core">
|
||||||
<meta name="keywords" content="Lua, LuaSocket, TCP, UDP, Network, Support,
|
<meta name="keywords" content="Lua, LuaSocket, TCP, UDP, Network, Support,
|
||||||
Installation">
|
Installation">
|
||||||
<title>LuaSocket: Installation</title>
|
<title>LuaSocket: Installation</title>
|
||||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||||
</head>
|
</head>
|
||||||
@ -29,7 +29,7 @@ Installation">
|
|||||||
<a href="index.html#download">download</a> ·
|
<a href="index.html#download">download</a> ·
|
||||||
<a href="installation.html">installation</a> ·
|
<a href="installation.html">installation</a> ·
|
||||||
<a href="introduction.html">introduction</a> ·
|
<a href="introduction.html">introduction</a> ·
|
||||||
<a href="reference.html">reference</a>
|
<a href="reference.html">reference</a>
|
||||||
</p>
|
</p>
|
||||||
</center>
|
</center>
|
||||||
<hr>
|
<hr>
|
||||||
@ -37,30 +37,70 @@ Installation">
|
|||||||
|
|
||||||
<!-- 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><CDIR></tt>
|
||||||
|
and <tt><LDIR></tt>, respectively.
|
||||||
|
For example, in my laptp, Lua 5.1 is configured to
|
||||||
|
use '<tt>/usr/local/lib/lua/5.1</tt>' for
|
||||||
|
<tt><CDIR></tt> and '<tt>/usr/local/share/lua/5.1</tt>' for
|
||||||
|
<tt><LDIR></tt>. On Windows, <tt><CDIR></tt>
|
||||||
|
usually points to the directory where the Lua executable is
|
||||||
|
found, and <tt><LDIR></tt> points to a
|
||||||
|
<tt>lua/</tt> directory inside <tt><CDIR></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>
|
<pre class=example>
|
||||||
luarocks install luasocket
|
<LDIR>/ltn12.lua
|
||||||
|
<LDIR>/socket.lua
|
||||||
|
<CDIR>/socket/core.dll
|
||||||
|
<LDIR>/socket/http.lua
|
||||||
|
<LDIR>/socket/tp.lua
|
||||||
|
<LDIR>/socket/ftp.lua
|
||||||
|
<LDIR>/socket/smtp.lua
|
||||||
|
<LDIR>/socket/url.lua
|
||||||
|
<LDIR>/mime.lua
|
||||||
|
<CDIR>/mime/core.dll
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<h3>Verification</h3>
|
<p> Naturally, on Unix systems, <tt>core.dll</tt>
|
||||||
<p>To verify that LuaSocket is installed correctly, open Lua and run:</p>
|
would be replaced by <tt>core.so</tt>.
|
||||||
<pre class=example><code>
|
</p>
|
||||||
local socket = require("socket")
|
|
||||||
print(socket._VERSION)
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<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> With the above setup, and an interpreter with shared library support,
|
||||||
<p>For more details, visit the <a href="https://github.com/lunarmodules/luasocket" target="_blank">LuaSocket GitHub repository</a>.</p>
|
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
|
||||||
|
> socket = require("socket")
|
||||||
|
> print(socket._VERSION)
|
||||||
|
--> LuaSocket 3.0.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
|
||||||
|
> http = require("socket.http")
|
||||||
|
> print(http.request("http://www.impa.br/~diego/software/luasocket"))
|
||||||
|
--> homepage gets dumped to terminal
|
||||||
|
</pre>
|
||||||
|
|
||||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||||
"http://www.w3.org/TR/html4/strict.dtd">
|
"http://www.w3.org/TR/html4/strict.dtd">
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta name="description" content="LuaSocket: Introduction to the core">
|
<meta name="description" content="LuaSocket: Introduction to the core">
|
||||||
<meta name="keywords" content="Lua, LuaSocket, TCP, UDP, Network,
|
<meta name="keywords" content="Lua, LuaSocket, TCP, UDP, Network,
|
||||||
Library, Support">
|
Library, Support">
|
||||||
<title>LuaSocket: Introduction to the core</title>
|
<title>LuaSocket: Introduction to the core</title>
|
||||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||||
</head>
|
</head>
|
||||||
@ -29,7 +29,7 @@ Library, Support">
|
|||||||
<a href="index.html#download">download</a> ·
|
<a href="index.html#download">download</a> ·
|
||||||
<a href="installation.html">installation</a> ·
|
<a href="installation.html">installation</a> ·
|
||||||
<a href="introduction.html">introduction</a> ·
|
<a href="introduction.html">introduction</a> ·
|
||||||
<a href="reference.html">reference</a>
|
<a href="reference.html">reference</a>
|
||||||
</p>
|
</p>
|
||||||
</center>
|
</center>
|
||||||
<hr>
|
<hr>
|
||||||
@ -61,23 +61,23 @@ interface to I/O across different domains and operating systems.
|
|||||||
The API design had two goals in mind. First, users
|
The API design had two goals in mind. First, users
|
||||||
experienced with the C API to sockets should feel comfortable using LuaSocket.
|
experienced with the C API to sockets should feel comfortable using LuaSocket.
|
||||||
Second, the simplicity and the feel of the Lua language should be
|
Second, the simplicity and the feel of the Lua language should be
|
||||||
preserved. To achieve these goals, the LuaSocket API keeps the function names and semantics the C API whenever possible, but their usage in Lua has been greatly simplified.
|
preserved. To achieve these goals, the LuaSocket API keeps the function names and semantics the C API whenever possible, but their usage in Lua has been greatly simplified.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
One of the simplifications is the receive pattern capability.
|
One of the simplifications is the receive pattern capability.
|
||||||
Applications can read data from stream domains (such as TCP)
|
Applications can read data from stream domains (such as TCP)
|
||||||
line by line, block by block, or until the connection is closed.
|
line by line, block by block, or until the connection is closed.
|
||||||
All I/O reads are buffered and the performance differences between
|
All I/O reads are buffered and the performance differences between
|
||||||
different receive patterns are negligible.
|
different receive patterns are negligible.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Another advantage is the flexible timeout control
|
Another advantage is the flexible timeout control
|
||||||
mechanism. As in C, all I/O operations are blocking by default. For
|
mechanism. As in C, all I/O operations are blocking by default. For
|
||||||
example, the <a href=tcp.html#send><tt>send</tt></a>,
|
example, the <a href=tcp.html#send><tt>send</tt></a>,
|
||||||
<a href=tcp.html#receive><tt>receive</tt></a> and
|
<a href=tcp.html#receive><tt>receive</tt></a> and
|
||||||
<a href=tcp.html#accept><tt>accept</tt></a> methods
|
<a href=tcp.html#accept><tt>accept</tt></a> methods
|
||||||
of the TCP domain will block the caller application until
|
of the TCP domain will block the caller application until
|
||||||
the operation is completed (if ever!). However, with a call to the
|
the operation is completed (if ever!). However, with a call to the
|
||||||
@ -87,7 +87,7 @@ the time it can be blocked by LuaSocket (the "<tt>total</tt>" timeout), on
|
|||||||
the time LuaSocket can internally be blocked by any OS call (the
|
the time LuaSocket can internally be blocked by any OS call (the
|
||||||
"<tt>block</tt>" timeout) or a combination of the two. Each LuaSocket
|
"<tt>block</tt>" timeout) or a combination of the two. Each LuaSocket
|
||||||
call might perform several OS calls, so that the two timeout values are
|
call might perform several OS calls, so that the two timeout values are
|
||||||
<em>not</em> equivalent.
|
<em>not</em> equivalent.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -95,10 +95,10 @@ Finally, the host name resolution is transparent, meaning that most
|
|||||||
functions and methods accept both IP addresses and host names. In case a
|
functions and methods accept both IP addresses and host names. In case a
|
||||||
host name is given, the library queries the system's resolver and
|
host name is given, the library queries the system's resolver and
|
||||||
tries the main IP address returned. Note that direct use of IP addresses
|
tries the main IP address returned. Note that direct use of IP addresses
|
||||||
is more efficient, of course. The
|
is more efficient, of course. The
|
||||||
<a href=dns.html#toip><tt>toip</tt></a>
|
<a href=dns.html#toip><tt>toip</tt></a>
|
||||||
and <a href=dns.html#tohostname><tt>tohostname</tt></a>
|
and <a href=dns.html#tohostname><tt>tohostname</tt></a>
|
||||||
functions from the DNS module are provided to convert between host names and IP addresses.
|
functions from the DNS module are provided to convert between host names and IP addresses.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -118,47 +118,47 @@ reassembled transparently on the other end. There are no boundaries in
|
|||||||
the data transfers. The library allows users to read data from the
|
the data transfers. The library allows users to read data from the
|
||||||
sockets in several different granularities: patterns are available for
|
sockets in several different granularities: patterns are available for
|
||||||
lines, arbitrary sized blocks or "read up to connection closed", all with
|
lines, arbitrary sized blocks or "read up to connection closed", all with
|
||||||
good performance.
|
good performance.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The library distinguishes three types of TCP sockets: <em>master</em>,
|
The library distinguishes three types of TCP sockets: <em>master</em>,
|
||||||
<em>client</em> and <em>server</em> sockets.
|
<em>client</em> and <em>server</em> sockets.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Master sockets are newly created TCP sockets returned by the function
|
Master sockets are newly created TCP sockets returned by the function
|
||||||
<a href=tcp.html#tcp><tt>socket.tcp</tt></a>. A master socket is
|
<a href=tcp.html#tcp><tt>socket.tcp</tt></a>. A master socket is
|
||||||
transformed into a server socket
|
transformed into a server socket
|
||||||
after it is associated with a <em>local</em> address by a call to the
|
after it is associated with a <em>local</em> address by a call to the
|
||||||
<a href=tcp.html#bind><tt>bind</tt></a> method followed by a call to the
|
<a href=tcp.html#bind><tt>bind</tt></a> method followed by a call to the
|
||||||
<a href=tcp.html#listen><tt>listen</tt></a>. Conversely, a master socket
|
<a href=tcp.html#listen><tt>listen</tt></a>. Conversely, a master socket
|
||||||
can be changed into a client socket with the method
|
can be changed into a client socket with the method
|
||||||
<a href=tcp.html#connect><tt>connect</tt></a>,
|
<a href=tcp.html#connect><tt>connect</tt></a>,
|
||||||
which associates it with a <em>remote</em> address.
|
which associates it with a <em>remote</em> address.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
On server sockets, applications can use the
|
On server sockets, applications can use the
|
||||||
<a href=tcp.html#accept><tt>accept</tt></a> method
|
<a href=tcp.html#accept><tt>accept</tt></a> method
|
||||||
to wait for a client connection. Once a connection is established, a
|
to wait for a client connection. Once a connection is established, a
|
||||||
client socket object is returned representing this connection. The
|
client socket object is returned representing this connection. The
|
||||||
other methods available for server socket objects are
|
other methods available for server socket objects are
|
||||||
<a href=tcp.html#getsockname><tt>getsockname</tt></a>,
|
<a href=tcp.html#getsockname><tt>getsockname</tt></a>,
|
||||||
<a href=tcp.html#setoption><tt>setoption</tt></a>,
|
<a href=tcp.html#setoption><tt>setoption</tt></a>,
|
||||||
<a href=tcp.html#settimeout><tt>settimeout</tt></a>, and
|
<a href=tcp.html#settimeout><tt>settimeout</tt></a>, and
|
||||||
<a href=tcp.html#close><tt>close</tt></a>.
|
<a href=tcp.html#close><tt>close</tt></a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Client sockets are used to exchange data between two applications over
|
Client sockets are used to exchange data between two applications over
|
||||||
the Internet. Applications can call the methods
|
the Internet. Applications can call the methods
|
||||||
<a href=tcp.html#send><tt>send</tt></a> and
|
<a href=tcp.html#send><tt>send</tt></a> and
|
||||||
<a href=tcp.html#receive><tt>receive</tt></a>
|
<a href=tcp.html#receive><tt>receive</tt></a>
|
||||||
to send and receive data. The other methods
|
to send and receive data. The other methods
|
||||||
available for client socket objects are
|
available for client socket objects are
|
||||||
<a href=tcp.html#getsockname><tt>getsockname</tt></a>,
|
<a href=tcp.html#getsockname><tt>getsockname</tt></a>,
|
||||||
<a href=tcp.html#getpeername><tt>getpeername</tt></a>,
|
<a href=tcp.html#getpeername><tt>getpeername</tt></a>,
|
||||||
<a href=tcp.html#setoption><tt>setoption</tt></a>,
|
<a href=tcp.html#setoption><tt>setoption</tt></a>,
|
||||||
<a href=tcp.html#settimeout><tt>settimeout</tt></a>,
|
<a href=tcp.html#settimeout><tt>settimeout</tt></a>,
|
||||||
<a href=tcp.html#shutdown><tt>shutdown</tt></a>, and
|
<a href=tcp.html#shutdown><tt>shutdown</tt></a>, and
|
||||||
@ -175,7 +175,7 @@ port (one that is chosen by the operating system) on the local host and
|
|||||||
awaits client connections on that port. When a connection is established,
|
awaits client connections on that port. When a connection is established,
|
||||||
the program reads a line from the remote end and sends it back, closing
|
the program reads a line from the remote end and sends it back, closing
|
||||||
the connection immediately. You can test it using the telnet
|
the connection immediately. You can test it using the telnet
|
||||||
program.
|
program.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre class=example>
|
<pre class=example>
|
||||||
@ -217,68 +217,68 @@ error free. Data transfers are atomic, one datagram at a time. Reading
|
|||||||
only part of a datagram discards the rest, so that the following read
|
only part of a datagram discards the rest, so that the following read
|
||||||
operation will act on the next datagram. The advantages are in
|
operation will act on the next datagram. The advantages are in
|
||||||
simplicity (no connection setup) and performance (no error checking or
|
simplicity (no connection setup) and performance (no error checking or
|
||||||
error correction).
|
error correction).
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Note that although no guarantees are made, these days
|
Note that although no guarantees are made, these days
|
||||||
networks are so good that, under normal circumstances, few errors
|
networks are so good that, under normal circumstances, few errors
|
||||||
happen in practice.
|
happen in practice.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
An UDP socket object is created by the
|
An UDP socket object is created by the
|
||||||
<a href=udp.html#udp><tt>socket.udp</tt></a> function. UDP
|
<a href=udp.html#udp><tt>socket.udp</tt></a> function. UDP
|
||||||
sockets do not need to be connected before use. The method
|
sockets do not need to be connected before use. The method
|
||||||
<a href=udp.html#sendto><tt>sendto</tt></a>
|
<a href=udp.html#sendto><tt>sendto</tt></a>
|
||||||
can be used immediately after creation to
|
can be used immediately after creation to
|
||||||
send a datagram to IP address and port. Host names are not allowed
|
send a datagram to IP address and port. Host names are not allowed
|
||||||
because performing name resolution for each packet would be forbiddingly
|
because performing name resolution for each packet would be forbiddingly
|
||||||
slow. Methods
|
slow. Methods
|
||||||
<a href=udp.html#receive><tt>receive</tt></a> and
|
<a href=udp.html#receive><tt>receive</tt></a> and
|
||||||
<a href=udp.html#receivefrom><tt>receivefrom</tt></a>
|
<a href=udp.html#receivefrom><tt>receivefrom</tt></a>
|
||||||
can be used to retrieve datagrams, the latter returning the IP and port of
|
can be used to retrieve datagrams, the latter returning the IP and port of
|
||||||
the sender as extra return values (thus being slightly less
|
the sender as extra return values (thus being slightly less
|
||||||
efficient).
|
efficient).
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
When communication is performed repeatedly with a single peer, an
|
When communication is performed repeatedly with a single peer, an
|
||||||
application should call the
|
application should call the
|
||||||
<a href=udp.html#setpeername><tt>setpeername</tt></a> method to specify a
|
<a href=udp.html#setpeername><tt>setpeername</tt></a> method to specify a
|
||||||
permanent partner. Methods
|
permanent partner. Methods
|
||||||
<a href=udp.html#sendto><tt>sendto</tt></a> and
|
<a href=udp.html#sendto><tt>sendto</tt></a> and
|
||||||
<a href=udp.html#receivefrom><tt>receivefrom</tt></a>
|
<a href=udp.html#receivefrom><tt>receivefrom</tt></a>
|
||||||
can no longer be used, but the method
|
can no longer be used, but the method
|
||||||
<a href=udp.html#send><tt>send</tt></a> can be used to send data
|
<a href=udp.html#send><tt>send</tt></a> can be used to send data
|
||||||
directly to the peer, and the method
|
directly to the peer, and the method
|
||||||
<a href=udp.html#receive><tt>receive</tt></a>
|
<a href=udp.html#receive><tt>receive</tt></a>
|
||||||
will only return datagrams originating
|
will only return datagrams originating
|
||||||
from that peer. There is about 30% performance gain due to this practice.
|
from that peer. There is about 30% performance gain due to this practice.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To associate an UDP socket with a local address, an application calls the
|
To associate an UDP socket with a local address, an application calls the
|
||||||
<a href=udp.html#setsockname><tt>setsockname</tt></a>
|
<a href=udp.html#setsockname><tt>setsockname</tt></a>
|
||||||
method <em>before</em> sending any datagrams. Otherwise, the socket is
|
method <em>before</em> sending any datagrams. Otherwise, the socket is
|
||||||
automatically bound to an ephemeral address before the first data
|
automatically bound to an ephemeral address before the first data
|
||||||
transmission and once bound the local address cannot be changed.
|
transmission and once bound the local address cannot be changed.
|
||||||
The other methods available for UDP sockets are
|
The other methods available for UDP sockets are
|
||||||
<a href=udp.html#getpeername><tt>getpeername</tt></a>,
|
<a href=udp.html#getpeername><tt>getpeername</tt></a>,
|
||||||
<a href=udp.html#getsockname><tt>getsockname</tt></a>,
|
<a href=udp.html#getsockname><tt>getsockname</tt></a>,
|
||||||
<a href=udp.html#settimeout><tt>settimeout</tt></a>,
|
<a href=udp.html#settimeout><tt>settimeout</tt></a>,
|
||||||
<a href=udp.html#setoption><tt>setoption</tt></a> and
|
<a href=udp.html#setoption><tt>setoption</tt></a> and
|
||||||
<a href=udp.html#close><tt>close</tt></a>.
|
<a href=udp.html#close><tt>close</tt></a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Example:
|
Example:
|
||||||
</p>
|
</p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
A simple daytime client, using LuaSocket. The program connects to a remote
|
A simple daytime client, using LuaSocket. The program connects to a remote
|
||||||
server and tries to retrieve the daytime, printing the answer it got or an
|
server and tries to retrieve the daytime, printing the answer it got or an
|
||||||
error message.
|
error message.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre class=example>
|
<pre class=example>
|
||||||
@ -301,11 +301,11 @@ io.write(assert(udp:receive()))
|
|||||||
|
|
||||||
<h3 id=more>Support modules</h3>
|
<h3 id=more>Support modules</h3>
|
||||||
|
|
||||||
<p> Although not covered in the introduction, LuaSocket offers
|
<p> Although not covered in the introduction, LuaSocket offers
|
||||||
much more than TCP and UDP functionality. As the library
|
much more than TCP and UDP functionality. As the library
|
||||||
evolved, support for <a href=http.html>HTTP</a>, <a href=ftp.html>FTP</a>,
|
evolved, support for <a href=http.html>HTTP</a>, <a href=ftp.html>FTP</a>,
|
||||||
and <a href=smtp.html>SMTP</a> were built on top of these. These modules
|
and <a href=smtp.html>SMTP</a> were built on top of these. These modules
|
||||||
and many others are covered by the <a href=reference.html>reference manual</a>.
|
and many others are covered by the <a href=reference.html>reference manual</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
@ -40,7 +40,7 @@ Pump, Support, Library">
|
|||||||
<h2 id="ltn12">LTN12</h2>
|
<h2 id="ltn12">LTN12</h2>
|
||||||
|
|
||||||
<p> The <tt>ltn12</tt> namespace implements the ideas described in
|
<p> The <tt>ltn12</tt> namespace implements the ideas described in
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||||
LTN012, Filters sources and sinks</a>. This manual simply describes the
|
LTN012, Filters sources and sinks</a>. This manual simply describes the
|
||||||
functions. Please refer to the LTN for a deeper explanation of the
|
functions. Please refer to the LTN for a deeper explanation of the
|
||||||
functionality provided by this module.
|
functionality provided by this module.
|
||||||
|
@ -54,7 +54,7 @@ MIME is described mainly in
|
|||||||
<p>
|
<p>
|
||||||
All functionality provided by the MIME module
|
All functionality provided by the MIME module
|
||||||
follows the ideas presented in
|
follows the ideas presented in
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||||
LTN012, Filters sources and sinks</a>.
|
LTN012, Filters sources and sinks</a>.
|
||||||
</p>
|
</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>
|
in <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a>.</p>
|
||||||
|
|
||||||
<p> In the description below, good understanding of <a
|
<p> In the description below, good understanding of <a
|
||||||
href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md"> LTN012, Filters
|
href="http://lua-users.org/wiki/FiltersSourcesAndSinks"> LTN012, Filters
|
||||||
sources and sinks</a> and the <a href="mime.html">MIME</a> module is
|
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
|
assumed. In fact, the SMTP module was the main reason for their
|
||||||
creation. </p>
|
creation. </p>
|
||||||
@ -122,7 +122,7 @@ smtp.<b>message(</b>mesgt<b>)</b>
|
|||||||
|
|
||||||
<p class="description">
|
<p class="description">
|
||||||
Returns a <em>simple</em>
|
Returns a <em>simple</em>
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep).
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep).
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="parameters">
|
<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>
|
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
|
and the <tt>body</tt>. The message <tt>body</tt> can be given as a string
|
||||||
or as a <em>simple</em>
|
or as a <em>simple</em>
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
source. For multipart messages, the body is a table that
|
source. For multipart messages, the body is a table that
|
||||||
recursively defines each part as an independent message, plus an optional
|
recursively defines each part as an independent message, plus an optional
|
||||||
<tt>preamble</tt> and <tt>epilogue</tt>.
|
<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">
|
<p class="return">
|
||||||
The function returns a <em>simple</em>
|
The function returns a <em>simple</em>
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
source that produces the
|
source that produces the
|
||||||
message contents as defined by <tt>mesgt</tt>, chunk by chunk.
|
message contents as defined by <tt>mesgt</tt>, chunk by chunk.
|
||||||
Hopefully, the following
|
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
|
address, or a string
|
||||||
in case there is just one recipient.
|
in case there is just one recipient.
|
||||||
The contents of the message are given by a <em>simple</em>
|
The contents of the message are given by a <em>simple</em>
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
<tt>source</tt>. Several arguments are optional:
|
<tt>source</tt>. Several arguments are optional:
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<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
|
<li> <tt>domain</tt>: Domain name used to greet the server; Defaults to the
|
||||||
local machine host name;</li>
|
local machine host name;</li>
|
||||||
<li> <tt>step</tt>:
|
<li> <tt>step</tt>:
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
pump step function used to pass data from the
|
pump step function used to pass data from the
|
||||||
source to the server. Defaults to the LTN12 <tt>pump.step</tt> function;</li>
|
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
|
<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. Each recipient of an SMTP mail message receives a copy of the
|
||||||
message body along with the headers, and nothing more. The headers
|
message body along with the headers, and nothing more. The headers
|
||||||
<em>are</em> part of the message and should be produced by the
|
<em>are</em> part of the message and should be produced by the
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
<tt>source</tt> function. The <tt>rcpt</tt> list is <em>not</em>
|
<tt>source</tt> function. The <tt>rcpt</tt> list is <em>not</em>
|
||||||
part of the message and will not be sent to anyone.
|
part of the message and will not be sent to anyone.
|
||||||
</p>
|
</p>
|
||||||
|
@ -164,9 +164,6 @@ Creates and returns a <em>clean</em>
|
|||||||
<a href="#try"><tt>try</tt></a>
|
<a href="#try"><tt>try</tt></a>
|
||||||
function that allows for cleanup before the exception
|
function that allows for cleanup before the exception
|
||||||
is raised.
|
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>
|
||||||
|
|
||||||
<p class="parameters">
|
<p class="parameters">
|
||||||
@ -210,9 +207,6 @@ 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>
|
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
|
and <a href="#newtry"><tt>newtry</tt></a> functions. It does not catch normal
|
||||||
Lua errors.
|
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>
|
||||||
|
|
||||||
<p class="parameters">
|
<p class="parameters">
|
||||||
@ -311,7 +305,7 @@ socket.<b>sink(</b>mode, socket<b>)</b>
|
|||||||
|
|
||||||
<p class="description">
|
<p class="description">
|
||||||
Creates an
|
Creates an
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
sink from a stream socket object.
|
sink from a stream socket object.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -386,7 +380,7 @@ socket.<b>source(</b>mode, socket [, length]<b>)</b>
|
|||||||
|
|
||||||
<p class="description">
|
<p class="description">
|
||||||
Creates an
|
Creates an
|
||||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a>
|
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||||
source from a stream socket object.
|
source from a stream socket object.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -431,9 +425,6 @@ 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
|
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
|
<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.
|
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>
|
||||||
|
|
||||||
<p class="parameters">
|
<p class="parameters">
|
||||||
|
@ -149,8 +149,8 @@ wild-card address).
|
|||||||
<!-- gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
|
||||||
<p class="name" id="gettimeout">
|
<p class="name" id="gettimeout">
|
||||||
connected:<b>gettimeout()</b><br>
|
connected:<b>settimeout(</b>value<b>)</b><br>
|
||||||
unconnected:<b>gettimeout()</b>
|
unconnected:<b>settimeout(</b>value<b>)</b>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="description">
|
<p class="description">
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||||
"http://www.w3.org/TR/html4/strict.dtd">
|
"http://www.w3.org/TR/html4/strict.dtd">
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta name="description" content="LuaSocket: URL manipulation">
|
<meta name="description" content="LuaSocket: URL manipulation">
|
||||||
<meta name="keywords" content="Lua, LuaSocket, URL, Library, Link, Network, Support">
|
<meta name="keywords" content="Lua, LuaSocket, URL, Library, Link, Network, Support">
|
||||||
<title>LuaSocket: URL support</title>
|
<title>LuaSocket: URL support</title>
|
||||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||||
</head>
|
</head>
|
||||||
@ -28,7 +28,7 @@
|
|||||||
<a href="index.html#download">download</a> ·
|
<a href="index.html#download">download</a> ·
|
||||||
<a href="installation.html">installation</a> ·
|
<a href="installation.html">installation</a> ·
|
||||||
<a href="introduction.html">introduction</a> ·
|
<a href="introduction.html">introduction</a> ·
|
||||||
<a href="reference.html">reference</a>
|
<a href="reference.html">reference</a>
|
||||||
</p>
|
</p>
|
||||||
</center>
|
</center>
|
||||||
<hr>
|
<hr>
|
||||||
@ -36,21 +36,21 @@
|
|||||||
|
|
||||||
<!-- url ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- url ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
|
||||||
<h2 id="url">URL</h2>
|
<h2 id="url">URL</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The <tt>url</tt> namespace provides functions to parse, protect,
|
The <tt>url</tt> namespace provides functions to parse, protect,
|
||||||
and build URLs, as well as functions to compose absolute URLs
|
and build URLs, as well as functions to compose absolute URLs
|
||||||
from base and relative URLs, according to
|
from base and relative URLs, according to
|
||||||
<a href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>.
|
<a href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To obtain the <tt>url</tt> namespace, run:
|
To obtain the <tt>url</tt> namespace, run:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre class=example>
|
<pre class=example>
|
||||||
-- loads the URL module
|
-- loads the URL module
|
||||||
local url = require("socket.url")
|
local url = require("socket.url")
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ url.<b>absolute(</b>base, relative<b>)</b>
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=description>
|
<p class=description>
|
||||||
Builds an absolute URL from a base URL and a relative URL.
|
Builds an absolute URL from a base URL and a relative URL.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=parameters>
|
<p class=parameters>
|
||||||
@ -130,14 +130,14 @@ url.<b>build(</b>parsed_url<b>)</b>
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=description>
|
<p class=description>
|
||||||
Rebuilds an URL from its parts.
|
Rebuilds an URL from its parts.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=parameters>
|
<p class=parameters>
|
||||||
<tt>Parsed_url</tt> is a table with same components returned by
|
<tt>Parsed_url</tt> is a table with same components returned by
|
||||||
<a href="#parse"><tt>parse</tt></a>.
|
<a href="#parse"><tt>parse</tt></a>.
|
||||||
Lower level components, if specified,
|
Lower level components, if specified,
|
||||||
take precedence over high level components of the URL grammar.
|
take precedence over high level components of the URL grammar.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=return>
|
<p class=return>
|
||||||
@ -152,10 +152,10 @@ url.<b>build_path(</b>segments, unsafe<b>)</b>
|
|||||||
|
|
||||||
<p class=description>
|
<p class=description>
|
||||||
Builds a <tt><path></tt> component from a list of
|
Builds a <tt><path></tt> component from a list of
|
||||||
<tt><segment></tt> parts.
|
<tt><segment></tt> parts.
|
||||||
Before composition, any reserved characters found in a segment are escaped into
|
Before composition, any reserved characters found in a segment are escaped into
|
||||||
their protected form, so that the resulting path is a valid URL path
|
their protected form, so that the resulting path is a valid URL path
|
||||||
component.
|
component.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=parameters>
|
<p class=parameters>
|
||||||
@ -165,8 +165,8 @@ characters are left untouched.
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=return>
|
<p class=return>
|
||||||
The function returns a string with the
|
The function returns a string with the
|
||||||
built <tt><path></tt> component.
|
built <tt><path></tt> component.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!-- escape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- escape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
@ -178,7 +178,7 @@ url.<b>escape(</b>content<b>)</b>
|
|||||||
<p class=description>
|
<p class=description>
|
||||||
Applies the URL escaping content coding to a string
|
Applies the URL escaping content coding to a string
|
||||||
Each byte is encoded as a percent character followed
|
Each byte is encoded as a percent character followed
|
||||||
by the two byte hexadecimal representation of its integer
|
by the two byte hexadecimal representation of its integer
|
||||||
value.
|
value.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -270,8 +270,8 @@ url.<b>parse_path(</b>path<b>)</b>
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=description>
|
<p class=description>
|
||||||
Breaks a <tt><path></tt> URL component into all its
|
Breaks a <tt><path></tt> URL component into all its
|
||||||
<tt><segment></tt> parts.
|
<tt><segment></tt> parts.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=description>
|
<p class=description>
|
||||||
@ -282,7 +282,7 @@ Breaks a <tt><path></tt> URL component into all its
|
|||||||
Since some characters are reserved in URLs, they must be escaped
|
Since some characters are reserved in URLs, they must be escaped
|
||||||
whenever present in a <tt><path></tt> component. Therefore, before
|
whenever present in a <tt><path></tt> component. Therefore, before
|
||||||
returning a list with all the parsed segments, the function removes
|
returning a list with all the parsed segments, the function removes
|
||||||
escaping from all of them.
|
escaping from all of them.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!-- unescape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- unescape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
@ -300,7 +300,7 @@ Removes the URL escaping content coding from a string.
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class=return>
|
<p class=return>
|
||||||
The function returns the decoded string.
|
The function returns the decoded string.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
@ -69,7 +69,6 @@ local function make_plat(plat)
|
|||||||
["socket.smtp"] = "src/smtp.lua",
|
["socket.smtp"] = "src/smtp.lua",
|
||||||
ltn12 = "src/ltn12.lua",
|
ltn12 = "src/ltn12.lua",
|
||||||
socket = "src/socket.lua",
|
socket = "src/socket.lua",
|
||||||
mbox = "src/mbox.lua",
|
|
||||||
mime = "src/mime.lua"
|
mime = "src/mime.lua"
|
||||||
}
|
}
|
||||||
if plat == "unix"
|
if plat == "unix"
|
||||||
|
2
makefile
Normal file → Executable file
2
makefile
Normal file → Executable file
@ -10,7 +10,7 @@
|
|||||||
# print print the build settings
|
# print print the build settings
|
||||||
|
|
||||||
PLAT?= linux
|
PLAT?= linux
|
||||||
PLATS= macosx linux win32 win64 mingw freebsd solaris ucrt64
|
PLATS= macosx linux win32 win64 mingw freebsd solaris
|
||||||
|
|
||||||
all: $(PLAT)
|
all: $(PLAT)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#--------------------------------------------------------------------------
|
#--------------------------------------------------------------------------
|
||||||
# Distribution makefile
|
# Distribution makefile
|
||||||
#--------------------------------------------------------------------------
|
#--------------------------------------------------------------------------
|
||||||
DIST = luasocket-3.1.0
|
DIST = luasocket-3.0.0
|
||||||
|
|
||||||
TEST = \
|
TEST = \
|
||||||
test/README \
|
test/README \
|
||||||
|
0
mime.vcxproj
Normal file → Executable file
0
mime.vcxproj
Normal file → Executable file
0
socket.vcxproj
Normal file → Executable file
0
socket.vcxproj
Normal file → Executable file
19
src/http.lua
19
src/http.lua
@ -54,7 +54,7 @@ local function receiveheaders(sock, headers)
|
|||||||
while line ~= "" do
|
while line ~= "" do
|
||||||
-- get field-name and value
|
-- get field-name and value
|
||||||
name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)"))
|
name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)"))
|
||||||
if not (name and value) then return nil, "malformed response headers" end
|
if not (name and value) then return nil, "malformed reponse headers" end
|
||||||
name = string.lower(name)
|
name = string.lower(name)
|
||||||
-- get next line (value might be folded)
|
-- get next line (value might be folded)
|
||||||
line, err = sock:receive()
|
line, err = sock:receive()
|
||||||
@ -62,7 +62,7 @@ local function receiveheaders(sock, headers)
|
|||||||
-- unfold any folded values
|
-- unfold any folded values
|
||||||
while string.find(line, "^%s") do
|
while string.find(line, "^%s") do
|
||||||
value = value .. line
|
value = value .. line
|
||||||
line, err = sock:receive()
|
line = sock:receive()
|
||||||
if err then return nil, err end
|
if err then return nil, err end
|
||||||
end
|
end
|
||||||
-- save pair in table
|
-- save pair in table
|
||||||
@ -81,7 +81,7 @@ socket.sourcet["http-chunked"] = function(sock, headers)
|
|||||||
dirty = function() return sock:dirty() end
|
dirty = function() return sock:dirty() end
|
||||||
}, {
|
}, {
|
||||||
__call = function()
|
__call = function()
|
||||||
-- get chunk size, skip extension
|
-- get chunk size, skip extention
|
||||||
local line, err = sock:receive()
|
local line, err = sock:receive()
|
||||||
if err then return nil, err end
|
if err then return nil, err end
|
||||||
local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
|
local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
|
||||||
@ -219,11 +219,9 @@ local function adjustproxy(reqt)
|
|||||||
local proxy = reqt.proxy or _M.PROXY
|
local proxy = reqt.proxy or _M.PROXY
|
||||||
if proxy then
|
if proxy then
|
||||||
proxy = url.parse(proxy)
|
proxy = url.parse(proxy)
|
||||||
proxy.port = proxy.port or 3128
|
return proxy.host, proxy.port or 3128
|
||||||
proxy.create = SCHEMES[proxy.scheme].create(reqt)
|
|
||||||
return proxy.host, proxy.port, proxy.create
|
|
||||||
else
|
else
|
||||||
return reqt.host, reqt.port, reqt.create
|
return reqt.host, reqt.port
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -281,7 +279,7 @@ local function adjustrequest(reqt)
|
|||||||
if not (host and host ~= "") then
|
if not (host and host ~= "") then
|
||||||
socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'")
|
socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'")
|
||||||
end
|
end
|
||||||
-- compute uri if user hasn't overridden
|
-- compute uri if user hasn't overriden
|
||||||
nreqt.uri = reqt.uri or adjusturi(nreqt)
|
nreqt.uri = reqt.uri or adjusturi(nreqt)
|
||||||
-- adjust headers in request
|
-- adjust headers in request
|
||||||
nreqt.headers = adjustheaders(nreqt)
|
nreqt.headers = adjustheaders(nreqt)
|
||||||
@ -293,10 +291,7 @@ local function adjustrequest(reqt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- ajust host and port if there is a proxy
|
-- ajust host and port if there is a proxy
|
||||||
local proxy_create
|
nreqt.host, nreqt.port = adjustproxy(nreqt)
|
||||||
nreqt.host, nreqt.port, proxy_create = adjustproxy(nreqt)
|
|
||||||
if not reqt.create then nreqt.create = proxy_create end
|
|
||||||
|
|
||||||
return nreqt
|
return nreqt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
2
src/inet.c
Normal file → Executable file
2
src/inet.c
Normal file → Executable file
@ -290,7 +290,7 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
lua_pushstring(L, name);
|
lua_pushstring(L, name);
|
||||||
lua_pushinteger(L, (int) strtol(port, (char **) NULL, 10));
|
lua_pushstring(L, port);
|
||||||
switch (family) {
|
switch (family) {
|
||||||
case AF_INET: lua_pushliteral(L, "inet"); break;
|
case AF_INET: lua_pushliteral(L, "inet"); break;
|
||||||
case AF_INET6: lua_pushliteral(L, "inet6"); break;
|
case AF_INET6: lua_pushliteral(L, "inet6"); break;
|
||||||
|
0
src/luasocket.c
Normal file → Executable file
0
src/luasocket.c
Normal file → Executable file
@ -10,7 +10,7 @@
|
|||||||
/*-------------------------------------------------------------------------* \
|
/*-------------------------------------------------------------------------* \
|
||||||
* Current socket library version
|
* Current socket library version
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
#define LUASOCKET_VERSION "LuaSocket 3.1.0"
|
#define LUASOCKET_VERSION "LuaSocket 3.0.0"
|
||||||
#define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab"
|
#define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab"
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
|
31
src/makefile
Normal file → Executable file
31
src/makefile
Normal file → Executable file
@ -1,6 +1,6 @@
|
|||||||
# luasocket src/makefile
|
# luasocket src/makefile
|
||||||
#
|
#
|
||||||
# Definitions in this section can be overridden on the command line or in the
|
# Definitions in this section can be overriden on the command line or in the
|
||||||
# environment.
|
# environment.
|
||||||
#
|
#
|
||||||
# These are equivalent:
|
# These are equivalent:
|
||||||
@ -74,13 +74,6 @@ LUAPREFIX_mingw?=/usr
|
|||||||
CDIR_mingw?=lua/$(LUAV)
|
CDIR_mingw?=lua/$(LUAV)
|
||||||
LDIR_mingw?=lua/$(LUAV)/lua
|
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:
|
# LUAINC_win32:
|
||||||
# LUALIB_win32:
|
# LUALIB_win32:
|
||||||
@ -160,7 +153,7 @@ print:
|
|||||||
#------
|
#------
|
||||||
# Supported platforms
|
# Supported platforms
|
||||||
#
|
#
|
||||||
PLATS= macosx linux win32 win64 mingw solaris ucrt64
|
PLATS= macosx linux win32 win64 mingw solaris
|
||||||
|
|
||||||
#------
|
#------
|
||||||
# Compiler and linker settings
|
# Compiler and linker settings
|
||||||
@ -226,21 +219,6 @@ LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o
|
|||||||
LD_mingw=gcc
|
LD_mingw=gcc
|
||||||
SOCKET_mingw=wsocket.o
|
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
|
# Compiler and linker settings
|
||||||
@ -294,7 +272,7 @@ SOCKET_win64=wsocket.obj
|
|||||||
#
|
#
|
||||||
SO=$(SO_$(PLAT))
|
SO=$(SO_$(PLAT))
|
||||||
O=$(O_$(PLAT))
|
O=$(O_$(PLAT))
|
||||||
SOCKET_V=3.1.0
|
SOCKET_V=3.0.0
|
||||||
MIME_V=1.0.3
|
MIME_V=1.0.3
|
||||||
SOCKET_SO=socket-$(SOCKET_V).$(SO)
|
SOCKET_SO=socket-$(SOCKET_V).$(SO)
|
||||||
MIME_SO=mime-$(MIME_V).$(SO)
|
MIME_SO=mime-$(MIME_V).$(SO)
|
||||||
@ -406,9 +384,6 @@ linux:
|
|||||||
mingw:
|
mingw:
|
||||||
$(MAKE) all PLAT=mingw
|
$(MAKE) all PLAT=mingw
|
||||||
|
|
||||||
ucrt64:
|
|
||||||
$(MAKE) all PLAT=ucrt64
|
|
||||||
|
|
||||||
solaris:
|
solaris:
|
||||||
$(MAKE) all-unix PLAT=solaris
|
$(MAKE) all-unix PLAT=solaris
|
||||||
|
|
||||||
|
0
src/mime.c
Normal file → Executable file
0
src/mime.c
Normal file → Executable file
@ -54,33 +54,6 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps)
|
|||||||
return opt->func(L, ps);
|
return opt->func(L, ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------*/
|
|
||||||
/* binds socket to network interface */
|
|
||||||
int opt_set_bindtodevice(lua_State *L, p_socket ps)
|
|
||||||
{
|
|
||||||
#ifndef SO_BINDTODEVICE
|
|
||||||
return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system");
|
|
||||||
#else
|
|
||||||
const char *dev = luaL_checkstring(L, 3);
|
|
||||||
return opt_set(L, ps, SOL_SOCKET, SO_BINDTODEVICE, (char*)dev, strlen(dev)+1);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int opt_get_bindtodevice(lua_State *L, p_socket ps)
|
|
||||||
{
|
|
||||||
#ifndef SO_BINDTODEVICE
|
|
||||||
return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system");
|
|
||||||
#else
|
|
||||||
char dev[IFNAMSIZ];
|
|
||||||
int len = sizeof(dev);
|
|
||||||
int err = opt_get(L, ps, SOL_SOCKET, SO_BINDTODEVICE, &dev, &len);
|
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
lua_pushstring(L, dev);
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------------*/
|
/*------------------------------------------------------*/
|
||||||
/* enables reuse of local address */
|
/* enables reuse of local address */
|
||||||
int opt_set_reuseaddr(lua_State *L, p_socket ps)
|
int opt_set_reuseaddr(lua_State *L, p_socket ps)
|
||||||
|
@ -53,9 +53,6 @@ int opt_get_tcp_keepintvl(lua_State *L, p_socket ps);
|
|||||||
int opt_set_tcp_defer_accept(lua_State *L, p_socket ps);
|
int opt_set_tcp_defer_accept(lua_State *L, p_socket ps);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int opt_set_bindtodevice(lua_State *L, p_socket ps);
|
|
||||||
int opt_get_bindtodevice(lua_State *L, p_socket ps);
|
|
||||||
|
|
||||||
int opt_set_keepalive(lua_State *L, p_socket ps);
|
int opt_set_keepalive(lua_State *L, p_socket ps);
|
||||||
int opt_get_keepalive(lua_State *L, p_socket ps);
|
int opt_get_keepalive(lua_State *L, p_socket ps);
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ local function adjust_headers(mesgt)
|
|||||||
lower["date"] = lower["date"] or
|
lower["date"] = lower["date"] or
|
||||||
os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or _M.ZONE)
|
os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or _M.ZONE)
|
||||||
lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
|
lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
|
||||||
-- this can't be overridden
|
-- this can't be overriden
|
||||||
lower["mime-version"] = "1.0"
|
lower["mime-version"] = "1.0"
|
||||||
return lower
|
return lower
|
||||||
end
|
end
|
||||||
@ -253,4 +253,4 @@ _M.send = socket.protect(function(mailt)
|
|||||||
return s:close()
|
return s:close()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return _M
|
return _M
|
0
src/socket.h
Normal file → Executable file
0
src/socket.h
Normal file → Executable file
@ -71,7 +71,6 @@ static luaL_Reg tcp_methods[] = {
|
|||||||
|
|
||||||
/* socket option handlers */
|
/* socket option handlers */
|
||||||
static t_opt optget[] = {
|
static t_opt optget[] = {
|
||||||
{"bindtodevice", opt_get_bindtodevice},
|
|
||||||
{"keepalive", opt_get_keepalive},
|
{"keepalive", opt_get_keepalive},
|
||||||
{"reuseaddr", opt_get_reuseaddr},
|
{"reuseaddr", opt_get_reuseaddr},
|
||||||
{"reuseport", opt_get_reuseport},
|
{"reuseport", opt_get_reuseport},
|
||||||
@ -93,7 +92,6 @@ static t_opt optget[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static t_opt optset[] = {
|
static t_opt optset[] = {
|
||||||
{"bindtodevice", opt_set_bindtodevice},
|
|
||||||
{"keepalive", opt_set_keepalive},
|
{"keepalive", opt_set_keepalive},
|
||||||
{"reuseaddr", opt_set_reuseaddr},
|
{"reuseaddr", opt_set_reuseaddr},
|
||||||
{"reuseport", opt_set_reuseport},
|
{"reuseport", opt_set_reuseport},
|
||||||
|
@ -16,6 +16,13 @@
|
|||||||
|
|
||||||
#define UNIXDGRAM_DATAGRAMSIZE 8192
|
#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
|
* Internal function prototypes
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
@ -35,8 +42,8 @@ static int meth_receivefrom(lua_State *L);
|
|||||||
static int meth_sendto(lua_State *L);
|
static int meth_sendto(lua_State *L);
|
||||||
static int meth_getsockname(lua_State *L);
|
static int meth_getsockname(lua_State *L);
|
||||||
|
|
||||||
static const char *unixdgram_tryconnect(p_unix un, const char *path, size_t len);
|
static const char *unixdgram_tryconnect(p_unix un, const char *path);
|
||||||
static const char *unixdgram_trybind(p_unix un, const char *path, size_t len);
|
static const char *unixdgram_trybind(p_unix un, const char *path);
|
||||||
|
|
||||||
/* unixdgram object methods */
|
/* unixdgram object methods */
|
||||||
static luaL_Reg unixdgram_methods[] = {
|
static luaL_Reg unixdgram_methods[] = {
|
||||||
@ -126,12 +133,13 @@ static int meth_send(lua_State *L)
|
|||||||
static int meth_sendto(lua_State *L)
|
static int meth_sendto(lua_State *L)
|
||||||
{
|
{
|
||||||
p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1);
|
p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1);
|
||||||
size_t count, sent, len = 0;
|
size_t count, sent = 0;
|
||||||
const char *data = luaL_checklstring(L, 2, &count);
|
const char *data = luaL_checklstring(L, 2, &count);
|
||||||
const char *path = luaL_checklstring(L, 3, &len);
|
const char *path = luaL_checkstring(L, 3);
|
||||||
p_timeout tm = &un->tm;
|
p_timeout tm = &un->tm;
|
||||||
int err;
|
int err;
|
||||||
struct sockaddr_un remote;
|
struct sockaddr_un remote;
|
||||||
|
size_t len = strlen(path);
|
||||||
|
|
||||||
if (len >= sizeof(remote.sun_path)) {
|
if (len >= sizeof(remote.sun_path)) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
@ -140,7 +148,7 @@ static int meth_sendto(lua_State *L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
memset(&remote, 0, sizeof(remote));
|
memset(&remote, 0, sizeof(remote));
|
||||||
memcpy(remote.sun_path, path, len);
|
strcpy(remote.sun_path, path);
|
||||||
remote.sun_family = AF_UNIX;
|
remote.sun_family = AF_UNIX;
|
||||||
timeout_markstart(tm);
|
timeout_markstart(tm);
|
||||||
#ifdef UNIX_HAS_SUN_LEN
|
#ifdef UNIX_HAS_SUN_LEN
|
||||||
@ -256,22 +264,18 @@ static int meth_dirty(lua_State *L) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Binds an object to an address
|
* Binds an object to an address
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
static const char *unixdgram_trybind(p_unix un, const char *path, size_t len) {
|
static const char *unixdgram_trybind(p_unix un, const char *path) {
|
||||||
struct sockaddr_un local;
|
struct sockaddr_un local;
|
||||||
int err;
|
size_t len = strlen(path);
|
||||||
if (len >= sizeof(local.sun_path)) return "path too long";
|
if (len >= sizeof(local.sun_path)) return "path too long";
|
||||||
memset(&local, 0, sizeof(local));
|
memset(&local, 0, sizeof(local));
|
||||||
memcpy(local.sun_path, path, len);
|
strcpy(local.sun_path, path);
|
||||||
local.sun_family = AF_UNIX;
|
local.sun_family = AF_UNIX;
|
||||||
|
size_t addrlen = SUN_LEN(&local);
|
||||||
#ifdef UNIX_HAS_SUN_LEN
|
#ifdef UNIX_HAS_SUN_LEN
|
||||||
local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len)
|
local.sun_len = addrlen + 1;
|
||||||
+ 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
|
#endif
|
||||||
|
int err = socket_bind(&un->sock, (SA *) &local, addrlen);
|
||||||
if (err != IO_DONE) socket_destroy(&un->sock);
|
if (err != IO_DONE) socket_destroy(&un->sock);
|
||||||
return socket_strerror(err);
|
return socket_strerror(err);
|
||||||
}
|
}
|
||||||
@ -279,9 +283,8 @@ static const char *unixdgram_trybind(p_unix un, const char *path, size_t len) {
|
|||||||
static int meth_bind(lua_State *L)
|
static int meth_bind(lua_State *L)
|
||||||
{
|
{
|
||||||
p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1);
|
p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1);
|
||||||
size_t len;
|
const char *path = luaL_checkstring(L, 2);
|
||||||
const char *path = luaL_checklstring(L, 2, &len);
|
const char *err = unixdgram_trybind(un, path);
|
||||||
const char *err = unixdgram_trybind(un, path, len);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L, err);
|
lua_pushstring(L, err);
|
||||||
@ -310,23 +313,20 @@ static int meth_getsockname(lua_State *L)
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Turns a master unixdgram object into a client object.
|
* Turns a master unixdgram object into a client object.
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
static const char *unixdgram_tryconnect(p_unix un, const char *path, size_t len)
|
static const char *unixdgram_tryconnect(p_unix un, const char *path)
|
||||||
{
|
{
|
||||||
struct sockaddr_un remote;
|
struct sockaddr_un remote;
|
||||||
int err;
|
size_t len = strlen(path);
|
||||||
if (len >= sizeof(remote.sun_path)) return "path too long";
|
if (len >= sizeof(remote.sun_path)) return "path too long";
|
||||||
memset(&remote, 0, sizeof(remote));
|
memset(&remote, 0, sizeof(remote));
|
||||||
memcpy(remote.sun_path, path, len);
|
strcpy(remote.sun_path, path);
|
||||||
remote.sun_family = AF_UNIX;
|
remote.sun_family = AF_UNIX;
|
||||||
timeout_markstart(&un->tm);
|
timeout_markstart(&un->tm);
|
||||||
|
size_t addrlen = SUN_LEN(&remote);
|
||||||
#ifdef UNIX_HAS_SUN_LEN
|
#ifdef UNIX_HAS_SUN_LEN
|
||||||
remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len)
|
remote.sun_len = addrlen + 1;
|
||||||
+ 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
|
#endif
|
||||||
|
int err = socket_connect(&un->sock, (SA *) &remote, addrlen, &un->tm);
|
||||||
if (err != IO_DONE) socket_destroy(&un->sock);
|
if (err != IO_DONE) socket_destroy(&un->sock);
|
||||||
return socket_strerror(err);
|
return socket_strerror(err);
|
||||||
}
|
}
|
||||||
@ -334,9 +334,8 @@ static const char *unixdgram_tryconnect(p_unix un, const char *path, size_t len)
|
|||||||
static int meth_connect(lua_State *L)
|
static int meth_connect(lua_State *L)
|
||||||
{
|
{
|
||||||
p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1);
|
p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1);
|
||||||
size_t len;
|
const char *path = luaL_checkstring(L, 2);
|
||||||
const char *path = luaL_checklstring(L, 2, &len);
|
const char *err = unixdgram_tryconnect(un, path);
|
||||||
const char *err = unixdgram_tryconnect(un, path, len);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L, err);
|
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_setstats(lua_State *L);
|
||||||
static int meth_getsockname(lua_State *L);
|
static int meth_getsockname(lua_State *L);
|
||||||
|
|
||||||
static const char *unixstream_tryconnect(p_unix un, const char *path, size_t len);
|
static const char *unixstream_tryconnect(p_unix un, const char *path);
|
||||||
static const char *unixstream_trybind(p_unix un, const char *path, size_t len);
|
static const char *unixstream_trybind(p_unix un, const char *path);
|
||||||
|
|
||||||
/* unixstream object methods */
|
/* unixstream object methods */
|
||||||
static luaL_Reg unixstream_methods[] = {
|
static luaL_Reg unixstream_methods[] = {
|
||||||
@ -181,12 +181,13 @@ static int meth_accept(lua_State *L) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Binds an object to an address
|
* Binds an object to an address
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
static const char *unixstream_trybind(p_unix un, const char *path, size_t len) {
|
static const char *unixstream_trybind(p_unix un, const char *path) {
|
||||||
struct sockaddr_un local;
|
struct sockaddr_un local;
|
||||||
|
size_t len = strlen(path);
|
||||||
int err;
|
int err;
|
||||||
if (len >= sizeof(local.sun_path)) return "path too long";
|
if (len >= sizeof(local.sun_path)) return "path too long";
|
||||||
memset(&local, 0, sizeof(local));
|
memset(&local, 0, sizeof(local));
|
||||||
memcpy(local.sun_path, path, len);
|
strcpy(local.sun_path, path);
|
||||||
local.sun_family = AF_UNIX;
|
local.sun_family = AF_UNIX;
|
||||||
#ifdef UNIX_HAS_SUN_LEN
|
#ifdef UNIX_HAS_SUN_LEN
|
||||||
local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len)
|
local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len)
|
||||||
@ -203,9 +204,8 @@ static const char *unixstream_trybind(p_unix un, const char *path, size_t len) {
|
|||||||
|
|
||||||
static int meth_bind(lua_State *L) {
|
static int meth_bind(lua_State *L) {
|
||||||
p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1);
|
p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1);
|
||||||
size_t len;
|
const char *path = luaL_checkstring(L, 2);
|
||||||
const char *path = luaL_checklstring(L, 2, &len);
|
const char *err = unixstream_trybind(un, path);
|
||||||
const char *err = unixstream_trybind(un, path, len);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L, err);
|
lua_pushstring(L, err);
|
||||||
@ -234,13 +234,14 @@ static int meth_getsockname(lua_State *L)
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Turns a master unixstream object into a client object.
|
* Turns a master unixstream object into a client object.
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
static const char *unixstream_tryconnect(p_unix un, const char *path, size_t len)
|
static const char *unixstream_tryconnect(p_unix un, const char *path)
|
||||||
{
|
{
|
||||||
struct sockaddr_un remote;
|
struct sockaddr_un remote;
|
||||||
int err;
|
int err;
|
||||||
|
size_t len = strlen(path);
|
||||||
if (len >= sizeof(remote.sun_path)) return "path too long";
|
if (len >= sizeof(remote.sun_path)) return "path too long";
|
||||||
memset(&remote, 0, sizeof(remote));
|
memset(&remote, 0, sizeof(remote));
|
||||||
memcpy(remote.sun_path, path, len);
|
strcpy(remote.sun_path, path);
|
||||||
remote.sun_family = AF_UNIX;
|
remote.sun_family = AF_UNIX;
|
||||||
timeout_markstart(&un->tm);
|
timeout_markstart(&un->tm);
|
||||||
#ifdef UNIX_HAS_SUN_LEN
|
#ifdef UNIX_HAS_SUN_LEN
|
||||||
@ -258,9 +259,8 @@ static const char *unixstream_tryconnect(p_unix un, const char *path, size_t len
|
|||||||
static int meth_connect(lua_State *L)
|
static int meth_connect(lua_State *L)
|
||||||
{
|
{
|
||||||
p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1);
|
p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1);
|
||||||
size_t len;
|
const char *path = luaL_checkstring(L, 2);
|
||||||
const char *path = luaL_checklstring(L, 2, &len);
|
const char *err = unixstream_tryconnect(un, path);
|
||||||
const char *err = unixstream_tryconnect(un, path, len);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L, err);
|
lua_pushstring(L, err);
|
||||||
|
@ -152,7 +152,7 @@ function _M.parse(url, default)
|
|||||||
url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
|
url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
|
||||||
function(s) parsed.scheme = s; return "" end)
|
function(s) parsed.scheme = s; return "" end)
|
||||||
-- get authority
|
-- get authority
|
||||||
url = string.gsub(url, "^//([^/%?#]*)", function(n)
|
url = string.gsub(url, "^//([^/]*)", function(n)
|
||||||
parsed.authority = n
|
parsed.authority = n
|
||||||
return ""
|
return ""
|
||||||
end)
|
end)
|
||||||
|
2
src/wsocket.c
Normal file → Executable file
2
src/wsocket.c
Normal file → Executable file
@ -262,7 +262,6 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got,
|
|||||||
if (err != WSAEWOULDBLOCK) {
|
if (err != WSAEWOULDBLOCK) {
|
||||||
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
||||||
prev = err;
|
prev = err;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
||||||
}
|
}
|
||||||
@ -292,7 +291,6 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
|||||||
if (err != WSAEWOULDBLOCK) {
|
if (err != WSAEWOULDBLOCK) {
|
||||||
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
||||||
prev = err;
|
prev = err;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
typedef int socklen_t;
|
|
||||||
typedef SOCKADDR_STORAGE t_sockaddr_storage;
|
typedef SOCKADDR_STORAGE t_sockaddr_storage;
|
||||||
typedef SOCKET t_socket;
|
typedef SOCKET t_socket;
|
||||||
typedef t_socket *p_socket;
|
typedef t_socket *p_socket;
|
||||||
|
Reference in New Issue
Block a user