mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-13 14:14:30 +02:00
Compare commits
146 Commits
revert-256
...
v3.1.0
Author | SHA1 | Date | |
---|---|---|---|
95b7efa9da | |||
80503077db | |||
5a7e3f0888 | |||
d1ad8160cb | |||
0c7df119c2 | |||
cff09ffb32 | |||
38c7b5161b | |||
1d61853ab8 | |||
88c8a85cb6 | |||
020c2c746b | |||
f7f0a77a3d | |||
d3777f9d06 | |||
e863315729 | |||
b5b60f9d6f | |||
e47d98f401 | |||
bac0b8dc27 | |||
2de8ddfbb8 | |||
5ed8b66e6d | |||
78d2cbfdee | |||
d9c08114da | |||
58f94e47d2 | |||
af0ddb6ea8 | |||
2eac895039 | |||
f98977b2da | |||
c1eacfa6d2 | |||
f97dc8489d | |||
f9e1d03f3c | |||
52c72694c2 | |||
9787c17e58 | |||
fdd741da5c | |||
d3434c0198 | |||
2a76cb906c | |||
e178b1e018 | |||
642433e771 | |||
e3c17b002a | |||
b57ca9bfa3 | |||
46ecb7e2dc | |||
2cc6f8a55c | |||
844165ff89 | |||
91aa6522a0 | |||
335f647075 | |||
36428e07cd | |||
d0f2d132bf | |||
a36818d3f3 | |||
8390d07774 | |||
989a5b1131 | |||
601ad8d59f | |||
480c052572 | |||
f6509d4fd5 | |||
52b22da7e3 | |||
6952262e6a | |||
d9cc531e3b | |||
5b18e475f3 | |||
743a5f1bcf | |||
a7baf8dc25 | |||
c8b4fdf858 | |||
84e5336e8b | |||
78a1657c7d | |||
733af884f1 | |||
ab3b0ef5c9 | |||
9acb6dc81a | |||
c89a931cc3 | |||
21514304be | |||
3a37ab8890 | |||
33883e78c8 | |||
c8d0fdda54 | |||
8b2dcdcf7d | |||
4e363330a3 | |||
d27b1a7945 | |||
5d07d9b227 | |||
d71e6bc459 | |||
42a1a732b7 | |||
86e1b3f45f | |||
1fa10673f7 | |||
c8b9b40eda | |||
c2245f35c5 | |||
ce6a08d57d | |||
83648f8df2 | |||
2015290cb4 | |||
ee30e4643d | |||
611cdd19cc | |||
4bf3eb6db2 | |||
133774cd3d | |||
e3ac49efbd | |||
98800e9129 | |||
2af4872a40 | |||
03b72d8f7e | |||
c7215bef07 | |||
1e4255e2a9 | |||
5cc91ab600 | |||
297f9d0277 | |||
34d525984c | |||
d9afe3fd9c | |||
c0fba03e4f | |||
e2e43d62fa | |||
2d8f0d9901 | |||
f8183bab87 | |||
d7ffc2f4e6 | |||
fe437ee844 | |||
678d558c5f | |||
30a0a6003b | |||
87c2dee13e | |||
525d703e16 | |||
898f2df025 | |||
fae993c118 | |||
ef2a3fcedb | |||
3f19a052e8 | |||
731b23bc89 | |||
395729d431 | |||
2bf6730fd5 | |||
b95527e140 | |||
c0374dd46f | |||
16b0026e27 | |||
1f6035070f | |||
c23bf865ce | |||
efc4bb3e2d | |||
f06b17c4c9 | |||
9b3f7a4304 | |||
2a467001f6 | |||
e587800164 | |||
38865fad3a | |||
fa807f3ffd | |||
a9c75cb099 | |||
699c36c019 | |||
f6ba23d463 | |||
b8f088e868 | |||
c5cef32897 | |||
4b0f1d753d | |||
40f79c1961 | |||
e136dd3df3 | |||
09ff9b650c | |||
59c8aaac34 | |||
5858c8e776 | |||
686f2ce822 | |||
144fa01c2f | |||
024646de54 | |||
57e04f55dc | |||
531012df1a | |||
d1e35c9573 | |||
4950294c26 | |||
e2bb1d3b42 | |||
288219fd6b | |||
4a3504612c | |||
97bfe1e043 | |||
053c032a70 | |||
2906d6a522 |
23
.editorconfig
Normal file
23
.editorconfig
Normal file
@ -0,0 +1,23 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
charset = utf-8
|
||||
|
||||
[{*.lua,*.rockspec,.luacheckrc}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
|
||||
[*.html]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.{c,h}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
45
.github/workflows/build.yml
vendored
Normal file
45
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Test build on ${{ matrix.platform }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ]
|
||||
platform: [ "ubuntu-20.04", "macos-11" ] # "windows-2022" not supported by gh-actions-lua
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Setup ‘lua’
|
||||
uses: leafo/gh-actions-lua@v9
|
||||
with:
|
||||
luaVersion: ${{ matrix.luaVersion }}
|
||||
- name: Setup ‘luarocks’
|
||||
uses: leafo/gh-actions-luarocks@v4
|
||||
- name: Make and install
|
||||
run: |
|
||||
export DEBUG=DEBUG
|
||||
luarocks make -- luasocket-scm-3.rockspec
|
||||
- name: Run regression tests
|
||||
run: |
|
||||
cd test
|
||||
lua hello.lua
|
||||
lua testsrvr.lua > /dev/null &
|
||||
lua testclnt.lua
|
||||
lua stufftest.lua
|
||||
lua excepttest.lua
|
||||
lua test_bind.lua
|
||||
lua test_getaddrinfo.lua
|
||||
lua ltn12test.lua
|
||||
lua mimetest.lua
|
||||
lua urltest.lua
|
||||
lua test_socket_error.lua
|
||||
kill %1
|
34
.github/workflows/deploy.yml
vendored
Normal file
34
.github/workflows/deploy.yml
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
name: Deploy
|
||||
|
||||
on: [ push, workflow_dispatch ]
|
||||
|
||||
jobs:
|
||||
|
||||
affected:
|
||||
uses: lunarmodules/.github/.github/workflows/list_affected_rockspecs.yml@main
|
||||
|
||||
build:
|
||||
needs: affected
|
||||
if: ${{ needs.affected.outputs.rockspecs }}
|
||||
uses: lunarmodules/.github/.github/workflows/test_build_rock.yml@main
|
||||
with:
|
||||
rockspecs: ${{ needs.affected.outputs.rockspecs }}
|
||||
|
||||
upload:
|
||||
needs: [ affected, build ]
|
||||
# Only run upload if:
|
||||
# 1. We are on the canonical repository (no uploads from forks)
|
||||
# 2. The current commit is either tagged or on the default branch (the workflow will upload dev/scm rockspecs any
|
||||
# time they are touched, tagged ones whenever the edited rockspec and tag match)
|
||||
# 3. Some rockspecs were changed — this implies the commit changing the rockspec is the same one that gets tagged
|
||||
if: >-
|
||||
${{
|
||||
github.repository == 'lunarmodules/luasocket' &&
|
||||
( github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/') ) &&
|
||||
needs.affected.outputs.rockspecs
|
||||
}}
|
||||
uses: lunarmodules/.github/.github/workflows/upload_to_luarocks.yml@main
|
||||
with:
|
||||
rockspecs: ${{ needs.affected.outputs.rockspecs }}
|
||||
secrets:
|
||||
apikey: ${{ secrets.LUAROCKS_APIKEY }}
|
13
.github/workflows/luacheck.yml
vendored
Normal file
13
.github/workflows/luacheck.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
name: Luacheck
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
|
||||
luacheck:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Luacheck
|
||||
uses: lunarmodules/luacheck@v0
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,7 +6,6 @@
|
||||
*.dll*
|
||||
*.user
|
||||
*.sdf
|
||||
Lua.props
|
||||
Debug
|
||||
Release
|
||||
*.manifest
|
||||
|
31
.luacheckrc
Normal file
31
.luacheckrc
Normal file
@ -0,0 +1,31 @@
|
||||
unused_args = false
|
||||
redefined = false
|
||||
max_line_length = false
|
||||
|
||||
not_globals = {
|
||||
"string.len",
|
||||
"table.getn",
|
||||
}
|
||||
|
||||
include_files = {
|
||||
"**/*.lua",
|
||||
"**/*.rockspec",
|
||||
".busted",
|
||||
".luacheckrc",
|
||||
}
|
||||
|
||||
exclude_files = {
|
||||
"etc/*.lua",
|
||||
"etc/**/*.lua",
|
||||
"test/*.lua",
|
||||
"test/**/*.lua",
|
||||
"samples/*.lua",
|
||||
"samples/**/*.lua",
|
||||
"gem/*.lua",
|
||||
"gem/**/*.lua",
|
||||
-- GH Actions Lua Environment
|
||||
".lua",
|
||||
".luarocks",
|
||||
".install",
|
||||
}
|
||||
|
54
.travis.yml
54
.travis.yml
@ -1,54 +0,0 @@
|
||||
language: erlang
|
||||
|
||||
env:
|
||||
global:
|
||||
- LUAROCKS_BASE=luarocks-2.0.13
|
||||
matrix:
|
||||
- LUA=lua5.1 LUA_DEV=liblua5.1-dev LUA_VER=5.1 LUA_SFX=5.1 LUA_INCDIR=/usr/include/lua5.1
|
||||
- LUA=lua5.2 LUA_DEV=liblua5.2-dev LUA_VER=5.2 LUA_SFX=5.2 LUA_INCDIR=/usr/include/lua5.2
|
||||
- LUA=luajit LUA_DEV=libluajit-5.1-dev LUA_VER=5.1 LUA_SFX=jit LUA_INCDIR=/usr/include/luajit-2.0
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
before_install:
|
||||
- if [ $LUA = "luajit" ]; then
|
||||
sudo add-apt-repository ppa:mwild1/ppa -y && sudo apt-get update -y;
|
||||
fi
|
||||
- sudo apt-get install $LUA
|
||||
- sudo apt-get install $LUA_DEV
|
||||
- lua$LUA_SFX -v
|
||||
# Install a recent luarocks release
|
||||
- wget http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz
|
||||
- tar zxvpf $LUAROCKS_BASE.tar.gz
|
||||
- cd $LUAROCKS_BASE
|
||||
- ./configure
|
||||
--lua-version=$LUA_VER --lua-suffix=$LUA_SFX --with-lua-include="$LUA_INCDIR"
|
||||
- sudo make
|
||||
- sudo make install
|
||||
- cd $TRAVIS_BUILD_DIR
|
||||
|
||||
|
||||
install:
|
||||
- export DEBUG=DEBUG
|
||||
- sudo -E luarocks make luasocket-scm-0.rockspec
|
||||
|
||||
script:
|
||||
- cd test
|
||||
- lua$LUA_SFX hello.lua
|
||||
- lua$LUA_SFX testsrvr.lua > /dev/null &
|
||||
- lua$LUA_SFX testclnt.lua
|
||||
- lua$LUA_SFX stufftest.lua
|
||||
- lua$LUA_SFX excepttest.lua
|
||||
- lua$LUA_SFX test_bind.lua
|
||||
- lua$LUA_SFX test_getaddrinfo.lua
|
||||
- lua$LUA_SFX ltn12test.lua
|
||||
- lua$LUA_SFX mimetest.lua
|
||||
- lua$LUA_SFX urltest.lua
|
||||
- lua$LUA_SFX test_socket_error.lua
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: change
|
||||
on_failure: always
|
65
CHANGELOG.md
Normal file
65
CHANGELOG.md
Normal file
@ -0,0 +1,65 @@
|
||||
# Changelog
|
||||
|
||||
## [v3.1.0](https://github.com/lunarmodules/luasocket/releases/v3.1.0) — 2022-07-27
|
||||
|
||||
* Add support for TCP Defer Accept – @Zash
|
||||
* Add support for TCP Fast Open – @Zash
|
||||
* Fix Windows (mingw32) builds – @goldenstein64
|
||||
* Avoid build warnings on 64-bit Windows – @rpatters1
|
||||
|
||||
## [v3.0.0](https://github.com/lunarmodules/luasocket/releases/v3.0.0) — 2022-03-25
|
||||
|
||||
The last time LuaSocket had a stable release tag was 14 years ago when 2.0.2 was tagged.
|
||||
A v3 release candidate was tagged 9 years ago.
|
||||
Since then it has been downloaded over 3 million times.
|
||||
Additionally the Git repository regularly gets several hundred clones a day.
|
||||
But 9 years is a long time and even the release candidate has grown a bit long in the tooth.
|
||||
Many Linux distros have packaged the current Git HEAD or some specific tested point as dated or otherwise labeled releases.
|
||||
256 commits later and having been migrated to the @lunarmodules org namespace on GitHub, please welcome v3.
|
||||
|
||||
This release is a "safe-harbor" tag that represents a minimal amount of changes to get a release tagged.
|
||||
Beyond some CI tooling, very little code has changed since migration to @lunarmodules ([5b18e47..e47d98f](https://github.com/lunarmodules/luasocket/compare/5b18e47..e47d98f?w=1)):
|
||||
|
||||
* Lua 5.4.3+ support – @pkulchenko, @Zash
|
||||
* Cleanup minor issues to get a code linter to pass – @Tieske, @jyoui, @alerque
|
||||
* Update Visual Studio build rules for Lua 5.1 – @ewestbrook
|
||||
* Set http transfer-encoding even without content-length – @tokenrove
|
||||
|
||||
Prior to migration to @lunarmodules ([v3.0-rc1..5b18e47](https://github.com/lunarmodules/luasocket/compare/v3.0-rc1..5b18e47?w=1)) many things happened of which the author of this changelog is not fully apprised.
|
||||
Your best bet if it affects your project somehow is to read the commit log & diffs yourself.
|
||||
|
||||
## [v3.0-rc1](https://github.com/lunarmodules/luasocket/releases/v3.0-rc1) — 2013-06-14
|
||||
|
||||
Main changes for LuaSocket 3.0-rc1 are IPv6 support and Lua 5.2 compatibility.
|
||||
|
||||
* Added: Compatible with Lua 5.2
|
||||
- Note that unless you define LUA_COMPAT_MODULE, package tables will not be exported as globals!
|
||||
* Added: IPv6 support;
|
||||
- Socket.connect and socket.bind support IPv6 addresses;
|
||||
- Getpeername and getsockname support IPv6 addresses, and return the socket family as a third value;
|
||||
- URL module updated to support IPv6 host names;
|
||||
- New socket.tcp6 and socket.udp6 functions;
|
||||
- New socket.dns.getaddrinfo and socket.dns.getnameinfo functions;
|
||||
* Added: getoption method;
|
||||
* Fixed: url.unescape was returning additional values;
|
||||
* Fixed: mime.qp, mime.unqp, mime.b64, and mime.unb64 could mistaking their own stack slots for functions arguments;
|
||||
* Fixed: Receiving zero-length datagram is now possible;
|
||||
* Improved: Hidden all internal library symbols;
|
||||
* Improved: Better error messages;
|
||||
* Improved: Better documentation of socket options.
|
||||
* Fixed: manual sample of HTTP authentication now uses correct "authorization" header (Alexandre Ittner);
|
||||
* Fixed: failure on bind() was destroying the socket (Sam Roberts);
|
||||
* Fixed: receive() returns immediatelly if prefix can satisfy bytes requested (M Joonas Pihlaja);
|
||||
* Fixed: multicast didn't work on Windows, or anywhere else for that matter (Herbert Leuwer, Adrian Sietsma);
|
||||
* Fixed: select() now reports an error when called with more sockets than FD_SETSIZE (Lorenzo Leonini);
|
||||
* Fixed: manual links to home.html changed to index.html (Robert Hahn);
|
||||
* Fixed: mime.unb64() would return an empty string on results that started with a null character (Robert Raschke);
|
||||
* Fixed: HTTP now automatically redirects on 303 and 307 (Jonathan Gray);
|
||||
* Fixed: calling sleep() with negative numbers could block forever, wasting CPU. Now it returns immediately (MPB);
|
||||
* Improved: FTP commands are now sent in upper case to help buggy servers (Anders Eurenius);
|
||||
* Improved: known headers now sent in canonic capitalization to help buggy servers (Joseph Stewart);
|
||||
* Improved: Clarified tcp:receive() in the manual (MPB);
|
||||
* Improved: Decent makefiles (LHF).
|
||||
* Fixed: RFC links in documentation now point to IETF (Cosmin Apreutesei).
|
||||
|
||||
## [v2.0.2](https://github.com/lunarmodules/luasocket/releases/v2.0.2) — 2007-09-11
|
3
LICENSE
3
LICENSE
@ -1,5 +1,4 @@
|
||||
LuaSocket 3.0 license
|
||||
Copyright <20> 2004-2013 Diego Nehab
|
||||
Copyright (C) 2004-2022 Diego Nehab
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
49
Lua.props
Executable file
49
Lua.props
Executable file
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'" Label="LuaPlat">
|
||||
<LUAPLAT>$(Platform)/$(Configuration)</LUAPLAT>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='Win32'" Label="LuaPlat">
|
||||
<LUAPLAT>$(Configuration)</LUAPLAT>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="UserMacros">
|
||||
<LUAV>5.3</LUAV>
|
||||
<LUAPREFIX>z:\data\build\vc14\</LUAPREFIX>
|
||||
<LUALIB>$(LUAPREFIX)\lib\lua\$(LUAV)\$(LUAPLAT)</LUALIB>
|
||||
<LUACDIR>$(LUAPREFIX)\bin\lua\$(LUAV)\$(LUAPLAT)</LUACDIR>
|
||||
<LUALDIR>$(LUAPREFIX)\bin\lua\$(LUAV)\$(LUAPLAT)\lua</LUALDIR>
|
||||
<LUAINC>$(LUAPREFIX)\include\lua\$(LUAV);$(LUAPREFIX)\include\lua$(LUAV)</LUAINC>
|
||||
<LUALIBNAME>lua$(LUAV.Replace('.', '')).lib</LUALIBNAME>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<_PropertySheetDisplayName>Lua</_PropertySheetDisplayName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup />
|
||||
<ItemGroup>
|
||||
<BuildMacro Include="LUAPLAT">
|
||||
<Value>$(LUAPLAT)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUAPREFIX">
|
||||
<Value>$(LUAPREFIX)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUAV">
|
||||
<Value>$(LUAV)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUALIB">
|
||||
<Value>$(LUALIB)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUAINC">
|
||||
<Value>$(LUAINC)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUACDIR">
|
||||
<Value>$(LUACDIR)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUALDIR">
|
||||
<Value>$(LUALDIR)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUALIBNAME">
|
||||
<Value>$(LUALIBNAME)</Value>
|
||||
</BuildMacro>
|
||||
</ItemGroup>
|
||||
</Project>
|
28
Lua51.props
28
Lua51.props
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros">
|
||||
<LUABIN_PATH>..\build\vc12\bin\lua\5.1\</LUABIN_PATH>
|
||||
<LUALIB_PATH>..\build\vc12\bin\lua\5.1\</LUALIB_PATH>
|
||||
<LUAINC_PATH>..\build\vc12\include\lua\5.1\</LUAINC_PATH>
|
||||
<LUALIB>lua51.lib</LUALIB>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<_PropertySheetDisplayName>Lua51</_PropertySheetDisplayName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup />
|
||||
<ItemGroup>
|
||||
<BuildMacro Include="LUALIB_PATH">
|
||||
<Value>$(LUALIB_PATH)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUABIN_PATH">
|
||||
<Value>$(LUABIN_PATH)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUAINC_PATH">
|
||||
<Value>$(LUAINC_PATH)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUALIB">
|
||||
<Value>$(LUALIB)</Value>
|
||||
</BuildMacro>
|
||||
</ItemGroup>
|
||||
</Project>
|
28
Lua52.props
28
Lua52.props
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros">
|
||||
<LUABIN_PATH>..\build\vc12\bin\lua\5.2\</LUABIN_PATH>
|
||||
<LUALIB_PATH>..\build\vc12\bin\lua\5.2\</LUALIB_PATH>
|
||||
<LUAINC_PATH>..\build\vc12\include\lua\5.2\</LUAINC_PATH>
|
||||
<LUALIB>lua52.lib</LUALIB>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<_PropertySheetDisplayName>Lua52</_PropertySheetDisplayName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup />
|
||||
<ItemGroup>
|
||||
<BuildMacro Include="LUALIB_PATH">
|
||||
<Value>$(LUALIB_PATH)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUABIN_PATH">
|
||||
<Value>$(LUABIN_PATH)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUAINC_PATH">
|
||||
<Value>$(LUAINC_PATH)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="LUALIB">
|
||||
<Value>$(LUALIB)</Value>
|
||||
</BuildMacro>
|
||||
</ItemGroup>
|
||||
</Project>
|
44
NEW
44
NEW
@ -1,44 +0,0 @@
|
||||
What's New
|
||||
|
||||
Main changes for LuaSocket 3.0-rc1 are IPv6 support and Lua 5.2 compatibility.
|
||||
|
||||
* Added: Compatible with Lua 5.2
|
||||
- Note that unless you define LUA_COMPAT_MODULE, package
|
||||
tables will not be exported as globals!
|
||||
* Added: IPv6 support;
|
||||
- Socket.connect and socket.bind support IPv6 addresses;
|
||||
- Getpeername and getsockname support IPv6 addresses, and
|
||||
return the socket family as a third value;
|
||||
- URL module updated to support IPv6 host names;
|
||||
- New socket.tcp6 and socket.udp6 functions;
|
||||
- New socket.dns.getaddrinfo and socket.dns.getnameinfo functions;
|
||||
* Added: getoption method;
|
||||
* Fixed: url.unescape was returning additional values;
|
||||
* Fixed: mime.qp, mime.unqp, mime.b64, and mime.unb64 could
|
||||
mistaking their own stack slots for functions arguments;
|
||||
* Fixed: Receiving zero-length datagram is now possible;
|
||||
* Improved: Hidden all internal library symbols;
|
||||
* Improved: Better error messages;
|
||||
* Improved: Better documentation of socket options.
|
||||
* Fixed: manual sample of HTTP authentication now uses correct
|
||||
"authorization" header (Alexandre Ittner);
|
||||
* Fixed: failure on bind() was destroying the socket (Sam Roberts);
|
||||
* Fixed: receive() returns immediatelly if prefix can satisfy
|
||||
bytes requested (M Joonas Pihlaja);
|
||||
* Fixed: multicast didn't work on Windows, or anywhere
|
||||
else for that matter (Herbert Leuwer, Adrian Sietsma);
|
||||
* Fixed: select() now reports an error when called with more
|
||||
sockets than FD_SETSIZE (Lorenzo Leonini);
|
||||
* Fixed: manual links to home.html changed to index.html (Robert Hahn);
|
||||
* Fixed: mime.unb64() would return an empty string on results that started
|
||||
with a null character (Robert Raschke);
|
||||
* Fixed: HTTP now automatically redirects on 303 and 307 (Jonathan Gray);
|
||||
* Fixed: calling sleep() with negative numbers could
|
||||
block forever, wasting CPU. Now it returns immediately (MPB);
|
||||
* Improved: FTP commands are now sent in upper case to
|
||||
help buggy servers (Anders Eurenius);
|
||||
* Improved: known headers now sent in canonic
|
||||
capitalization to help buggy servers (Joseph Stewart);
|
||||
* Improved: Clarified tcp:receive() in the manual (MPB);
|
||||
* Improved: Decent makefiles (LHF).
|
||||
* Fixed: RFC links in documentation now point to IETF (Cosmin Apreutesei).
|
11
README
11
README
@ -1,11 +0,0 @@
|
||||
This is the LuaSocket 3.0-rc1. It has been tested on Windows 7, Mac OS X,
|
||||
and Linux.
|
||||
|
||||
Please use the project page at GitHub
|
||||
|
||||
https://github.com/diegonehab/luasocket
|
||||
|
||||
to file bug reports or propose changes.
|
||||
|
||||
Have fun,
|
||||
Diego Nehab.
|
12
README.md
Normal file
12
README.md
Normal file
@ -0,0 +1,12 @@
|
||||
# LuaSocket
|
||||
|
||||
|
||||
[](https://github.com/lunarmodules/luasocket/actions?workflow=Build)
|
||||
[](https://github.com/lunarmodules/luasocket/actions?workflow=Luacheck)
|
||||
[](https://github.com/lunarmodules/luasocket/releases)
|
||||
[](https://luarocks.org/modules/lunarmodules/luasocket)
|
||||
|
||||
LuaSocket is a Lua extension library composed of two parts:
|
||||
|
||||
1. a set of C modules that provide support for the TCP and UDP transport layers, and
|
||||
2. a set of Lua modules that provide functions commonly needed by applications that deal with the Internet.
|
215
doc/index.html
215
doc/index.html
@ -1,215 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="The LuaSocket Homepage">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Network, Library, Support, Internet">
|
||||
<title>LuaSocket: Network support for the Lua language </title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- whatis +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=whatis>What is LuaSocket?</h2>
|
||||
|
||||
<p>
|
||||
LuaSocket is a <a href="http://www.lua.org">Lua</a> extension library
|
||||
that is composed by two parts: a C core that provides support for the TCP
|
||||
and UDP transport layers, and a set of Lua modules that add support for
|
||||
functionality commonly needed by applications that deal with the Internet.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The core support has been implemented so that it is both efficient and
|
||||
simple to use. It is available to any Lua application once it has been
|
||||
properly initialized by the interpreter in use. The code has been tested
|
||||
and runs well on several Windows and UNIX platforms. </p>
|
||||
|
||||
<p>
|
||||
Among the support modules, the most commonly used implement the
|
||||
<a href=smtp.html>SMTP</a>
|
||||
(sending e-mails),
|
||||
<a href=http.html>HTTP</a>
|
||||
(WWW access) and
|
||||
<a href=ftp.html>FTP</a>
|
||||
(uploading and downloading files) client
|
||||
protocols. These provide a very natural and generic interface to the
|
||||
functionality defined by each protocol.
|
||||
In addition, you will find that the
|
||||
<a href=mime.html>MIME</a> (common encodings),
|
||||
<a href=url.html>URL</a>
|
||||
(anything you could possible want to do with one) and
|
||||
<a href=ltn12.html>LTN12</a>
|
||||
(filters, sinks, sources and pumps) modules can be very handy.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The library is available under the same
|
||||
<a href="http://www.lua.org/copyright.html">
|
||||
terms and conditions</a> as the Lua language, the MIT license. The idea is
|
||||
that if you can use Lua in a project, you should also be able to use
|
||||
LuaSocket.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Copyright © 1999-2013 Diego Nehab. All rights reserved. <br>
|
||||
Author: <A href="http://www.impa.br/~diego">Diego Nehab</a>
|
||||
</p>
|
||||
|
||||
<!-- download +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=download>Download</h2>
|
||||
|
||||
<p>
|
||||
LuaSocket version 3.0-rc1 is now available for download!
|
||||
It is compatible with Lua 5.1 and 5.2, and has
|
||||
been tested on Windows XP, Linux, and Mac OS X. Chances
|
||||
are it works well on most UNIX distributions and Windows flavors.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The current version of the library can be found at
|
||||
the <a href="https://github.com/diegonehab/luasocket">LuaSocket
|
||||
project page</a> on GitHub. Besides the full C and Lua source code
|
||||
for the library, the distribution contains several examples,
|
||||
this user's manual and basic test procedures.
|
||||
</p>
|
||||
|
||||
<p> Take a look at the <a
|
||||
href=installation.html>installation</a> section of the
|
||||
manual to find out how to properly install the library.
|
||||
</p>
|
||||
|
||||
<!-- thanks +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=thanks>Special thanks</h2>
|
||||
|
||||
<p>
|
||||
This marks the first release of LuaSocket that
|
||||
wholeheartedly embraces the open-source development
|
||||
philosophy. After a long hiatus, Matthew Wild finally
|
||||
convinced me it was time for a release including IPv6 and
|
||||
Lua 5.2 support. It was more work than we anticipated.
|
||||
Special thanks to Sam Roberts, Florian Zeitz, and Paul
|
||||
Aurich, Liam Devine, Alexey Melnichuk, and everybody else
|
||||
that has helped bring this library back to life.
|
||||
</p>
|
||||
|
||||
<!-- whatsnew +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=new>What's New</h2>
|
||||
|
||||
<p>
|
||||
Main changes for LuaSocket 3.0-rc1 are IPv6 support
|
||||
and Lua 5.2 compatibility.
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> Added: Compatible with Lua 5.2
|
||||
<ul>
|
||||
<li> Note that unless you define <tt>LUA_COMPAT_MODULE</tt>,
|
||||
package tables will <em>not</em> be exported as globals!
|
||||
</ul>
|
||||
<li> Added: IPv6 support;
|
||||
<ul>
|
||||
<li> <tt>Socket.connect</tt> and <tt>socket.bind</tt> support IPv6 addresses;
|
||||
<li> <tt>Getpeername</tt> and <tt>getsockname</tt> support
|
||||
IPv6 addresses, and return the socket family as a third value;
|
||||
<li> URL module updated to support IPv6 host names;
|
||||
<li> New <tt>socket.tcp6</tt> and <tt>socket.udp6</tt> functions;
|
||||
<li> New <tt>socket.dns.getaddrinfo</tt> and
|
||||
<tt>socket.dns.getnameinfo</tt> functions;
|
||||
</ul>
|
||||
<li> Added: <tt>getoption</tt> method;
|
||||
<li> Fixed: <tt>url.unescape</tt> was returning additional values;
|
||||
<li> Fixed: <tt>mime.qp</tt>, <tt>mime.unqp</tt>,
|
||||
<tt>mime.b64</tt>, and <tt>mime.unb64</tt> could
|
||||
mistaking their own stack slots for functions arguments;
|
||||
<li> Fixed: Receiving zero-length datagram is now possible;
|
||||
<li> Improved: Hidden all internal library symbols;
|
||||
<li> Improved: Better error messages;
|
||||
<li> Improved: Better documentation of socket options.
|
||||
<li> Fixed: manual sample of HTTP authentication now uses correct
|
||||
"authorization" header (Alexandre Ittner);
|
||||
<li> Fixed: failure on bind() was destroying the socket (Sam Roberts);
|
||||
<li> Fixed: receive() returns immediatelly if prefix can satisfy
|
||||
bytes requested (M Joonas Pihlaja);
|
||||
<li> Fixed: multicast didn't work on Windows, or anywhere
|
||||
else for that matter (Herbert Leuwer, Adrian Sietsma);
|
||||
<li> Fixed: select() now reports an error when called with more
|
||||
sockets than FD_SETSIZE (Lorenzo Leonini);
|
||||
<li> Fixed: manual links to home.html changed to index.html
|
||||
(Robert Hahn);
|
||||
<li> Fixed: mime.unb64() would return an empty string on results that started
|
||||
with a null character (Robert Raschke);
|
||||
<li> Fixed: HTTP now automatically redirects on 303 and 307 (Jonathan Gray);
|
||||
<li> Fixed: calling sleep() with negative numbers could
|
||||
block forever, wasting CPU. Now it returns immediately (MPB);
|
||||
<li> Improved: FTP commands are now sent in upper case to
|
||||
help buggy servers (Anders Eurenius);
|
||||
<li> Improved: known headers now sent in canonic
|
||||
capitalization to help buggy servers (Joseph Stewart);
|
||||
<li> Improved: Clarified tcp:receive() in the manual (MPB);
|
||||
<li> Improved: Decent makefiles (LHF).
|
||||
<li> Fixed: RFC links in documentation now point to IETF (Cosmin Apreutesei).
|
||||
</ul>
|
||||
|
||||
<!-- old ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=old>Old Versions</h2>
|
||||
|
||||
<p>
|
||||
All previous versions of the LuaSocket library can be downloaded <a
|
||||
href="http://www.impa.br/~diego/software/luasocket/old">
|
||||
here</a>. Although these versions are no longer supported, they are
|
||||
still available for those that have compatibility issues.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Tue Jun 11 18:50:23 HKT 2013
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,4 +1,4 @@
|
||||
<!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">
|
||||
<html>
|
||||
|
||||
@ -13,22 +13,22 @@
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
<tr><td align="center"><a href="http://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
@ -36,14 +36,14 @@
|
||||
|
||||
<!-- dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=dns>DNS</h2>
|
||||
<h2 id="dns">DNS</h2>
|
||||
|
||||
<p>
|
||||
IPv4 name resolution functions
|
||||
<a href=#toip><tt>dns.toip</tt></a>
|
||||
IPv4 name resolution functions
|
||||
<a href="#toip"><tt>dns.toip</tt></a>
|
||||
and
|
||||
<a href=#tohostname><tt>dns.tohostname</tt></a>
|
||||
return <em>all</em> information obtained from
|
||||
<a href="#tohostname"><tt>dns.tohostname</tt></a>
|
||||
return <em>all</em> information obtained from
|
||||
the resolver in a table of the form:
|
||||
</p>
|
||||
|
||||
@ -60,10 +60,10 @@ Note that the <tt>alias</tt> list can be empty.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The more general name resolution function
|
||||
<a href=#getaddrinfo><tt>dns.getaddrinfo</tt></a>, which
|
||||
The more general name resolution function
|
||||
<a href="#getaddrinfo"><tt>dns.getaddrinfo</tt></a>, which
|
||||
supports both IPv6 and IPv4,
|
||||
returns <em>all</em> information obtained from
|
||||
returns <em>all</em> information obtained from
|
||||
the resolver in a table of the form:
|
||||
</p>
|
||||
|
||||
@ -88,82 +88,82 @@ addresses, and <tt>"inet6"</tt> for IPv6 addresses.
|
||||
|
||||
<!-- getaddrinfo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=getaddrinfo>
|
||||
<p class="name" id="getaddrinfo">
|
||||
socket.dns.<b>getaddrinfo(</b>address<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Converts from host name to address.
|
||||
<p class="description">
|
||||
Converts from host name to address.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Address</tt> can be an IPv4 or IPv6 address or host name.
|
||||
<p class="parameters">
|
||||
<tt>Address</tt> can be an IPv4 or IPv6 address or host name.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The function returns a table with all information returned by
|
||||
the resolver. In case of error, the function returns <b><tt>nil</tt></b>
|
||||
followed by an error message.
|
||||
followed by an error message.
|
||||
</p>
|
||||
|
||||
<!-- gethostname ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=gethostname>
|
||||
<p class="name" id="gethostname">
|
||||
socket.dns.<b>gethostname()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns the standard host name for the machine as a string.
|
||||
<p class="description">
|
||||
Returns the standard host name for the machine as a string.
|
||||
</p>
|
||||
|
||||
<!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=tohostname>
|
||||
<p class="name" id="tohostname">
|
||||
socket.dns.<b>tohostname(</b>address<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Converts from IPv4 address to host name.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Address</tt> can be an IP address or host name.
|
||||
<p class="parameters">
|
||||
<tt>Address</tt> can be an IP address or host name.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The function returns a string with the canonic host name of the given
|
||||
<tt>address</tt>, followed by a table with all information returned by
|
||||
the resolver. In case of error, the function returns <b><tt>nil</tt></b>
|
||||
followed by an error message.
|
||||
followed by an error message.
|
||||
</p>
|
||||
|
||||
<!-- toip +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=toip>
|
||||
<p class="name" id="toip">
|
||||
socket.dns.<b>toip(</b>address<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Converts from host name to IPv4 address.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Address</tt> can be an IP address or host name.
|
||||
<p class="parameters">
|
||||
<tt>Address</tt> can be an IP address or host name.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
Returns a string with the first IP address found for <tt>address</tt>,
|
||||
followed by a table with all information returned by the resolver.
|
||||
In case of error, the function returns <b><tt>nil</tt></b> followed by an error
|
||||
message.
|
||||
message.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
@ -13,22 +13,22 @@
|
||||
|
||||
<!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
<tr><td align="center"><a href="http://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
<!-- ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=ftp>FTP</h2>
|
||||
<h2 id="ftp">FTP</h2>
|
||||
|
||||
<p>
|
||||
FTP (File Transfer Protocol) is a protocol used to transfer files
|
||||
@ -50,28 +50,28 @@ High level functions are provided supporting the most common operations.
|
||||
These high level functions are implemented on top of a lower level
|
||||
interface. Using the low-level interface, users can easily create their
|
||||
own functions to access <em>any</em> operation supported by the FTP
|
||||
protocol. For that, check the implementation.
|
||||
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="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||
LTN012, Filters sources and sinks</a> is necessary.
|
||||
LTN012, Filters sources and sinks</a> is necessary.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<p>
|
||||
To obtain the <tt>ftp</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- loads the FTP module and any libraries it requires
|
||||
local ftp = require("socket.ftp")
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
URLs MUST conform to
|
||||
<a href="http://www.ietf.org/rfc/rfc1738.txt">RFC 1738</a>,
|
||||
that is, an URL is a string in the form:
|
||||
<a href="http://www.ietf.org/rfc/rfc1738.txt">RFC 1738</a>,
|
||||
that is, an URL is a string in the form:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
@ -81,19 +81,19 @@ that is, an URL is a string in the form:
|
||||
|
||||
<p>
|
||||
The following constants in the namespace can be set to control the default behavior of
|
||||
the FTP module:
|
||||
the FTP module:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> <tt>PASSWORD</tt>: default anonymous password.
|
||||
<li> <tt>TIMEOUT</tt>: sets the timeout for all I/O operations;
|
||||
<li> <tt>USER</tt>: default anonymous user;
|
||||
<li> <tt>PASSWORD</tt>: default anonymous password.</li>
|
||||
<li> <tt>TIMEOUT</tt>: sets the timeout for all I/O operations;</li>
|
||||
<li> <tt>USER</tt>: default anonymous user;</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<!-- ftp.get ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=get>
|
||||
<p class="name" id="get">
|
||||
ftp.<b>get(</b>url<b>)</b><br>
|
||||
ftp.<b>get{</b><br>
|
||||
host = <i>string</i>,<br>
|
||||
@ -109,19 +109,19 @@ ftp.<b>get{</b><br>
|
||||
<b>}</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
The <tt>get</tt> function has two forms. The simple form has fixed
|
||||
functionality: it downloads the contents of a URL and returns it as a
|
||||
string. The generic form allows a <em>lot</em> more control, as explained
|
||||
below.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
If the argument of the <tt>get</tt> function is a table, the function
|
||||
expects at least the fields <tt>host</tt>, <tt>sink</tt>, and one of
|
||||
expects at least the fields <tt>host</tt>, <tt>sink</tt>, and one of
|
||||
<tt>argument</tt> or <tt>path</tt> (<tt>argument</tt> takes
|
||||
precedence). <tt>Host</tt> is the server to connect to. <tt>Sink</tt> is
|
||||
the <em>simple</em>
|
||||
the <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
sink that will receive the downloaded data. <tt>Argument</tt> or
|
||||
<tt>path</tt> give the target path to the resource in the server. The
|
||||
@ -129,28 +129,28 @@ optional arguments are the following:
|
||||
</p>
|
||||
<ul>
|
||||
<li><tt>user</tt>, <tt>password</tt>: User name and password used for
|
||||
authentication. Defaults to "<tt>ftp:anonymous@anonymous.org</tt>";
|
||||
authentication. Defaults to "<tt>ftp:anonymous@anonymous.org</tt>";</li>
|
||||
<li><tt>command</tt>: The FTP command used to obtain data. Defaults to
|
||||
"<tt>retr</tt>", but see example below;
|
||||
<li><tt>port</tt>: The port to used for the control connection. Defaults to 21;
|
||||
"<tt>retr</tt>", but see example below;</li>
|
||||
<li><tt>port</tt>: The port to used for the control connection. Defaults to 21;</li>
|
||||
<li><tt>type</tt>: The transfer mode. Can take values "<tt>i</tt>" or
|
||||
"<tt>a</tt>". Defaults to whatever is the server default;
|
||||
<li><tt>step</tt>:
|
||||
"<tt>a</tt>". Defaults to whatever is the server default;</li>
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
pump step function used to pass data from the
|
||||
server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;
|
||||
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
|
||||
<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
|
||||
<a href="tcp.html#socket.tcp"><tt>socket.tcp</tt></a> when the communications socket is created.</li>
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
If successful, the simple version returns the URL contents as a
|
||||
string, and the generic function returns 1. In case of error, both
|
||||
functions return <b><tt>nil</tt></b> and an error message describing the
|
||||
error.
|
||||
error.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load the ftp support
|
||||
local ftp = require("socket.ftp")
|
||||
|
||||
@ -159,7 +159,7 @@ local ftp = require("socket.ftp")
|
||||
f, e = ftp.get("ftp://ftp.tecgraf.puc-rio.br/pub/lua/lua.tar.gz;type=i")
|
||||
</pre>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load needed modules
|
||||
local ftp = require("socket.ftp")
|
||||
local ltn12 = require("ltn12")
|
||||
@ -178,7 +178,7 @@ end
|
||||
|
||||
<!-- put ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=put>
|
||||
<p class="name" id="put">
|
||||
ftp.<b>put(</b>url, content<b>)</b><br>
|
||||
ftp.<b>put{</b><br>
|
||||
host = <i>string</i>,<br>
|
||||
@ -194,57 +194,57 @@ ftp.<b>put{</b><br>
|
||||
<b>}</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
The <tt>put</tt> function has two forms. The simple form has fixed
|
||||
functionality: it uploads a string of content into a URL. The generic form
|
||||
allows a <em>lot</em> more control, as explained below.
|
||||
allows a <em>lot</em> more control, as explained below.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
If the argument of the <tt>put</tt> function is a table, the function
|
||||
expects at least the fields <tt>host</tt>, <tt>source</tt>, and one of
|
||||
expects at least the fields <tt>host</tt>, <tt>source</tt>, and one of
|
||||
<tt>argument</tt> or <tt>path</tt> (<tt>argument</tt> takes
|
||||
precedence). <tt>Host</tt> is the server to connect to. <tt>Source</tt> is
|
||||
the <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
source that will provide the contents to be uploaded.
|
||||
the <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
source that will provide the contents to be uploaded.
|
||||
<tt>Argument</tt> or
|
||||
<tt>path</tt> give the target path to the resource in the server. The
|
||||
optional arguments are the following:
|
||||
</p>
|
||||
<ul>
|
||||
<li><tt>user</tt>, <tt>password</tt>: User name and password used for
|
||||
authentication. Defaults to "<tt>ftp:anonymous@anonymous.org</tt>";
|
||||
authentication. Defaults to "<tt>ftp:anonymous@anonymous.org</tt>";</li>
|
||||
<li><tt>command</tt>: The FTP command used to send data. Defaults to
|
||||
"<tt>stor</tt>", but see example below;
|
||||
<li><tt>port</tt>: The port to used for the control connection. Defaults to 21;
|
||||
"<tt>stor</tt>", but see example below;</li>
|
||||
<li><tt>port</tt>: The port to used for the control connection. Defaults to 21;</li>
|
||||
<li><tt>type</tt>: The transfer mode. Can take values "<tt>i</tt>" or
|
||||
"<tt>a</tt>". Defaults to whatever is the server default;
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
"<tt>a</tt>". Defaults to whatever is the server default;</li>
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
pump step function used to pass data from the
|
||||
server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;
|
||||
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
|
||||
<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
|
||||
<a href="tcp.html#socket.tcp"><tt>socket.tcp</tt></a> when the communications socket is created.</li>
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
Both functions return 1 if successful, or <b><tt>nil</tt></b> and an error
|
||||
message describing the reason for failure.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load the ftp support
|
||||
local ftp = require("socket.ftp")
|
||||
|
||||
-- Log as user "fulano" on server "ftp.example.com",
|
||||
-- using password "silva", and store a file "README" with contents
|
||||
-- using password "silva", and store a file "README" with contents
|
||||
-- "wrong password, of course"
|
||||
f, e = ftp.put("ftp://fulano:silva@ftp.example.com/README",
|
||||
f, e = ftp.put("ftp://fulano:silva@ftp.example.com/README",
|
||||
"wrong password, of course")
|
||||
</pre>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load the ftp support
|
||||
local ftp = require("socket.ftp")
|
||||
local ltn12 = require("ltn12")
|
||||
@ -253,7 +253,7 @@ local ltn12 = require("ltn12")
|
||||
-- using password "silva", and append to the remote file "LOG", sending the
|
||||
-- contents of the local file "LOCAL-LOG"
|
||||
f, e = ftp.put{
|
||||
host = "ftp.example.com",
|
||||
host = "ftp.example.com",
|
||||
user = "fulano",
|
||||
password = "silva",
|
||||
command = "appe",
|
||||
@ -265,15 +265,15 @@ f, e = ftp.put{
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
@ -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">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: HTTP support">
|
||||
<meta name="keywords" content="Lua, HTTP, Library, WWW, Browser, Network, Support">
|
||||
<meta name="keywords" content="Lua, HTTP, Library, WWW, Browser, Network, Support">
|
||||
<title>LuaSocket: HTTP support</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
@ -13,22 +13,22 @@
|
||||
|
||||
<!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
<tr><td align="center"><a href="http://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</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>
|
||||
</center>
|
||||
<hr>
|
||||
@ -36,12 +36,12 @@
|
||||
|
||||
<!-- http +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id="http">HTTP</h2>
|
||||
<h2 id="http">HTTP</h2>
|
||||
|
||||
<p>
|
||||
HTTP (Hyper Text Transfer Protocol) is the protocol used to exchange
|
||||
information between web-browsers and servers. The <tt>http</tt>
|
||||
namespace offers full support for the client side of the HTTP
|
||||
namespace offers full support for the client side of the HTTP
|
||||
protocol (i.e.,
|
||||
the facilities that would be used by a web-browser implementation). The
|
||||
implementation conforms to the HTTP/1.1 standard,
|
||||
@ -50,16 +50,16 @@ implementation conforms to the HTTP/1.1 standard,
|
||||
|
||||
<p>
|
||||
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
|
||||
<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>
|
||||
To obtain the <tt>http</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- loads the HTTP module and any libraries it requires
|
||||
local http = require("socket.http")
|
||||
</pre>
|
||||
@ -67,12 +67,12 @@ local http = require("socket.http")
|
||||
<p>
|
||||
URLs must conform to
|
||||
<a href="http://www.ietf.org/rfc/rfc1738.txt">RFC 1738</a>,
|
||||
that is, an URL is a string in the form:
|
||||
that is, an URL is a string in the form:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
[http://][<user>[:<password>]@]<host>[:<port>][/<path>]
|
||||
[http://][<user>[:<password>]@]<host>[:<port>][/<path>]
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
@ -97,34 +97,34 @@ headers = {<br>
|
||||
<p>
|
||||
Field names are case insensitive (as specified by the standard) and all
|
||||
functions work with lowercase field names (but see
|
||||
<a href=socket.html#headers.canonic><tt>socket.headers.canonic</tt></a>).
|
||||
<a href="socket.html#headers.canonic"><tt>socket.headers.canonic</tt></a>).
|
||||
Field values are left unmodified.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: MIME headers are independent of order. Therefore, there is no problem
|
||||
in representing them in a Lua table.
|
||||
in representing them in a Lua table.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The following constants can be set to control the default behavior of
|
||||
the HTTP module:
|
||||
the HTTP module:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> <tt>PROXY</tt>: default proxy used for connections;
|
||||
<li> <tt>TIMEOUT</tt>: sets the timeout for all I/O operations;
|
||||
<li> <tt>USERAGENT</tt>: default user agent reported to server.
|
||||
<li> <tt>PROXY</tt>: default proxy used for connections;</li>
|
||||
<li> <tt>TIMEOUT</tt>: sets the timeout for all I/O operations;</li>
|
||||
<li> <tt>USERAGENT</tt>: default user agent reported to server.</li>
|
||||
</ul>
|
||||
|
||||
<p class=note id="post">
|
||||
<p class="note">
|
||||
Note: These constants are global. Changing them will also
|
||||
change the behavior other code that might be using LuaSocket.
|
||||
</p>
|
||||
|
||||
<!-- http.request ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="request">
|
||||
<p class="name" id="request">
|
||||
http.<b>request(</b>url [, body]<b>)</b><br>
|
||||
http.<b>request{</b><br>
|
||||
url = <i>string</i>,<br>
|
||||
@ -135,30 +135,31 @@ http.<b>request{</b><br>
|
||||
[step = <i>LTN12 pump step</i>,]<br>
|
||||
[proxy = <i>string</i>,]<br>
|
||||
[redirect = <i>boolean</i>,]<br>
|
||||
[create = <i>function</i>]<br>
|
||||
[create = <i>function</i>,]<br>
|
||||
[maxredirects = <i>number</i>]<br>
|
||||
<b>}</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
The request function has two forms. The simple form downloads
|
||||
a URL using the <tt>GET</tt> or <tt>POST</tt> method and is based
|
||||
on strings. The generic form performs any HTTP method and is
|
||||
<a href=http://lua-users.org/wiki/FiltersSourcesAndSinks>LTN12</a> based.
|
||||
<p class="description">
|
||||
The request function has two forms. The simple form downloads
|
||||
a URL using the <tt>GET</tt> or <tt>POST</tt> method and is based
|
||||
on strings. The generic form performs any HTTP method and is
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> based.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
If the first argument of the <tt>request</tt> function is a string, it
|
||||
should be an <tt>url</tt>. In that case, if a <tt>body</tt>
|
||||
is provided as a string, the function will perform a <tt>POST</tt> method
|
||||
in the <tt>url</tt>. Otherwise, it performs a <tt>GET</tt> in the
|
||||
<tt>url</tt>
|
||||
<tt>url</tt>
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
If the first argument is instead a table, the most important fields are
|
||||
<p class="parameters">
|
||||
If the first argument is instead a table, the most important fields are
|
||||
the <tt>url</tt> and the <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<tt>sink</tt> that will receive the downloaded content.
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<tt>sink</tt> that will receive the downloaded content.
|
||||
Any part of the <tt>url</tt> can be overridden by including
|
||||
the appropriate field in the request table.
|
||||
If authentication information is provided, the function
|
||||
@ -168,48 +169,51 @@ function discards the downloaded data. The optional parameters are the
|
||||
following:
|
||||
</p>
|
||||
<ul>
|
||||
<li><tt>method</tt>: The HTTP request method. Defaults to "GET";
|
||||
<li><tt>headers</tt>: Any additional HTTP headers to send with the request;
|
||||
<li><tt>source</tt>: <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<li><tt>method</tt>: The HTTP request method. Defaults to "GET";</li>
|
||||
<li><tt>headers</tt>: Any additional HTTP headers to send with the request;</li>
|
||||
<li><tt>source</tt>: <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
source to provide the request body. If there
|
||||
is a body, you need to provide an appropriate "<tt>content-length</tt>"
|
||||
request header field, or the function will attempt to send the body as
|
||||
"<tt>chunked</tt>" (something few servers support). Defaults to the empty source;
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
pump step function used to move data.
|
||||
Defaults to the LTN12 <tt>pump.step</tt> function.
|
||||
<li><tt>proxy</tt>: The URL of a proxy server to use. Defaults to no proxy;
|
||||
<li><tt>redirect</tt>: Set to <tt><b>false</b></tt> to prevent the
|
||||
function from automatically following 301 or 302 server redirect messages;
|
||||
"<tt>chunked</tt>" (something few servers support). Defaults to the empty source;</li>
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
pump step function used to move data.
|
||||
Defaults to the LTN12 <tt>pump.step</tt> function.</li>
|
||||
<li><tt>proxy</tt>: The URL of a proxy server to use. Defaults to no proxy;</li>
|
||||
<li><tt>redirect</tt>: Set to <tt><b>false</b></tt> to prevent the
|
||||
function from automatically following 301 or 302 server redirect messages;</li>
|
||||
<li><tt>create</tt>: An optional function to be used instead of
|
||||
<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
|
||||
<a href="tcp.html#socket.tcp"><tt>socket.tcp</tt></a> when the communications socket is created.</li>
|
||||
<li><tt>maxredirects</tt>: An optional number specifying the maximum number of
|
||||
redirects to follow. Defaults to <tt>5</tt> if not specified. A boolean
|
||||
<tt>false</tt> value means no maximum (unlimited).</li>
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
In case of failure, the function returns <tt><b>nil</b></tt> followed by an
|
||||
error message. If successful, the simple form returns the response
|
||||
error message. If successful, the simple form returns the response
|
||||
body as a string, followed by the response status code, the response
|
||||
headers and the response status line. The generic function returns the same
|
||||
information, except the first return value is just the number 1 (the body
|
||||
goes to the <tt>sink</tt>).
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
Even when the server fails to provide the contents of the requested URL (URL not found, for example),
|
||||
<p class="return">
|
||||
Even when the server fails to provide the contents of the requested URL (URL not found, for example),
|
||||
it usually returns a message body (a web page informing the
|
||||
URL was not found or some other useless page). To make sure the
|
||||
operation was successful, check the returned status <tt>code</tt>. For
|
||||
a list of the possible values and their meanings, refer to <a
|
||||
href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a>.
|
||||
href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a>.
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Here are a few examples with the simple interface:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load the http module
|
||||
local io = require("io")
|
||||
local http = require("socket.http")
|
||||
@ -217,15 +221,15 @@ local ltn12 = require("ltn12")
|
||||
|
||||
-- connect to server "www.cs.princeton.edu" and retrieves this manual
|
||||
-- file from "~diego/professional/luasocket/http.html" and print it to stdout
|
||||
http.request{
|
||||
url = "http://www.cs.princeton.edu/~diego/professional/luasocket/http.html",
|
||||
http.request{
|
||||
url = "http://www.cs.princeton.edu/~diego/professional/luasocket/http.html",
|
||||
sink = ltn12.sink.file(io.stdout)
|
||||
}
|
||||
|
||||
-- connect to server "www.example.com" and tries to retrieve
|
||||
-- "/private/index.html". Fails because authentication is needed.
|
||||
b, c, h = http.request("http://www.example.com/private/index.html")
|
||||
-- b returns some useless page telling about the denied access,
|
||||
-- b returns some useless page telling about the denied access,
|
||||
-- h returns authentication information
|
||||
-- and c returns with value 401 (Authentication Required)
|
||||
|
||||
@ -235,11 +239,11 @@ r, e = http.request("http://wrong.host/")
|
||||
-- r is nil, and e returns with value "host not found"
|
||||
</pre>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
And here is an example using the generic interface:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load the http module
|
||||
http = require("socket.http")
|
||||
|
||||
@ -261,7 +265,7 @@ r, c, h = http.request {
|
||||
-- }
|
||||
</pre>
|
||||
|
||||
<p class=note id="post">
|
||||
<p class="note" id="post">
|
||||
Note: When sending a POST request, simple interface adds a
|
||||
"<tt>Content-type: application/x-www-form-urlencoded</tt>"
|
||||
header to the request. This is the type used by
|
||||
@ -269,21 +273,21 @@ HTML forms. If you need another type, use the generic
|
||||
interface.
|
||||
</p>
|
||||
|
||||
<p class=note id="authentication">
|
||||
<p class="note" id="authentication">
|
||||
Note: Some URLs are protected by their
|
||||
servers from anonymous download. For those URLs, the server must receive
|
||||
some sort of authentication along with the request or it will deny
|
||||
download and return status "401 Authentication Required".
|
||||
download and return status "401 Authentication Required".
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
The HTTP/1.1 standard defines two authentication methods: the Basic
|
||||
Authentication Scheme and the Digest Authentication Scheme, both
|
||||
explained in detail in
|
||||
<a href="http://www.ietf.org/rfc/rfc2068.txt">RFC 2068</a>.
|
||||
</p>
|
||||
|
||||
<p class=note>The Basic Authentication Scheme sends
|
||||
<p class="note">The Basic Authentication Scheme sends
|
||||
<tt><user></tt> and
|
||||
<tt><password></tt> unencrypted to the server and is therefore
|
||||
considered unsafe. Unfortunately, by the time of this implementation,
|
||||
@ -292,7 +296,7 @@ Therefore, this is the method used by the toolkit whenever
|
||||
authentication is required.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load required modules
|
||||
http = require("socket.http")
|
||||
mime = require("mime")
|
||||
@ -312,20 +316,20 @@ r, c = http.request {
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:26 EDT 2006
|
||||
Last modified by Eric Westbrook on <br>
|
||||
Sat Feb 23 19:09:42 UTC 2019
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
138
docs/index.html
Normal file
138
docs/index.html
Normal file
@ -0,0 +1,138 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="The LuaSocket Homepage">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Network, Library, Support, Internet">
|
||||
<title>LuaSocket: Network support for the Lua language </title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align="center"><a href="http://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- whatis +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id="whatis">What is LuaSocket?</h2>
|
||||
|
||||
<p>
|
||||
LuaSocket is a <a href="http://www.lua.org">Lua</a> extension library
|
||||
that is composed by two parts: a C core that provides support for the TCP
|
||||
and UDP transport layers, and a set of Lua modules that add support for
|
||||
functionality commonly needed by applications that deal with the Internet.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The core support has been implemented so that it is both efficient and
|
||||
simple to use. It is available to any Lua application once it has been
|
||||
properly initialized by the interpreter in use. The code has been tested
|
||||
and runs well on several Windows and UNIX platforms. </p>
|
||||
|
||||
<p>
|
||||
Among the support modules, the most commonly used implement the
|
||||
<a href="smtp.html">SMTP</a>
|
||||
(sending e-mails),
|
||||
<a href="http.html">HTTP</a>
|
||||
(WWW access) and
|
||||
<a href="ftp.html">FTP</a>
|
||||
(uploading and downloading files) client
|
||||
protocols. These provide a very natural and generic interface to the
|
||||
functionality defined by each protocol.
|
||||
In addition, you will find that the
|
||||
<a href="mime.html">MIME</a> (common encodings),
|
||||
<a href="url.html">URL</a>
|
||||
(anything you could possible want to do with one) and
|
||||
<a href="ltn12.html">LTN12</a>
|
||||
(filters, sinks, sources and pumps) modules can be very handy.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The library is available under the same
|
||||
<a href="http://www.lua.org/copyright.html">
|
||||
terms and conditions</a> as the Lua language, the MIT license. The idea is
|
||||
that if you can use Lua in a project, you should also be able to use
|
||||
LuaSocket.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Copyright © 1999-2013 Diego Nehab. All rights reserved. <br>
|
||||
Author: <a href="http://www.impa.br/~diego">Diego Nehab</a>
|
||||
</p>
|
||||
|
||||
<!-- download +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id="download">Download</h2>
|
||||
|
||||
<p>
|
||||
LuaSocket version 3.1.0 is now available for download!
|
||||
It is compatible with Lua 5.1 through 5.4.
|
||||
Chances are it works well on most UNIX distributions and Windows flavors.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The current version of the library can be found at
|
||||
the <a href="https://github.com/lunarmodules/luasocket">LuaSocket
|
||||
project page</a> on GitHub. Besides the full C and Lua source code
|
||||
for the library, the distribution contains several examples,
|
||||
this user's manual and basic test procedures.
|
||||
</p>
|
||||
|
||||
<p> Take a look at the <a
|
||||
href="installation.html">installation</a> section of the
|
||||
manual to find out how to properly install the library.
|
||||
</p>
|
||||
|
||||
<!-- thanks +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id="thanks">Special thanks</h2>
|
||||
|
||||
<p>
|
||||
This marks the first release of LuaSocket that
|
||||
wholeheartedly embraces the open-source development
|
||||
philosophy. After a long hiatus, Matthew Wild finally
|
||||
convinced me it was time for a release including IPv6 and
|
||||
Lua 5.2 support. It was more work than we anticipated.
|
||||
Special thanks to Sam Roberts, Florian Zeitz, and Paul
|
||||
Aurich, Liam Devine, Alexey Melnichuk, and everybody else
|
||||
that has helped bring this library back to life.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class="bar">
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -89,7 +89,7 @@ it should be easy to use LuaSocket. Just fire the interpreter and use the
|
||||
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
|
||||
> socket = require("socket")
|
||||
> print(socket._VERSION)
|
||||
--> LuaSocket 3.0-rc1
|
||||
--> LuaSocket 3.0.0
|
||||
</pre>
|
||||
|
||||
<p> Each module loads their dependencies automatically, so you only need to
|
@ -1,4 +1,4 @@
|
||||
<!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">
|
||||
<html>
|
||||
|
||||
@ -14,22 +14,22 @@ Pump, Support, Library">
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
<tr><td align="center"><a href="http://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
@ -37,7 +37,7 @@ Pump, Support, Library">
|
||||
|
||||
<!-- ltn12 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=ltn12>LTN12</h2>
|
||||
<h2 id="ltn12">LTN12</h2>
|
||||
|
||||
<p> The <tt>ltn12</tt> namespace implements the ideas described in
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||
@ -46,11 +46,11 @@ functions. Please refer to the LTN for a deeper explanation of the
|
||||
functionality provided by this module.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<p>
|
||||
To obtain the <tt>ltn12</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- loads the LTN21 module
|
||||
local ltn12 = require("ltn12")
|
||||
</pre>
|
||||
@ -61,32 +61,32 @@ local ltn12 = require("ltn12")
|
||||
|
||||
<!-- chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="filter.chain">
|
||||
ltn12.filter.<b>chain(</b>filter<sub>1</sub>, filter<sub>2</sub>
|
||||
<p class="name" id="filter.chain">
|
||||
ltn12.filter.<b>chain(</b>filter<sub>1</sub>, filter<sub>2</sub>
|
||||
[, ... filter<sub>N</sub>]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns a filter that passes all data it receives through each of a
|
||||
series of given filters.
|
||||
series of given filters.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Filter<sub>1</sub></tt> to <tt>filter<sub>N</sub></tt> are simple
|
||||
filters.
|
||||
filters.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The function returns the chained filter.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
The nesting of filters can be arbitrary. For instance, the useless filter
|
||||
below doesn't do anything but return the data that was passed to it,
|
||||
unaltered.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load required modules
|
||||
local ltn12 = require("ltn12")
|
||||
local mime = require("mime")
|
||||
@ -102,26 +102,26 @@ id = ltn12.filter.chain(
|
||||
|
||||
<!-- cycle ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="filter.cycle">
|
||||
<p class="name" id="filter.cycle">
|
||||
ltn12.filter.<b>cycle(</b>low [, ctx, extra]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns a high-level filter that cycles though a low-level filter by
|
||||
passing it each chunk and updating a context between calls.
|
||||
passing it each chunk and updating a context between calls.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Low</tt> is the low-level filter to be cycled,
|
||||
<p class="parameters">
|
||||
<tt>Low</tt> is the low-level filter to be cycled,
|
||||
<tt>ctx</tt> is the initial context and <tt>extra</tt> is any extra
|
||||
argument the low-level filter might take.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns the high-level filter.
|
||||
<p class="return">
|
||||
The function returns the high-level filter.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load the ltn12 module
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
@ -137,15 +137,15 @@ end
|
||||
|
||||
<!-- all ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="pump.all">
|
||||
<p class="name" id="pump.all">
|
||||
ltn12.pump.<b>all(</b>source, sink<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Pumps <em>all</em> data from a <tt>source</tt> to a <tt>sink</tt>.
|
||||
<p class="description">
|
||||
Pumps <em>all</em> data from a <tt>source</tt> to a <tt>sink</tt>.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
If successful, the function returns a value that evaluates to
|
||||
<b><tt>true</tt></b>. In case
|
||||
of error, the function returns a <b><tt>false</tt></b> value, followed by an error message.
|
||||
@ -153,15 +153,15 @@ of error, the function returns a <b><tt>false</tt></b> value, followed by an err
|
||||
|
||||
<!-- step +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="pump.step">
|
||||
<p class="name" id="pump.step">
|
||||
ltn12.pump.<b>step(</b>source, sink<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Pumps <em>one</em> chunk of data from a <tt>source</tt> to a <tt>sink</tt>.
|
||||
<p class="description">
|
||||
Pumps <em>one</em> chunk of data from a <tt>source</tt> to a <tt>sink</tt>.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
If successful, the function returns a value that evaluates to
|
||||
<b><tt>true</tt></b>. In case
|
||||
of error, the function returns a <b><tt>false</tt></b> value, followed by an error message.
|
||||
@ -173,52 +173,52 @@ of error, the function returns a <b><tt>false</tt></b> value, followed by an err
|
||||
|
||||
<!-- chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.chain">
|
||||
<p class="name" id="sink.chain">
|
||||
ltn12.sink.<b>chain(</b>filter, sink<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a new sink that passes data through a <tt>filter</tt> before sending it to a given <tt>sink</tt>.
|
||||
<p class="description">
|
||||
Creates and returns a new sink that passes data through a <tt>filter</tt> before sending it to a given <tt>sink</tt>.
|
||||
</p>
|
||||
|
||||
<!-- error ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.error">
|
||||
<p class="name" id="sink.error">
|
||||
ltn12.sink.<b>error(</b>message<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Creates and returns a sink that aborts transmission with the error
|
||||
<tt>message</tt>.
|
||||
</p>
|
||||
|
||||
<!-- file +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.file">
|
||||
<p class="name" id="sink.file">
|
||||
ltn12.sink.<b>file(</b>handle, message<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates a sink that sends data to a file.
|
||||
<p class="description">
|
||||
Creates a sink that sends data to a file.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Handle</tt> is a file handle. If <tt>handle</tt> is <tt><b>nil</b></tt>,
|
||||
<tt>message</tt> should give the reason for failure.
|
||||
<p class="parameters">
|
||||
<tt>Handle</tt> is a file handle. If <tt>handle</tt> is <tt><b>nil</b></tt>,
|
||||
<tt>message</tt> should give the reason for failure.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The function returns a sink that sends all data to the given <tt>handle</tt>
|
||||
and closes the file when done, or a sink that aborts the transmission with
|
||||
the error <tt>message</tt>
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
In the following example, notice how the prototype is designed to
|
||||
<p class="note">
|
||||
In the following example, notice how the prototype is designed to
|
||||
fit nicely with the <tt>io.open</tt> function.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load the ltn12 module
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
@ -231,45 +231,45 @@ ltn12.pump.all(
|
||||
|
||||
<!-- null +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.null">
|
||||
<p class="name" id="sink.null">
|
||||
ltn12.sink.<b>null()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns a sink that ignores all data it receives.
|
||||
<p class="description">
|
||||
Returns a sink that ignores all data it receives.
|
||||
</p>
|
||||
|
||||
<!-- simplify +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.simplify">
|
||||
<p class="name" id="sink.simplify">
|
||||
ltn12.sink.<b>simplify(</b>sink<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a simple sink given a fancy <tt>sink</tt>.
|
||||
<p class="description">
|
||||
Creates and returns a simple sink given a fancy <tt>sink</tt>.
|
||||
</p>
|
||||
|
||||
<!-- table ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.table">
|
||||
<p class="name" id="sink.table">
|
||||
ltn12.sink.<b>table(</b>[table]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Creates a sink that stores all chunks in a table. The chunks can later be
|
||||
efficiently concatenated into a single string.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Table</tt> is used to hold the chunks. If
|
||||
<tt><b>nil</b></tt>, the function creates its own table.
|
||||
<tt><b>nil</b></tt>, the function creates its own table.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns the sink and the table used to store the chunks.
|
||||
<p class="return">
|
||||
The function returns the sink and the table used to store the chunks.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load needed modules
|
||||
local http = require("socket.http")
|
||||
local ltn12 = require("ltn12")
|
||||
@ -291,89 +291,89 @@ end
|
||||
|
||||
<!-- cat ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.cat">
|
||||
<p class="name" id="source.cat">
|
||||
ltn12.source.<b>cat(</b>source<sub>1</sub> [, source<sub>2</sub>, ...,
|
||||
source<sub>N</sub>]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Creates a new source that produces the concatenation of the data produced
|
||||
by a number of sources.
|
||||
by a number of sources.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Source<sub>1</sub></tt> to <tt>source<sub>N</sub></tt> are the original
|
||||
sources.
|
||||
sources.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The function returns the new source.
|
||||
</p>
|
||||
|
||||
<!-- chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.chain">
|
||||
<p class="name" id="source.chain">
|
||||
ltn12.source.<b>chain(</b>source, filter<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates a new <tt>source</tt> that passes data through a <tt>filter</tt>
|
||||
before returning it.
|
||||
<p class="description">
|
||||
Creates a new <tt>source</tt> that passes data through a <tt>filter</tt>
|
||||
before returning it.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The function returns the new source.
|
||||
</p>
|
||||
|
||||
<!-- empty ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.empty">
|
||||
<p class="name" id="source.empty">
|
||||
ltn12.source.<b>empty()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns an empty source.
|
||||
<p class="description">
|
||||
Creates and returns an empty source.
|
||||
</p>
|
||||
|
||||
<!-- error ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.error">
|
||||
<p class="name" id="source.error">
|
||||
ltn12.source.<b>error(</b>message<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Creates and returns a source that aborts transmission with the error
|
||||
<tt>message</tt>.
|
||||
</p>
|
||||
|
||||
<!-- file +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.file">
|
||||
<p class="name" id="source.file">
|
||||
ltn12.source.<b>file(</b>handle, message<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates a source that produces the contents of a file.
|
||||
<p class="description">
|
||||
Creates a source that produces the contents of a file.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Handle</tt> is a file handle. If <tt>handle</tt> is <tt><b>nil</b></tt>,
|
||||
<tt>message</tt> should give the reason for failure.
|
||||
<p class="parameters">
|
||||
<tt>Handle</tt> is a file handle. If <tt>handle</tt> is <tt><b>nil</b></tt>,
|
||||
<tt>message</tt> should give the reason for failure.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a source that reads chunks of data from
|
||||
<p class="return">
|
||||
The function returns a source that reads chunks of data from
|
||||
given <tt>handle</tt> and returns it to the user,
|
||||
closing the file when done, or a source that aborts the transmission with
|
||||
the error <tt>message</tt>
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
In the following example, notice how the prototype is designed to
|
||||
<p class="note">
|
||||
In the following example, notice how the prototype is designed to
|
||||
fit nicely with the <tt>io.open</tt> function.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load the ltn12 module
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
@ -386,41 +386,41 @@ ltn12.pump.all(
|
||||
|
||||
<!-- simplify +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.simplify">
|
||||
<p class="name" id="source.simplify">
|
||||
ltn12.source.<b>simplify(</b>source<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a simple source given a fancy <tt>source</tt>.
|
||||
<p class="description">
|
||||
Creates and returns a simple source given a fancy <tt>source</tt>.
|
||||
</p>
|
||||
|
||||
<!-- string +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.string">
|
||||
<p class="name" id="source.string">
|
||||
ltn12.source.<b>string(</b>string<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Creates and returns a source that produces the contents of a
|
||||
<tt>string</tt>, chunk by chunk.
|
||||
<tt>string</tt>, chunk by chunk.
|
||||
</p>
|
||||
|
||||
<!-- table +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.table">
|
||||
<p class="name" id="source.table">
|
||||
ltn12.source.<b>table(</b>table<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Creates and returns a source that produces the numerically-indexed values of a <tt>table</tt> successively beginning at 1. The source returns nil (end-of-stream) whenever a nil value is produced by the current index, which proceeds forward regardless.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@ -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">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: MIME support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, MIME, Library, Support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, MIME, Library, Support">
|
||||
<title>LuaSocket: MIME module</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
@ -13,22 +13,22 @@
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
<tr><td align="center"><a href="http://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
@ -36,14 +36,14 @@
|
||||
|
||||
<!-- mime +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=mime>MIME</h2>
|
||||
<h2 id="mime">MIME</h2>
|
||||
|
||||
<p>
|
||||
The <tt>mime</tt> namespace offers filters that apply and remove common
|
||||
content transfer encodings, such as Base64 and Quoted-Printable.
|
||||
It also provides functions to break text into lines and change
|
||||
the end-of-line convention.
|
||||
MIME is described mainly in
|
||||
MIME is described mainly in
|
||||
<a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>,
|
||||
<a href="http://www.ietf.org/rfc/rfc2046.txt">2046</a>,
|
||||
<a href="http://www.ietf.org/rfc/rfc2047.txt">2047</a>,
|
||||
@ -52,17 +52,17 @@ MIME is described mainly in
|
||||
</p>
|
||||
|
||||
<p>
|
||||
All functionality provided by the MIME module
|
||||
follows the ideas presented in
|
||||
All functionality provided by the MIME module
|
||||
follows the ideas presented in
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||
LTN012, Filters sources and sinks</a>.
|
||||
LTN012, Filters sources and sinks</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<p>
|
||||
To obtain the <tt>mime</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- loads the MIME module and everything it requires
|
||||
local mime = require("mime")
|
||||
</pre>
|
||||
@ -70,60 +70,60 @@ local mime = require("mime")
|
||||
|
||||
<!-- High-level +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id=high>High-level filters</h3>
|
||||
<h3 id="high">High-level filters</h3>
|
||||
|
||||
|
||||
<!-- decode +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="decode">
|
||||
<p class="name" id="decode">
|
||||
mime.<b>decode(</b>"base64"<b>)</b><br>
|
||||
mime.<b>decode(</b>"quoted-printable"<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns a filter that decodes data from a given transfer content
|
||||
encoding.
|
||||
</p>
|
||||
|
||||
<!-- encode +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="encode">
|
||||
<p class="name" id="encode">
|
||||
mime.<b>encode(</b>"base64"<b>)</b><br>
|
||||
mime.<b>encode(</b>"quoted-printable" [, mode]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns a filter that encodes data according to a given transfer content
|
||||
encoding.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
In the Quoted-Printable case, the user can specify whether the data is
|
||||
textual or binary, by passing the <tt>mode</tt> strings "<tt>text</tt>" or
|
||||
"<tt>binary</tt>". <tt>Mode</tt> defaults to "<tt>text</tt>".
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Although both transfer content encodings specify a limit for the line
|
||||
length, the encoding filters do <em>not</em> break text into lines (for
|
||||
added flexibility).
|
||||
added flexibility).
|
||||
Below is a filter that converts binary data to the Base64 transfer content
|
||||
encoding and breaks it into lines of the correct size.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
base64 = ltn12.filter.chain(
|
||||
mime.encode("base64"),
|
||||
mime.wrap("base64")
|
||||
)
|
||||
</pre>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: Text data <em>has</em> to be converted to canonic form
|
||||
<em>before</em> being encoded.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
base64 = ltn12.filter.chain(
|
||||
mime.normalize(),
|
||||
mime.encode("base64"),
|
||||
@ -133,77 +133,77 @@ base64 = ltn12.filter.chain(
|
||||
|
||||
<!-- normalize ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="normalize">
|
||||
<p class="name" id="normalize">
|
||||
mime.<b>normalize(</b>[marker]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Converts most common end-of-line markers to a specific given marker.
|
||||
<p class="description">
|
||||
Converts most common end-of-line markers to a specific given marker.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Marker</tt> is the new marker. It defaults to CRLF, the canonic
|
||||
<p class="parameters">
|
||||
<tt>Marker</tt> is the new marker. It defaults to CRLF, the canonic
|
||||
end-of-line marker defined by the MIME standard.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a filter that performs the conversion.
|
||||
<p class="return">
|
||||
The function returns a filter that performs the conversion.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: There is no perfect solution to this problem. Different end-of-line
|
||||
markers are an evil that will probably plague developers forever.
|
||||
markers are an evil that will probably plague developers forever.
|
||||
This function, however, will work perfectly for text created with any of
|
||||
the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF),
|
||||
the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF),
|
||||
or the DOS (CRLF) conventions. Even if the data has mixed end-of-line
|
||||
markers, the function will still work well, although it doesn't
|
||||
markers, the function will still work well, although it doesn't
|
||||
guarantee that the number of empty lines will be correct.
|
||||
</p>
|
||||
|
||||
<!-- stuff +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="stuff">
|
||||
<p class="name" id="stuff">
|
||||
mime.<b>stuff()</b><br>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Creates and returns a filter that performs stuffing of SMTP messages.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The <a href=smtp.html#send><tt>smtp.send</tt></a> function
|
||||
<p class="note">
|
||||
Note: The <a href="smtp.html#send"><tt>smtp.send</tt></a> function
|
||||
uses this filter automatically. You don't need to chain it with your
|
||||
source, or apply it to your message body.
|
||||
source, or apply it to your message body.
|
||||
</p>
|
||||
|
||||
<!-- wrap +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="wrap">
|
||||
<p class="name" id="wrap">
|
||||
mime.<b>wrap(</b>"text" [, length]<b>)</b><br>
|
||||
mime.<b>wrap(</b>"base64"<b>)</b><br>
|
||||
mime.<b>wrap(</b>"quoted-printable"<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns a filter that breaks data into lines.
|
||||
<p class="description">
|
||||
Returns a filter that breaks data into lines.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
The "<tt>text</tt>" line-wrap filter simply breaks text into lines by
|
||||
inserting CRLF end-of-line markers at appropriate positions.
|
||||
<tt>Length</tt> defaults 76.
|
||||
<p class="parameters">
|
||||
The "<tt>text</tt>" line-wrap filter simply breaks text into lines by
|
||||
inserting CRLF end-of-line markers at appropriate positions.
|
||||
<tt>Length</tt> defaults 76.
|
||||
The "<tt>base64</tt>" line-wrap filter works just like the default
|
||||
"<tt>text</tt>" line-wrap filter with default length.
|
||||
"<tt>text</tt>" line-wrap filter with default length.
|
||||
The function can also wrap "<tt>quoted-printable</tt>" lines, taking care
|
||||
not to break lines in the middle of an escaped character. In that case, the
|
||||
line length is fixed at 76.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
For example, to create an encoding filter for the Quoted-Printable transfer content encoding of text data, do the following:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
qp = ltn12.filter.chain(
|
||||
mime.normalize(),
|
||||
mime.encode("quoted-printable"),
|
||||
@ -211,155 +211,155 @@ qp = ltn12.filter.chain(
|
||||
)
|
||||
</pre>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: To break into lines with a different end-of-line convention, apply
|
||||
a normalization filter after the line break filter.
|
||||
a normalization filter after the line break filter.
|
||||
</p>
|
||||
|
||||
<!-- Low-level ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id=low>Low-level filters</h3>
|
||||
<h3 id="low">Low-level filters</h3>
|
||||
|
||||
<!-- b64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="b64">
|
||||
<p class="name" id="b64">
|
||||
A, B = mime.<b>b64(</b>C [, D]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to perform Base64 encoding.
|
||||
<p class="description">
|
||||
Low-level filter to perform Base64 encoding.
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<tt>A</tt> is the encoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be encoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> encoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is padded with
|
||||
the encoding of the remaining bytes of <tt>C</tt>.
|
||||
<p class="description">
|
||||
<tt>A</tt> is the encoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be encoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> encoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is padded with
|
||||
the encoding of the remaining bytes of <tt>C</tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The simplest use of this function is to encode a string into it's
|
||||
Base64 transfer content encoding. Notice the extra parenthesis around the
|
||||
call to <tt>mime.b64</tt>, to discard the second return value.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
print((mime.b64("diego:password")))
|
||||
--> ZGllZ286cGFzc3dvcmQ=
|
||||
</pre>
|
||||
|
||||
<!-- dot +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<p class=name id="dot">
|
||||
<p class="name" id="dot">
|
||||
A, n = mime.<b>dot(</b>m [, B]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Low-level filter to perform SMTP stuffing and enable transmission of
|
||||
messages containing the sequence "CRLF.CRLF".
|
||||
messages containing the sequence "CRLF.CRLF".
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>A</tt> is the stuffed version of <tt>B</tt>. '<tt>n</tt>' gives the
|
||||
number of characters from the sequence CRLF seen in the end of <tt>B</tt>.
|
||||
'<tt>m</tt>' should tell the same, but for the previous chunk.
|
||||
</p>
|
||||
|
||||
<p class=note>Note: The message body is defined to begin with
|
||||
<p class="note">Note: The message body is defined to begin with
|
||||
an implicit CRLF. Therefore, to stuff a message correctly, the
|
||||
first <tt>m</tt> should have the value 2.
|
||||
first <tt>m</tt> should have the value 2.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
print((string.gsub(mime.dot(2, ".\r\nStuffing the message.\r\n.\r\n."), "\r\n", "\\n")))
|
||||
--> ..\nStuffing the message.\n..\n..
|
||||
</pre>
|
||||
|
||||
<p class=note>
|
||||
Note: The <a href=smtp.html#send><tt>smtp.send</tt></a> function
|
||||
uses this filter automatically. You don't need to
|
||||
apply it again.
|
||||
<p class="note">
|
||||
Note: The <a href="smtp.html#send"><tt>smtp.send</tt></a> function
|
||||
uses this filter automatically. You don't need to
|
||||
apply it again.
|
||||
</p>
|
||||
|
||||
<!-- eol ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="eol">
|
||||
<p class="name" id="eol">
|
||||
A, B = mime.<b>eol(</b>C [, D, marker]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to perform end-of-line marker translation.
|
||||
<p class="description">
|
||||
Low-level filter to perform end-of-line marker translation.
|
||||
For each chunk, the function needs to know if the last character of the
|
||||
previous chunk could be part of an end-of-line marker or not. This is the
|
||||
context the function receives besides the chunk. An updated version of
|
||||
the context is returned after each new chunk.
|
||||
the context is returned after each new chunk.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>A</tt> is the translated version of <tt>D</tt>. <tt>C</tt> is the
|
||||
ASCII value of the last character of the previous chunk, if it was a
|
||||
candidate for line break, or 0 otherwise.
|
||||
candidate for line break, or 0 otherwise.
|
||||
<tt>B</tt> is the same as <tt>C</tt>, but for the current
|
||||
chunk. <tt>Marker</tt> gives the new end-of-line marker and defaults to CRLF.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- translates the end-of-line marker to UNIX
|
||||
unix = mime.eol(0, dos, "\n")
|
||||
unix = mime.eol(0, dos, "\n")
|
||||
</pre>
|
||||
|
||||
<!-- qp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="qp">
|
||||
<p class="name" id="qp">
|
||||
A, B = mime.<b>qp(</b>C [, D, marker]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to perform Quoted-Printable encoding.
|
||||
<p class="description">
|
||||
Low-level filter to perform Quoted-Printable encoding.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is the encoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be encoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> encoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is padded with
|
||||
the encoding of the remaining bytes of <tt>C</tt>.
|
||||
Throughout encoding, occurrences of CRLF are replaced by the
|
||||
<p class="parameters">
|
||||
<tt>A</tt> is the encoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be encoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> encoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is padded with
|
||||
the encoding of the remaining bytes of <tt>C</tt>.
|
||||
Throughout encoding, occurrences of CRLF are replaced by the
|
||||
<tt>marker</tt>, which itself defaults to CRLF.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The simplest use of this function is to encode a string into it's
|
||||
Quoted-Printable transfer content encoding.
|
||||
Quoted-Printable transfer content encoding.
|
||||
Notice the extra parenthesis around the call to <tt>mime.qp</tt>, to discard the second return value.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
print((mime.qp("maçã")))
|
||||
<pre class="example">
|
||||
print((mime.qp("ma<EFBFBD><EFBFBD>")))
|
||||
--> ma=E7=E3=
|
||||
</pre>
|
||||
|
||||
<!-- qpwrp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="qpwrp">
|
||||
<p class="name" id="qpwrp">
|
||||
A, m = mime.<b>qpwrp(</b>n [, B, length]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to break Quoted-Printable text into lines.
|
||||
<p class="description">
|
||||
Low-level filter to break Quoted-Printable text into lines.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is a copy of <tt>B</tt>, broken into lines of at most
|
||||
<tt>length</tt> bytes (defaults to 76).
|
||||
'<tt>n</tt>' should tell how many bytes are left for the first
|
||||
line of <tt>B</tt> and '<tt>m</tt>' returns the number of bytes
|
||||
left in the last line of <tt>A</tt>.
|
||||
<p class="parameters">
|
||||
<tt>A</tt> is a copy of <tt>B</tt>, broken into lines of at most
|
||||
<tt>length</tt> bytes (defaults to 76).
|
||||
'<tt>n</tt>' should tell how many bytes are left for the first
|
||||
line of <tt>B</tt> and '<tt>m</tt>' returns the number of bytes
|
||||
left in the last line of <tt>A</tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: Besides breaking text into lines, this function makes sure the line
|
||||
breaks don't fall in the middle of an escaped character combination. Also,
|
||||
this function only breaks lines that are bigger than <tt>length</tt> bytes.
|
||||
@ -367,86 +367,86 @@ this function only breaks lines that are bigger than <tt>length</tt> bytes.
|
||||
|
||||
<!-- unb64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="unb64">
|
||||
<p class="name" id="unb64">
|
||||
A, B = mime.<b>unb64(</b>C [, D]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to perform Base64 decoding.
|
||||
<p class="description">
|
||||
Low-level filter to perform Base64 decoding.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is the decoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be decoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> decoding.
|
||||
<p class="parameters">
|
||||
<tt>A</tt> is the decoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be decoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> decoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is the empty string
|
||||
and <tt>B</tt> returns whatever couldn't be decoded.
|
||||
and <tt>B</tt> returns whatever couldn't be decoded.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The simplest use of this function is to decode a string from it's
|
||||
Base64 transfer content encoding.
|
||||
Base64 transfer content encoding.
|
||||
Notice the extra parenthesis around the call to <tt>mime.unqp</tt>, to discard the second return value.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
print((mime.unb64("ZGllZ286cGFzc3dvcmQ=")))
|
||||
--> diego:password
|
||||
</pre>
|
||||
|
||||
<!-- unqp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="unqp">
|
||||
<p class="name" id="unqp">
|
||||
A, B = mime.<b>unqp(</b>C [, D]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Low-level filter to remove the Quoted-Printable transfer content encoding
|
||||
from data.
|
||||
from data.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is the decoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be decoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> decoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is augmented with
|
||||
the encoding of the remaining bytes of <tt>C</tt>.
|
||||
<p class="parameters">
|
||||
<tt>A</tt> is the decoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be decoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> decoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is augmented with
|
||||
the encoding of the remaining bytes of <tt>C</tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The simplest use of this function is to decode a string from it's
|
||||
Quoted-Printable transfer content encoding.
|
||||
Quoted-Printable transfer content encoding.
|
||||
Notice the extra parenthesis around the call to <tt>mime.unqp</tt>, to discard the second return value.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
print((mime.qp("ma=E7=E3=")))
|
||||
--> maçã
|
||||
--> ma<EFBFBD><EFBFBD>
|
||||
</pre>
|
||||
|
||||
<!-- wrp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="wrp">
|
||||
<p class="name" id="wrp">
|
||||
A, m = mime.<b>wrp(</b>n [, B, length]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to break text into lines with CRLF marker.
|
||||
Text is assumed to be in the <a href=#normalize><tt>normalize</tt></a> form.
|
||||
<p class="description">
|
||||
Low-level filter to break text into lines with CRLF marker.
|
||||
Text is assumed to be in the <a href="#normalize"><tt>normalize</tt></a> form.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is a copy of <tt>B</tt>, broken into lines of at most
|
||||
<tt>length</tt> bytes (defaults to 76).
|
||||
'<tt>n</tt>' should tell how many bytes are left for the first
|
||||
line of <tt>B</tt> and '<tt>m</tt>' returns the number of bytes
|
||||
left in the last line of <tt>A</tt>.
|
||||
<p class="parameters">
|
||||
<tt>A</tt> is a copy of <tt>B</tt>, broken into lines of at most
|
||||
<tt>length</tt> bytes (defaults to 76).
|
||||
'<tt>n</tt>' should tell how many bytes are left for the first
|
||||
line of <tt>B</tt> and '<tt>m</tt>' returns the number of bytes
|
||||
left in the last line of <tt>A</tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: This function only breaks lines that are bigger than
|
||||
<p class="note">
|
||||
Note: This function only breaks lines that are bigger than
|
||||
<tt>length</tt> bytes. The resulting line length does not include the CRLF
|
||||
marker.
|
||||
</p>
|
||||
@ -454,10 +454,10 @@ marker.
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
@ -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">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: Index to reference manual">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Index, Manual, Network, Library,
|
||||
Support, Manual">
|
||||
Support, Manual">
|
||||
<title>LuaSocket: Index to reference manual</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
@ -14,22 +14,22 @@ Support, Manual">
|
||||
|
||||
<!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
<tr><td align="center"><a href="http://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
@ -92,7 +92,7 @@ Support, Manual">
|
||||
<a href="ltn12.html#sink.table">table</a>.
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<a href="ltn12.html#source">source</a>:
|
||||
<a href="ltn12.html#source">source</a>:
|
||||
<a href="ltn12.html#source.cat">cat</a>,
|
||||
<a href="ltn12.html#source.chain">chain</a>,
|
||||
<a href="ltn12.html#source.empty">empty</a>,
|
||||
@ -238,10 +238,10 @@ Support, Manual">
|
||||
|
||||
<!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
@ -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">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: SMTP support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, SMTP, E-Mail, MIME, Multipart,
|
||||
Library, Support">
|
||||
Library, Support">
|
||||
<title>LuaSocket: SMTP support</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
@ -14,22 +14,22 @@ Library, Support">
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
<tr><td align="center"><a href="http://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
@ -37,14 +37,14 @@ Library, Support">
|
||||
|
||||
<!-- smtp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=smtp>SMTP</h2>
|
||||
<h2 id="smtp">SMTP</h2>
|
||||
|
||||
<p> The <tt>smtp</tt> namespace provides functionality to send e-mail
|
||||
messages. The high-level API consists of two functions: one to
|
||||
messages. The high-level API consists of two functions: one to
|
||||
define an e-mail message, and another to actually send the message.
|
||||
Although almost all users will find that these functions provide more than
|
||||
enough functionality, the underlying implementation allows for even more
|
||||
control (if you bother to read the code).
|
||||
control (if you bother to read the code).
|
||||
</p>
|
||||
|
||||
<p>The implementation conforms to the Simple Mail Transfer Protocol,
|
||||
@ -54,19 +54,19 @@ href="http://www.ietf.org/rfc/rfc2822.txt">RFC 2822</a>,
|
||||
which governs the Internet Message Format.
|
||||
Multipart messages (those that contain attachments) are part
|
||||
of the MIME standard, but described mainly
|
||||
in <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a>
|
||||
in <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a>.</p>
|
||||
|
||||
<p> In the description below, good understanding of <a
|
||||
href="http://lua-users.org/wiki/FiltersSourcesAndSinks"> LTN012, Filters
|
||||
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
|
||||
sources and sinks</a> and the <a href="mime.html">MIME</a> module is
|
||||
assumed. In fact, the SMTP module was the main reason for their
|
||||
creation. </p>
|
||||
|
||||
<p>
|
||||
<p>
|
||||
To obtain the <tt>smtp</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- loads the SMTP module and everything it requires
|
||||
local smtp = require("socket.smtp")
|
||||
</pre>
|
||||
@ -92,40 +92,40 @@ headers = {<br>
|
||||
<p>
|
||||
Field names are case insensitive (as specified by the standard) and all
|
||||
functions work with lowercase field names (but see
|
||||
<a href=socket.html#headers.canonic><tt>socket.headers.canonic</tt></a>).
|
||||
<a href="socket.html#headers.canonic"><tt>socket.headers.canonic</tt></a>).
|
||||
Field values are left unmodified.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: MIME headers are independent of order. Therefore, there is no problem
|
||||
in representing them in a Lua table.
|
||||
in representing them in a Lua table.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The following constants can be set to control the default behavior of
|
||||
the SMTP module:
|
||||
the SMTP module:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> <tt>DOMAIN</tt>: domain used to greet the server;
|
||||
<li> <tt>PORT</tt>: default port used for the connection;
|
||||
<li> <tt>SERVER</tt>: default server used for the connection;
|
||||
<li> <tt>TIMEOUT</tt>: default timeout for all I/O operations;
|
||||
<li> <tt>ZONE</tt>: default time zone.
|
||||
<li> <tt>DOMAIN</tt>: domain used to greet the server;</li>
|
||||
<li> <tt>PORT</tt>: default port used for the connection;</li>
|
||||
<li> <tt>SERVER</tt>: default server used for the connection;</li>
|
||||
<li> <tt>TIMEOUT</tt>: default timeout for all I/O operations;</li>
|
||||
<li> <tt>ZONE</tt>: default time zone.</li>
|
||||
</ul>
|
||||
|
||||
<!-- message ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=message>
|
||||
<p class="name" id="message">
|
||||
smtp.<b>message(</b>mesgt<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep).
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep).
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
The only parameter of the function is a table describing the message.
|
||||
<tt>Mesgt</tt> has the following form (notice the recursive structure):
|
||||
</p>
|
||||
@ -135,7 +135,7 @@ The only parameter of the function is a table describing the message.
|
||||
<tr><td><tt>
|
||||
mesgt = {<br>
|
||||
headers = <i>header-table</i>,<br>
|
||||
body = <i>LTN12 source</i> or <i>string</i> or
|
||||
body = <i>LTN12 source</i> or <i>string</i> or
|
||||
<i>multipart-mesgt</i><br>
|
||||
}<br>
|
||||
<br>
|
||||
@ -151,36 +151,36 @@ multipart-mesgt = {<br>
|
||||
</table>
|
||||
</blockquote>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
For a simple message, all that is needed is a set of <tt>headers</tt>
|
||||
and the <tt>body</tt>. The message <tt>body</tt> can be given as a string
|
||||
or as a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
or as a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
source. For multipart messages, the body is a table that
|
||||
recursively defines each part as an independent message, plus an optional
|
||||
<tt>preamble</tt> and <tt>epilogue</tt>.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<p class="return">
|
||||
The function returns a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
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
|
||||
example will make things clear. When in doubt, refer to the appropriate RFC
|
||||
as listed in the introduction. </p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load the smtp support and its friends
|
||||
local smtp = require("socket.smtp")
|
||||
local mime = require("mime")
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
-- creates a source to send a message with two parts. The first part is
|
||||
-- creates a source to send a message with two parts. The first part is
|
||||
-- plain text, the second part is a PNG image, encoded as base64.
|
||||
source = smtp.message{
|
||||
headers = {
|
||||
-- Remember that headers are *ignored* by smtp.send.
|
||||
-- Remember that headers are *ignored* by smtp.send.
|
||||
from = "Sicrano de Oliveira <sicrano@example.com>",
|
||||
to = "Fulano da Silva <fulano@example.com>",
|
||||
subject = "Here is a message with attachments"
|
||||
@ -191,20 +191,20 @@ source = smtp.message{
|
||||
"Preamble will probably appear even in a MIME enabled client.",
|
||||
-- first part: no headers means plain text, us-ascii.
|
||||
-- The mime.eol low-level filter normalizes end-of-line markers.
|
||||
[1] = {
|
||||
[1] = {
|
||||
body = mime.eol(0, [[
|
||||
Lines in a message body should always end with CRLF.
|
||||
The smtp module will *NOT* perform translation. However, the
|
||||
Lines in a message body should always end with CRLF.
|
||||
The smtp module will *NOT* perform translation. However, the
|
||||
send function *DOES* perform SMTP stuffing, whereas the message
|
||||
function does *NOT*.
|
||||
]])
|
||||
},
|
||||
-- second part: headers describe content to be a png image,
|
||||
-- second part: headers describe content to be a png image,
|
||||
-- sent under the base64 transfer content encoding.
|
||||
-- notice that nothing happens until the message is actually sent.
|
||||
-- small chunks are loaded into memory right before transmission and
|
||||
-- notice that nothing happens until the message is actually sent.
|
||||
-- small chunks are loaded into memory right before transmission and
|
||||
-- translation happens on the fly.
|
||||
[2] = {
|
||||
[2] = {
|
||||
headers = {
|
||||
["content-type"] = 'image/png; name="image.png"',
|
||||
["content-disposition"] = 'attachment; filename="image.png"',
|
||||
@ -234,7 +234,7 @@ r, e = smtp.send{
|
||||
|
||||
<!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=send>
|
||||
<p class="name" id="send">
|
||||
smtp.<b>send{</b><br>
|
||||
from = <i>string</i>,<br>
|
||||
rcpt = <i>string</i> or <i>string-table</i>,<br>
|
||||
@ -249,53 +249,53 @@ smtp.<b>send{</b><br>
|
||||
<b>}</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Sends a message to a recipient list. Since sending messages is not as
|
||||
simple as downloading an URL from a FTP or HTTP server, this function
|
||||
doesn't have a simple interface. However, see the
|
||||
<a href=#message><tt>message</tt></a> source factory for
|
||||
simple as downloading an URL from a FTP or HTTP server, this function
|
||||
doesn't have a simple interface. However, see the
|
||||
<a href="#message"><tt>message</tt></a> source factory for
|
||||
a very powerful way to define the message contents.
|
||||
</p>
|
||||
|
||||
|
||||
<p class=parameters>
|
||||
The sender is given by the e-mail address in the <tt>from</tt> field.
|
||||
<p class="parameters">
|
||||
The sender is given by the e-mail address in the <tt>from</tt> field.
|
||||
<tt>Rcpt</tt> is a Lua table with one entry for each recipient e-mail
|
||||
address, or a string
|
||||
in case there is just one recipient.
|
||||
The contents of the message are given by a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
in case there is just one recipient.
|
||||
The contents of the message are given by a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<tt>source</tt>. Several arguments are optional:
|
||||
</p>
|
||||
<ul>
|
||||
<li> <tt>user</tt>, <tt>password</tt>: User and password for
|
||||
authentication. The function will attempt LOGIN and PLAIN authentication
|
||||
methods if supported by the server (both are unsafe);
|
||||
<li> <tt>server</tt>: Server to connect to. Defaults to "localhost";
|
||||
<li> <tt>port</tt>: Port to connect to. Defaults to 25;
|
||||
methods if supported by the server (both are unsafe);</li>
|
||||
<li> <tt>server</tt>: Server to connect to. Defaults to "localhost";</li>
|
||||
<li> <tt>port</tt>: Port to connect to. Defaults to 25;</li>
|
||||
<li> <tt>domain</tt>: Domain name used to greet the server; Defaults to the
|
||||
local machine host name;
|
||||
<li> <tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
local machine host name;</li>
|
||||
<li> <tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
pump step function used to pass data from the
|
||||
source to the server. Defaults to the LTN12 <tt>pump.step</tt> function;
|
||||
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
|
||||
<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
|
||||
<a href="tcp.html#socket.tcp"><tt>socket.tcp</tt></a> when the communications socket is created.</li>
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
If successful, the function returns 1. Otherwise, the function returns
|
||||
<b><tt>nil</tt></b> followed by an error message.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: SMTP servers can be very picky with the format of e-mail
|
||||
addresses. To be safe, use only addresses of the form
|
||||
"<tt><fulano@example.com></tt>" in the <tt>from</tt> and
|
||||
<tt>rcpt</tt> arguments to the <tt>send</tt> function. In headers, e-mail
|
||||
addresses can take whatever form you like. </p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Big note: There is a good deal of misconception with the use of the
|
||||
destination address field headers, i.e., the '<tt>To</tt>', '<tt>Cc</tt>',
|
||||
and, more importantly, the '<tt>Bcc</tt>' headers. Do <em>not</em> add a
|
||||
@ -303,68 +303,69 @@ and, more importantly, the '<tt>Bcc</tt>' headers. Do <em>not</em> add a
|
||||
exact opposite of what you expect.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Only recipients specified in the <tt>rcpt</tt> list will receive a copy of the
|
||||
message. Each recipient of an SMTP mail message receives a copy of the
|
||||
message body along with the headers, and nothing more. The headers
|
||||
<em>are</em> part of the message and should be produced by the
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<em>are</em> part of the message and should be produced by the
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<tt>source</tt> function. The <tt>rcpt</tt> list is <em>not</em>
|
||||
part of the message and will not be sent to anyone.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
<a href="http://www.ietf.org/rfc/rfc2822.txt">RFC 2822</a>
|
||||
has two <em>important and short</em> sections, "3.6.3. Destination address
|
||||
fields" and "5. Security considerations", explaining the proper
|
||||
use of these headers. Here is a summary of what it says:
|
||||
use of these headers. Here is a summary of what it says:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> <tt>To</tt>: contains the address(es) of the primary recipient(s)
|
||||
of the message;
|
||||
of the message;</li>
|
||||
<li> <tt>Cc</tt>: (where the "Cc" means "Carbon Copy" in the sense of
|
||||
making a copy on a typewriter using carbon paper) contains the
|
||||
addresses of others who are to receive the message, though the
|
||||
content of the message may not be directed at them;
|
||||
content of the message may not be directed at them;</li>
|
||||
<li> <tt>Bcc</tt>: (where the "Bcc" means "Blind Carbon
|
||||
Copy") contains addresses of recipients of the message whose addresses are not to be revealed to other recipients of the message.
|
||||
</ul>
|
||||
Copy") contains addresses of recipients of the message whose addresses are not
|
||||
to be revealed to other recipients of the message.</li>
|
||||
</ul>
|
||||
|
||||
<p class=note>
|
||||
The LuaSocket <tt>send</tt> function does not care or interpret the
|
||||
headers you send, but it gives you full control over what is sent and
|
||||
<p class="note">
|
||||
The LuaSocket <tt>send</tt> function does not care or interpret the
|
||||
headers you send, but it gives you full control over what is sent and
|
||||
to whom it is sent:
|
||||
</p>
|
||||
<ul>
|
||||
<li> If someone is to receive the message, the e-mail address <em>has</em>
|
||||
to be in the recipient list. This is the only parameter that controls who
|
||||
gets a copy of the message;
|
||||
<li> If there are multiple recipients, none of them will automatically
|
||||
gets a copy of the message;</li>
|
||||
<li> If there are multiple recipients, none of them will automatically
|
||||
know that someone else got that message. That is, the default behavior is
|
||||
similar to the <tt>Bcc</tt> field of popular e-mail clients;
|
||||
similar to the <tt>Bcc</tt> field of popular e-mail clients;</li>
|
||||
<li> It is up to you to add the <tt>To</tt> header with the list of primary
|
||||
recipients so that other recipients can see it;
|
||||
<li> It is also up to you to add the <tt>Cc</tt> header with the
|
||||
list of additional recipients so that everyone else sees it;
|
||||
<li> Adding a header <tt>Bcc</tt> is nonsense, unless it is
|
||||
recipients so that other recipients can see it;</li>
|
||||
<li> It is also up to you to add the <tt>Cc</tt> header with the
|
||||
list of additional recipients so that everyone else sees it;</li>
|
||||
<li> Adding a header <tt>Bcc</tt> is nonsense, unless it is
|
||||
empty. Otherwise, everyone receiving the message will see it and that is
|
||||
exactly what you <em>don't</em> want to happen!
|
||||
exactly what you <em>don't</em> want to happen!</li>
|
||||
</ul>
|
||||
|
||||
<p class=note>
|
||||
I hope this clarifies the issue. Otherwise, please refer to
|
||||
<p class="note">
|
||||
I hope this clarifies the issue. Otherwise, please refer to
|
||||
<a href="http://www.ietf.org/rfc/rfc2821.txt">RFC 2821</a>
|
||||
and
|
||||
<a href="http://www.ietf.org/rfc/rfc2822.txt">RFC 2822</a>.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- load the smtp support
|
||||
local smtp = require("socket.smtp")
|
||||
|
||||
-- Connects to server "localhost" and sends a message to users
|
||||
-- "fulano@example.com", "beltrano@example.com",
|
||||
-- "fulano@example.com", "beltrano@example.com",
|
||||
-- and "sicrano@example.com".
|
||||
-- Note that "fulano" is the primary recipient, "beltrano" receives a
|
||||
-- carbon copy and neither of them knows that "sicrano" received a blind
|
||||
@ -388,17 +389,17 @@ mesgt = {
|
||||
|
||||
r, e = smtp.send{
|
||||
from = from,
|
||||
rcpt = rcpt,
|
||||
rcpt = rcpt,
|
||||
source = smtp.message(mesgt)
|
||||
}
|
||||
</pre>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
@ -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">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: The core namespace">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Socket, Network, Library, Support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Socket, Network, Library, Support">
|
||||
<title>LuaSocket: The socket namespace</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
@ -13,22 +13,22 @@
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
<tr><td align="center"><a href="https://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
@ -36,71 +36,71 @@
|
||||
|
||||
<!-- socket +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=socket>The socket namespace</h2>
|
||||
<h2 id="socket">The socket namespace</h2>
|
||||
|
||||
<p>
|
||||
The <tt>socket</tt> namespace contains the core functionality of LuaSocket.
|
||||
The <tt>socket</tt> namespace contains the core functionality of LuaSocket.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<p>
|
||||
To obtain the <tt>socket</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- loads the socket module
|
||||
<pre class="example">
|
||||
-- loads the socket module
|
||||
local socket = require("socket")
|
||||
</pre>
|
||||
|
||||
<!-- headers.canonic ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="headers.canonic">
|
||||
<p class="name" id="headers.canonic">
|
||||
socket.headers.<b>canonic</b></p>
|
||||
|
||||
<p> The <tt>socket.headers.canonic</tt> table
|
||||
is used by the HTTP and SMTP modules to translate from
|
||||
lowercase field names back into their canonic
|
||||
<p> The <tt>socket.headers.canonic</tt> table
|
||||
is used by the HTTP and SMTP modules to translate from
|
||||
lowercase field names back into their canonic
|
||||
capitalization. When a lowercase field name exists as a key
|
||||
in this table, the associated value is substituted in
|
||||
whenever the field name is sent out.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<p>
|
||||
You can obtain the <tt>headers</tt> namespace if case run-time
|
||||
modifications are required by running:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- loads the headers module
|
||||
<pre class="example">
|
||||
-- loads the headers module
|
||||
local headers = require("headers")
|
||||
</pre>
|
||||
|
||||
|
||||
<!-- bind ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=bind>
|
||||
<p class="name" id="bind">
|
||||
socket.<b>bind(</b>address, port [, backlog]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
This function is a shortcut that creates and returns a TCP server object
|
||||
bound to a local <tt>address</tt> and <tt>port</tt>, ready to
|
||||
bound to a local <tt>address</tt> and <tt>port</tt>, ready to
|
||||
accept client connections. Optionally,
|
||||
user can also specify the <tt>backlog</tt> argument to the
|
||||
<a href=tcp.html#listen><tt>listen</tt></a> method (defaults to 32).
|
||||
user can also specify the <tt>backlog</tt> argument to the
|
||||
<a href="tcp.html#listen"><tt>listen</tt></a> method (defaults to 32).
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The server object returned will have the option "<tt>reuseaddr</tt>"
|
||||
<p class="note">
|
||||
Note: The server object returned will have the option "<tt>reuseaddr</tt>"
|
||||
set to <tt><b>true</b></tt>.
|
||||
</p>
|
||||
|
||||
<!-- connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=connect>
|
||||
<p class="name" id="connect">
|
||||
socket.<b>connect[46](</b>address, port [, locaddr] [, locport] [, family]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
This function is a shortcut that creates and returns a TCP client object
|
||||
connected to a remote <tt>address</tt> at a given <tt>port</tt>. Optionally,
|
||||
the user can also specify the local address and port to bind
|
||||
@ -114,40 +114,40 @@ of connect are defined as simple helper functions that restrict the
|
||||
|
||||
<!-- debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=debug>
|
||||
<p class="name" id="debug">
|
||||
socket.<b>_DEBUG</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
This constant is set to <tt><b>true</b></tt> if the library was compiled
|
||||
with debug support.
|
||||
</p>
|
||||
|
||||
<!-- datagramsize +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=debug>
|
||||
<p class="name" id="datagramsize">
|
||||
socket.<b>_DATAGRAMSIZE</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Default datagram size used by calls to
|
||||
<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>.
|
||||
(Unless changed in compile time, the value is 8192.)
|
||||
</p>
|
||||
|
||||
<!-- get time +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=gettime>
|
||||
<p class="name" id="gettime">
|
||||
socket.<b>gettime()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns the UNIX time in seconds. You should subtract the values returned by this function
|
||||
to get meaningful values.
|
||||
to get meaningful values.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
t = socket.gettime()
|
||||
-- do stuff
|
||||
print(socket.gettime() - t .. " seconds elapsed")
|
||||
@ -155,38 +155,38 @@ print(socket.gettime() - t .. " seconds elapsed")
|
||||
|
||||
<!-- newtry +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=newtry>
|
||||
<p class="name" id="newtry">
|
||||
socket.<b>newtry(</b>finalizer<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a <em>clean</em>
|
||||
<p class="description">
|
||||
Creates and returns a <em>clean</em>
|
||||
<a href="#try"><tt>try</tt></a>
|
||||
function that allows for cleanup before the exception
|
||||
is raised.
|
||||
function that allows for cleanup before the exception
|
||||
is raised.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Finalizer</tt> is a function that will be called before
|
||||
<tt>try</tt> throws the exception.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns your customized <tt>try</tt> function.
|
||||
<p class="return">
|
||||
The function returns your customized <tt>try</tt> function.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: This idea saved a <em>lot</em> of work with the
|
||||
implementation of protocols in LuaSocket:
|
||||
<p class="note">
|
||||
Note: This idea saved a <em>lot</em> of work with the
|
||||
implementation of protocols in LuaSocket:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
foo = socket.protect(function()
|
||||
-- connect somewhere
|
||||
local c = socket.try(socket.connect("somewhere", 42))
|
||||
-- create a try function that closes 'c' on error
|
||||
local try = socket.newtry(function() c:close() end)
|
||||
-- do everything reassured c will be closed
|
||||
-- do everything reassured c will be closed
|
||||
try(c:send("hello there?\r\n"))
|
||||
local answer = try(c:receive())
|
||||
...
|
||||
@ -198,40 +198,40 @@ end)
|
||||
|
||||
<!-- protect +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=protect>
|
||||
<p class="name" id="protect">
|
||||
socket.<b>protect(</b>func<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Converts a function that throws exceptions into a safe function. This
|
||||
function only catches exceptions thrown by the <a href=#try><tt>try</tt></a>
|
||||
and <a href=#newtry><tt>newtry</tt></a> functions. It does not catch normal
|
||||
function only catches exceptions thrown by the <a href="#try"><tt>try</tt></a>
|
||||
and <a href="#newtry"><tt>newtry</tt></a> functions. It does not catch normal
|
||||
Lua errors.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Func</tt> is a function that calls
|
||||
<a href=#try><tt>try</tt></a> (or <tt>assert</tt>, or <tt>error</tt>)
|
||||
to throw exceptions.
|
||||
<p class="parameters">
|
||||
<tt>Func</tt> is a function that calls
|
||||
<a href="#try"><tt>try</tt></a> (or <tt>assert</tt>, or <tt>error</tt>)
|
||||
to throw exceptions.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
Returns an equivalent function that instead of throwing exceptions in case of
|
||||
a failed <a href=#try><tt>try</tt></a> call, returns <tt><b>nil</b></tt>
|
||||
a failed <a href="#try"><tt>try</tt></a> call, returns <tt><b>nil</b></tt>
|
||||
followed by an error message.
|
||||
</p>
|
||||
|
||||
<!-- select +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=select>
|
||||
<p class="name" id="select">
|
||||
socket.<b>select(</b>recvt, sendt [, timeout]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Waits for a number of sockets to change status.
|
||||
<p class="description">
|
||||
Waits for a number of sockets to change status.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Recvt</tt> is an array with the sockets to test for characters
|
||||
available for reading. Sockets in the <tt>sendt</tt> array are watched to
|
||||
see if it is OK to immediately write on them. <tt>Timeout</tt> is the
|
||||
@ -242,7 +242,7 @@ be empty tables or <tt><b>nil</b></tt>. Non-socket values (or values with
|
||||
non-numeric indices) in the arrays will be silently ignored.
|
||||
</p>
|
||||
|
||||
<p class=return> The function returns a list with the sockets ready for
|
||||
<p class="return"> The function returns a list with the sockets ready for
|
||||
reading, a list with the sockets ready for writing and an error message.
|
||||
The error message is "<tt>timeout</tt>" if a timeout
|
||||
condition was met, "<tt>select failed</tt>" if the call
|
||||
@ -250,216 +250,218 @@ to <tt>select</tt> failed, and
|
||||
<tt><b>nil</b></tt> otherwise. The returned tables are
|
||||
doubly keyed both by integers and also by the sockets
|
||||
themselves, to simplify the test if a specific socket has
|
||||
changed status.
|
||||
changed status.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
<b>Note:</b> <tt>select</tt> can monitor a limited number
|
||||
of sockets, as defined by the constant <tt>socket._SETSIZE</tt>. This
|
||||
of sockets, as defined by the constant <a href="#setsize">
|
||||
<tt>socket._SETSIZE</tt></a>. This
|
||||
number may be as high as 1024 or as low as 64 by default,
|
||||
depending on the system. It is usually possible to change this
|
||||
at compile time. Invoking <tt>select</tt> with a larger
|
||||
number of sockets will raise an error.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<b>Important note</b>: a known bug in WinSock causes <tt>select</tt> to fail
|
||||
<p class="note">
|
||||
<b>Important note</b>: a known bug in WinSock causes <tt>select</tt> to fail
|
||||
on non-blocking TCP sockets. The function may return a socket as
|
||||
writable even though the socket is <em>not</em> ready for sending.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
<b>Another important note</b>: calling select with a server socket in the receive parameter before a call to accept does <em>not</em> guarantee
|
||||
<a href=tcp.html#accept><tt>accept</tt></a> will return immediately.
|
||||
Use the <a href=tcp.html#settimeout><tt>settimeout</tt></a>
|
||||
method or <tt>accept</tt> might block forever.
|
||||
<a href="tcp.html#accept"><tt>accept</tt></a> will return immediately.
|
||||
Use the <a href="tcp.html#settimeout"><tt>settimeout</tt></a>
|
||||
method or <tt>accept</tt> might block forever.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
<b>Yet another note</b>: If you close a socket and pass
|
||||
it to <tt>select</tt>, it will be ignored.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
<b>Using select with non-socket objects</b>: Any object that implements <tt>getfd</tt> and <tt>dirty</tt> can be used with <tt>select</tt>, allowing objects from other libraries to be used within a <tt>socket.select</tt> driven loop.
|
||||
</p>
|
||||
|
||||
<!-- setsize ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=setsize>
|
||||
<p class="name" id="setsize">
|
||||
socket.<b>_SETSIZE</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
The maximum number of sockets that the <a
|
||||
href=#select><tt>select</tt></a> function can handle.
|
||||
href="#select"><tt>select</tt></a> function can handle.
|
||||
</p>
|
||||
|
||||
|
||||
<!-- sink ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=sink>
|
||||
<p class="name" id="sink">
|
||||
socket.<b>sink(</b>mode, socket<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates an
|
||||
<p class="description">
|
||||
Creates an
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
sink from a stream socket object.
|
||||
sink from a stream socket object.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Mode</tt> defines the behavior of the sink. The following
|
||||
options are available:
|
||||
</p>
|
||||
<ul>
|
||||
<li> <tt>"http-chunked"</tt>: sends data through socket after applying the
|
||||
<em>chunked transfer coding</em>, closing the socket when done;
|
||||
<em>chunked transfer coding</em>, closing the socket when done;</li>
|
||||
<li> <tt>"close-when-done"</tt>: sends all received data through the
|
||||
socket, closing the socket when done;
|
||||
socket, closing the socket when done;</li>
|
||||
<li> <tt>"keep-open"</tt>: sends all received data through the
|
||||
socket, leaving it open when done.
|
||||
socket, leaving it open when done.</li>
|
||||
</ul>
|
||||
<p>
|
||||
<tt>Socket</tt> is the stream socket object used to send the data.
|
||||
<tt>Socket</tt> is the stream socket object used to send the data.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a sink with the appropriate behavior.
|
||||
<p class="return">
|
||||
The function returns a sink with the appropriate behavior.
|
||||
</p>
|
||||
|
||||
<!-- skip ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=skip>
|
||||
<p class="name" id="skip">
|
||||
socket.<b>skip(</b>d [, ret<sub>1</sub>, ret<sub>2</sub> ... ret<sub>N</sub>]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Drops a number of arguments and returns the remaining.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>D</tt> is the number of arguments to drop. <tt>Ret<sub>1</sub></tt> to
|
||||
<tt>ret<sub>N</sub></tt> are the arguments.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The function returns <tt>ret<sub>d+1</sub></tt> to <tt>ret<sub>N</sub></tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: This function is useful to avoid creation of dummy variables:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- get the status code and separator from SMTP server reply
|
||||
<pre class="example">
|
||||
-- get the status code and separator from SMTP server reply
|
||||
local code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
|
||||
</pre>
|
||||
|
||||
<!-- sleep ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=sleep>
|
||||
<p class="name" id="sleep">
|
||||
socket.<b>sleep(</b>time<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Freezes the program execution during a given amount of time.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Time</tt> is the number of seconds to sleep for. If
|
||||
<tt>time</tt> is negative, the function returns immediately.
|
||||
</p>
|
||||
|
||||
<!-- source +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=source>
|
||||
<p class="name" id="source">
|
||||
socket.<b>source(</b>mode, socket [, length]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates an
|
||||
<p class="description">
|
||||
Creates an
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
source from a stream socket object.
|
||||
source from a stream socket object.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Mode</tt> defines the behavior of the source. The following
|
||||
options are available:
|
||||
</p>
|
||||
<ul>
|
||||
<li> <tt>"http-chunked"</tt>: receives data from socket and removes the
|
||||
<em>chunked transfer coding</em> before returning the data;
|
||||
<em>chunked transfer coding</em> before returning the data;</li>
|
||||
<li> <tt>"by-length"</tt>: receives a fixed number of bytes from the
|
||||
socket. This mode requires the extra argument <tt>length</tt>;
|
||||
socket. This mode requires the extra argument <tt>length</tt>;</li>
|
||||
<li> <tt>"until-closed"</tt>: receives data from a socket until the other
|
||||
side closes the connection.
|
||||
side closes the connection.</li>
|
||||
</ul>
|
||||
<p>
|
||||
<tt>Socket</tt> is the stream socket object used to receive the data.
|
||||
<tt>Socket</tt> is the stream socket object used to receive the data.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a source with the appropriate behavior.
|
||||
<p class="return">
|
||||
The function returns a source with the appropriate behavior.
|
||||
</p>
|
||||
|
||||
<!-- socketinvalid ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=socketinvalid>
|
||||
<p class="name" id="socketinvalid">
|
||||
socket.<b>_SOCKETINVALID</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
The OS value for an invalid socket.
|
||||
<p class="description">
|
||||
The OS value for an invalid socket. This can be used with <a href="tcp.html#getfd">
|
||||
<tt>tcp:getfd</tt></a> and <a href="tcp.html#setfd"><tt>tcp:setfd</tt></a> methods.
|
||||
</p>
|
||||
|
||||
<!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=try>
|
||||
<p class="name" id="try">
|
||||
socket.<b>try(</b>ret<sub>1</sub> [, ret<sub>2</sub> ... ret<sub>N</sub>]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Throws an exception in case <tt>ret<sub>1</sub></tt> is falsy, using
|
||||
<tt>ret<sub>2</sub></tt> as the error message. The exception is supposed to be caught
|
||||
by a <a href=#protect><tt>protect</tt></a>ed function only.
|
||||
<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.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Ret<sub>1</sub></tt> to <tt>ret<sub>N</sub></tt> can be arbitrary
|
||||
arguments, but are usually the return values of a function call
|
||||
nested with <tt>try</tt>.
|
||||
arguments, but are usually the return values of a function call
|
||||
nested with <tt>try</tt>.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The function returns <tt>ret</tt><sub>1</sub> to <tt>ret</tt><sub>N</sub> if
|
||||
<tt>ret</tt><sub>1</sub> is not <tt><b>nil</b></tt> or <tt><b>false</b></tt>.
|
||||
Otherwise, it calls <tt>error</tt> passing <tt>ret</tt><sub>2</sub> wrapped
|
||||
in a table with metatable used by <a href=#protect><tt>protect</tt></a> to
|
||||
in a table with metatable used by <a href="#protect"><tt>protect</tt></a> to
|
||||
distinguish exceptions from runtime errors.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
<pre class="example">
|
||||
-- connects or throws an exception with the appropriate error message
|
||||
c = socket.try(socket.connect("localhost", 80))
|
||||
</pre>
|
||||
|
||||
<!-- version ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=version>
|
||||
<p class="name" id="version">
|
||||
socket.<b>_VERSION</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
This constant has a string describing the current LuaSocket version.
|
||||
<p class="description">
|
||||
This constant has a string describing the current LuaSocket version.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
@ -13,17 +13,17 @@
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
<tr><td align="center"><a href="http://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
@ -40,42 +40,43 @@
|
||||
|
||||
<!-- accept +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="accept">
|
||||
<p class="name" id="accept">
|
||||
server:<b>accept()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Waits for a remote connection on the server
|
||||
object and returns a client object representing that connection.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
If a connection is successfully initiated, a client object is returned.
|
||||
If a timeout condition is met, the method returns <b><tt>nil</tt></b>
|
||||
followed by the error string '<tt>timeout</tt>'. Other errors are
|
||||
reported by <b><tt>nil</tt></b> followed by a message describing the error.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: calling <a href=socket.html#select><tt>socket.select</tt></a>
|
||||
<p class="note">
|
||||
Note: calling <a href="socket.html#select"><tt>socket.select</tt></a>
|
||||
with a server object in
|
||||
the <tt>recvt</tt> parameter before a call to <tt>accept</tt> does
|
||||
<em>not</em> guarantee <tt>accept</tt> will return immediately. Use the <a
|
||||
href=#settimeout><tt>settimeout</tt></a> method or <tt>accept</tt>
|
||||
href="#settimeout"><tt>settimeout</tt></a> method or <tt>accept</tt>
|
||||
might block until <em>another</em> client shows up.
|
||||
</p>
|
||||
|
||||
<!-- bind +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="bind">
|
||||
<p class="name" id="bind">
|
||||
master:<b>bind(</b>address, port<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Binds a master object to <tt>address</tt> and <tt>port</tt> on the
|
||||
local host.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Address</tt> can be an IP address or a host name.
|
||||
<tt>Port</tt> must be an integer number in the range [0..64K).
|
||||
If <tt>address</tt>
|
||||
@ -86,25 +87,25 @@ If <tt>port</tt> is 0, the system automatically
|
||||
chooses an ephemeral port.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
In case of success, the method returns 1. In case of error, the
|
||||
method returns <b><tt>nil</tt></b> followed by an error message.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The function <a href=socket.html#bind><tt>socket.bind</tt></a>
|
||||
<p class="note">
|
||||
Note: The function <a href="socket.html#bind"><tt>socket.bind</tt></a>
|
||||
is available and is a shortcut for the creation of server sockets.
|
||||
</p>
|
||||
|
||||
<!-- close ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="close">
|
||||
<p class="name" id="close">
|
||||
master:<b>close()</b><br>
|
||||
client:<b>close()</b><br>
|
||||
server:<b>close()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Closes a TCP object. The internal socket used by the object is closed
|
||||
and the local address to which the object was
|
||||
bound is made available to other applications. No further operations
|
||||
@ -112,7 +113,7 @@ bound is made available to other applications. No further operations
|
||||
a closed socket.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: It is important to close all used sockets once they are not
|
||||
needed, since, in many systems, each socket uses a file descriptor,
|
||||
which are limited system resources. Garbage-collected objects are
|
||||
@ -121,53 +122,53 @@ automatically closed before destruction, though.
|
||||
|
||||
<!-- connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="connect">
|
||||
<p class="name" id="connect">
|
||||
master:<b>connect(</b>address, port<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Attempts to connect a master object to a remote host, transforming it into a
|
||||
client object.
|
||||
Client objects support methods
|
||||
<a href=#send><tt>send</tt></a>,
|
||||
<a href=#receive><tt>receive</tt></a>,
|
||||
<a href=#getsockname><tt>getsockname</tt></a>,
|
||||
<a href=#getpeername><tt>getpeername</tt></a>,
|
||||
<a href=#settimeout><tt>settimeout</tt></a>,
|
||||
and <a href=#close><tt>close</tt></a>.
|
||||
<a href="#send"><tt>send</tt></a>,
|
||||
<a href="#receive"><tt>receive</tt></a>,
|
||||
<a href="#getsockname"><tt>getsockname</tt></a>,
|
||||
<a href="#getpeername"><tt>getpeername</tt></a>,
|
||||
<a href="#settimeout"><tt>settimeout</tt></a>,
|
||||
and <a href="#close"><tt>close</tt></a>.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Address</tt> can be an IP address or a host name.
|
||||
<tt>Port</tt> must be an integer number in the range [1..64K).
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
In case of error, the method returns <b><tt>nil</tt></b> followed by a string
|
||||
describing the error. In case of success, the method returns 1.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The function <a href=socket.html#connect><tt>socket.connect</tt></a>
|
||||
<p class="note">
|
||||
Note: The function <a href="socket.html#connect"><tt>socket.connect</tt></a>
|
||||
is available and is a shortcut for the creation of client sockets.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: Starting with LuaSocket 2.0,
|
||||
the <a href=#settimeout><tt>settimeout</tt></a>
|
||||
the <a href="#settimeout"><tt>settimeout</tt></a>
|
||||
method affects the behavior of <tt>connect</tt>, causing it to return
|
||||
with an error in case of a timeout. If that happens, you can still call <a
|
||||
href=socket.html#select><tt>socket.select</tt></a> with the socket in the
|
||||
href="socket.html#select"><tt>socket.select</tt></a> with the socket in the
|
||||
<tt>sendt</tt> table. The socket will be writable when the connection is
|
||||
established.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: Starting with LuaSocket 3.0, the host name resolution
|
||||
depends on whether the socket was created by
|
||||
<a href=#socket.tcp><tt>socket.tcp</tt></a>,
|
||||
<a href=#socket.tcp4><tt>socket.tcp4</tt></a> or
|
||||
<a href=#socket.tcp6><tt>socket.tcp6</tt></a>. Addresses from
|
||||
<a href="#socket.tcp"><tt>socket.tcp</tt></a>,
|
||||
<a href="#socket.tcp4"><tt>socket.tcp4</tt></a> or
|
||||
<a href="#socket.tcp6"><tt>socket.tcp6</tt></a>. Addresses from
|
||||
the appropriate family (or both) are tried in the order
|
||||
returned by the resolver until the
|
||||
first success or until the last failure. If the timeout was
|
||||
@ -176,42 +177,44 @@ set to zero, only the first address is tried.
|
||||
|
||||
<!-- dirty +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="dirty">
|
||||
<p class="name" id="dirty">
|
||||
master:<b>dirty()</b><br>
|
||||
client:<b>dirty()</b><br>
|
||||
server:<b>dirty()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Check the read buffer status.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
Returns <tt>true</tt> if there is any data in the read buffer, <tt>false</tt> otherwise.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: <b>This is an internal method, use at your own risk.</b>
|
||||
</p>
|
||||
|
||||
|
||||
<!-- getfd +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="getfd">
|
||||
<p class="name" id="getfd">
|
||||
master:<b>getfd()</b><br>
|
||||
client:<b>getfd()</b><br>
|
||||
server:<b>getfd()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns the underling socket descriptor or handle associated to the object.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The descriptor or handle. In case the object has been closed, the return will be -1.
|
||||
<p class="return">
|
||||
The descriptor or handle. In case the object has been closed, the return value
|
||||
will be -1. For an invalid socket it will be <a href="socket.html#socketinvalid">
|
||||
<tt>_SOCKETINVALID</tt></a>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: <b>This is an internal method. Unlikely to be
|
||||
portable. Use at your own risk. </b>
|
||||
</p>
|
||||
@ -219,28 +222,27 @@ portable. Use at your own risk. </b>
|
||||
|
||||
<!-- getoption ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="getoption">
|
||||
client:<b>getoption(</b>option)</b><br>
|
||||
server:<b>getoption(</b>option)</b>
|
||||
<p class="name" id="getoption">
|
||||
client:<b>getoption(option)</b><br>
|
||||
server:<b>getoption(option)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Gets options for the TCP object.
|
||||
See <a href=#setoption><tt>setoption</tt></a> for description of the
|
||||
See <a href="#setoption"><tt>setoption</tt></a> for description of the
|
||||
option names and values.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Option</tt> is a string with the option name.
|
||||
<p class="parameters">
|
||||
<tt>Option</tt> is a string with the option name.</p>
|
||||
<ul>
|
||||
|
||||
<li> '<tt>keepalive</tt>'
|
||||
<li> '<tt>linger</tt>'
|
||||
<li> '<tt>reuseaddr</tt>'
|
||||
<li> '<tt>tcp-nodelay</tt>'
|
||||
<li> '<tt>keepalive</tt>'</li>
|
||||
<li> '<tt>linger</tt>'</li>
|
||||
<li> '<tt>reuseaddr</tt>'</li>
|
||||
<li> '<tt>tcp-nodelay</tt>'</li>
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The method returns the option <tt>value</tt> in case of success, or
|
||||
<b><tt>nil</tt></b> followed by an error message otherwise.
|
||||
</p>
|
||||
@ -248,38 +250,38 @@ The method returns the option <tt>value</tt> in case of success, or
|
||||
|
||||
<!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="getpeername">
|
||||
<p class="name" id="getpeername">
|
||||
client:<b>getpeername()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns information about the remote side of a connected client object.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
Returns a string with the IP address of the peer, the
|
||||
port number that peer is using for the connection,
|
||||
and a string with the family ("<tt>inet</tt>" or "<tt>inet6</tt>").
|
||||
In case of error, the method returns <b><tt>nil</tt></b>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: It makes no sense to call this method on server objects.
|
||||
</p>
|
||||
|
||||
<!-- getsockname ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="getsockname">
|
||||
<p class="name" id="getsockname">
|
||||
master:<b>getsockname()</b><br>
|
||||
client:<b>getsockname()</b><br>
|
||||
server:<b>getsockname()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns the local address information associated to the object.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The method returns a string with local IP address, a number with
|
||||
the local port,
|
||||
and a string with the family ("<tt>inet</tt>" or "<tt>inet6</tt>").
|
||||
@ -288,31 +290,31 @@ In case of error, the method returns <b><tt>nil</tt></b>.
|
||||
|
||||
<!-- getstats +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="getstats">
|
||||
<p class="name" id="getstats">
|
||||
master:<b>getstats()</b><br>
|
||||
client:<b>getstats()</b><br>
|
||||
server:<b>getstats()</b><br>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns accounting information on the socket, useful for throttling
|
||||
of bandwidth.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The method returns the number of bytes received, the number of bytes sent,
|
||||
and the age of the socket object in seconds.
|
||||
</p>
|
||||
|
||||
<!-- gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="gettimeout">
|
||||
<p class="name" id="gettimeout">
|
||||
master:<b>gettimeout()</b><br>
|
||||
client:<b>gettimeout()</b><br>
|
||||
server:<b>gettimeout()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns the current block timeout followed by the curent
|
||||
total timeout.
|
||||
</p>
|
||||
@ -320,65 +322,65 @@ total timeout.
|
||||
|
||||
<!-- listen ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="listen">
|
||||
<p class="name" id="listen">
|
||||
master:<b>listen(</b>backlog<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Specifies the socket is willing to receive connections, transforming the
|
||||
object into a server object. Server objects support the
|
||||
<a href=#accept><tt>accept</tt></a>,
|
||||
<a href=#getsockname><tt>getsockname</tt></a>,
|
||||
<a href=#setoption><tt>setoption</tt></a>,
|
||||
<a href=#settimeout><tt>settimeout</tt></a>,
|
||||
and <a href=#close><tt>close</tt></a> methods.
|
||||
<a href="#accept"><tt>accept</tt></a>,
|
||||
<a href="#getsockname"><tt>getsockname</tt></a>,
|
||||
<a href="#setoption"><tt>setoption</tt></a>,
|
||||
<a href="#settimeout"><tt>settimeout</tt></a>,
|
||||
and <a href="#close"><tt>close</tt></a> methods.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
The parameter <tt>backlog</tt> specifies the number of client
|
||||
connections that can
|
||||
be queued waiting for service. If the queue is full and another client
|
||||
attempts connection, the connection is refused.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
In case of success, the method returns 1. In case of error, the
|
||||
method returns <b><tt>nil</tt></b> followed by an error message.
|
||||
</p>
|
||||
|
||||
<!-- receive ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="receive">
|
||||
<p class="name" id="receive">
|
||||
client:<b>receive(</b>[pattern [, prefix]]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Reads data from a client object, according to the specified <em>read
|
||||
pattern</em>. Patterns follow the Lua file I/O format, and the difference in performance between all patterns is negligible.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Pattern</tt> can be any of the following:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> '<tt>*a</tt>': reads from the socket until the connection is
|
||||
closed. No end-of-line translation is performed;
|
||||
closed. No end-of-line translation is performed;</li>
|
||||
<li> '<tt>*l</tt>': reads a line of text from the socket. The line is
|
||||
terminated by a LF character (ASCII 10), optionally preceded by a
|
||||
CR character (ASCII 13). The CR and LF characters are not included in
|
||||
the returned line. In fact, <em>all</em> CR characters are
|
||||
ignored by the pattern. This is the default pattern;
|
||||
ignored by the pattern. This is the default pattern;</li>
|
||||
<li> <tt>number</tt>: causes the method to read a specified <tt>number</tt>
|
||||
of bytes from the socket.
|
||||
of bytes from the socket.</li>
|
||||
</ul>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Prefix</tt> is an optional string to be concatenated to the beginning
|
||||
of any received data before return.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
If successful, the method returns the received pattern. In case of error,
|
||||
the method returns <tt><b>nil</b></tt> followed by an error
|
||||
message, followed by a (possibly empty) string containing
|
||||
@ -388,7 +390,7 @@ closed before the transmission was completed or the string
|
||||
'<tt>timeout</tt>' in case there was a timeout during the operation.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
<b>Important note</b>: This function was changed <em>severely</em>. It used
|
||||
to support multiple patterns (but I have never seen this feature used) and
|
||||
now it doesn't anymore. Partial results used to be returned in the same
|
||||
@ -399,22 +401,22 @@ too.
|
||||
|
||||
<!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="send">
|
||||
<p class="name" id="send">
|
||||
client:<b>send(</b>data [, i [, j]]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Sends <tt>data</tt> through client object.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Data</tt> is the string to be sent. The optional arguments
|
||||
<tt>i</tt> and <tt>j</tt> work exactly like the standard
|
||||
<tt>string.sub</tt> Lua function to allow the selection of a
|
||||
substring to be sent.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
If successful, the method returns the index of the last byte
|
||||
within <tt>[i, j]</tt> that has been sent. Notice that, if
|
||||
<tt>i</tt> is 1 or absent, this is effectively the total
|
||||
@ -428,7 +430,7 @@ was completed or the string '<tt>timeout</tt>' in case
|
||||
there was a timeout during the operation.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: Output is <em>not</em> buffered. For small strings,
|
||||
it is always better to concatenate them in Lua
|
||||
(with the '<tt>..</tt>' operator) and send the result in one call
|
||||
@ -437,27 +439,27 @@ instead of calling the method several times.
|
||||
|
||||
<!-- setoption ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="setoption">
|
||||
<p class="name" id="setoption">
|
||||
client:<b>setoption(</b>option [, value]<b>)</b><br>
|
||||
server:<b>setoption(</b>option [, value]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Sets options for the TCP object. Options are only needed by low-level or
|
||||
time-critical applications. You should only modify an option if you
|
||||
are sure you need it.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Option</tt> is a string with the option name, and <tt>value</tt>
|
||||
depends on the option being set:
|
||||
depends on the option being set:</p>
|
||||
|
||||
<ul>
|
||||
|
||||
<li> '<tt>keepalive</tt>': Setting this option to <tt>true</tt> enables
|
||||
the periodic transmission of messages on a connected socket. Should the
|
||||
connected party fail to respond to these messages, the connection is
|
||||
considered broken and processes using the socket are notified;
|
||||
considered broken and processes using the socket are notified;</li>
|
||||
|
||||
<li> '<tt>linger</tt>': Controls the action taken when unsent data are
|
||||
queued on a socket and a close is performed. The value is a table with a
|
||||
@ -468,73 +470,85 @@ it is able to transmit the data or until '<tt>timeout</tt>' has passed. If
|
||||
'<tt>on</tt>' is <tt>false</tt> and a close is issued, the system will
|
||||
process the close in a manner that allows the process to continue as
|
||||
quickly as possible. I do not advise you to set this to anything other than
|
||||
zero;
|
||||
zero;</li>
|
||||
|
||||
<li> '<tt>reuseaddr</tt>': Setting this option indicates that the rules
|
||||
used in validating addresses supplied in a call to
|
||||
<a href=#bind><tt>bind</tt></a> should allow reuse of local addresses;
|
||||
<a href="#bind"><tt>bind</tt></a> should allow reuse of local addresses;</li>
|
||||
|
||||
<li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt>
|
||||
disables the Nagle's algorithm for the connection;
|
||||
disables the Nagle's algorithm for the connection;</li>
|
||||
|
||||
<li> '<tt>tcp-keepidle</tt>': value in seconds for <tt>TCP_KEEPIDLE</tt> Linux only!!</li>
|
||||
|
||||
<li> '<tt>tcp-keepcnt</tt>': value for <tt>TCP_KEEPCNT</tt> Linux only!!</li>
|
||||
|
||||
<li> '<tt>tcp-keepintvl</tt>': value for <tt>TCP_KEEPINTVL</tt> Linux only!!</li>
|
||||
|
||||
<li> '<tt>tcp-defer-accept</tt>': value for <tt>TCP_DEFER_ACCEPT</tt> Linux only!!</li>
|
||||
|
||||
<li> '<tt>tcp-fastopen</tt>': value for <tt>TCP_FASTOPEN</tt> Linux only!!</li>
|
||||
|
||||
<li> '<tt>tcp-fastopen-connect</tt>': value for <tt>TCP_FASTOPEN_CONNECT</tt> Linux only!!</li>
|
||||
|
||||
<li> '<tt>ipv6-v6only</tt>':
|
||||
Setting this option to <tt>true</tt> restricts an <tt>inet6</tt> socket to
|
||||
sending and receiving only IPv6 packets.
|
||||
sending and receiving only IPv6 packets.</li>
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The method returns 1 in case of success, or <b><tt>nil</tt></b>
|
||||
followed by an error message otherwise.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The descriptions above come from the man pages.
|
||||
</p>
|
||||
|
||||
<!-- setstats +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="setstats">
|
||||
<p class="name" id="setstats">
|
||||
master:<b>setstats(</b>received, sent, age<b>)</b><br>
|
||||
client:<b>setstats(</b>received, sent, age<b>)</b><br>
|
||||
server:<b>setstats(</b>received, sent, age<b>)</b><br>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Resets accounting information on the socket, useful for throttling
|
||||
of bandwidth.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
<tt>Received</tt> is a number with the new number of bytes received.
|
||||
<tt>Sent</tt> is a number with the new number of bytes sent.
|
||||
<tt>Age</tt> is the new age in seconds.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The method returns 1 in case of success and <tt><b>nil</b></tt> otherwise.
|
||||
</p>
|
||||
|
||||
<!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="settimeout">
|
||||
<p class="name" id="settimeout">
|
||||
master:<b>settimeout(</b>value [, mode]<b>)</b><br>
|
||||
client:<b>settimeout(</b>value [, mode]<b>)</b><br>
|
||||
server:<b>settimeout(</b>value [, mode]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Changes the timeout values for the object. By default,
|
||||
all I/O operations are blocking. That is, any call to the methods
|
||||
<a href=#send><tt>send</tt></a>,
|
||||
<a href=#receive><tt>receive</tt></a>, and
|
||||
<a href=#accept><tt>accept</tt></a>
|
||||
<a href="#send"><tt>send</tt></a>,
|
||||
<a href="#receive"><tt>receive</tt></a>, and
|
||||
<a href="#accept"><tt>accept</tt></a>
|
||||
will block indefinitely, until the operation completes. The
|
||||
<tt>settimeout</tt> method defines a limit on the amount of time the
|
||||
I/O methods can block. When a timeout is set and the specified amount of
|
||||
time has elapsed, the affected methods give up and fail with an error code.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
The amount of time to wait is specified as the
|
||||
<tt>value</tt> parameter, in seconds. There are two timeout modes and
|
||||
both can be used together for fine tuning:
|
||||
@ -551,12 +565,12 @@ the amount of time LuaSocket can block a Lua script before returning from
|
||||
a call.</li>
|
||||
</ul>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
The <b><tt>nil</tt></b> timeout <tt>value</tt> allows operations to block
|
||||
indefinitely. Negative timeout values have the same effect.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: although timeout values have millisecond precision in LuaSocket,
|
||||
large blocks can cause I/O functions not to respect timeout values due
|
||||
to the time the library takes to transfer blocks to and from the OS
|
||||
@ -565,7 +579,7 @@ and perform automatic name resolution might be blocked by the resolver for
|
||||
longer than the specified timeout value.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The old <tt>timeout</tt> method is deprecated. The name has been
|
||||
changed for sake of uniformity, since all other method names already
|
||||
contained verbs making their imperative nature obvious.
|
||||
@ -573,123 +587,126 @@ contained verbs making their imperative nature obvious.
|
||||
|
||||
<!-- shutdown +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="shutdown">
|
||||
<p class="name" id="shutdown">
|
||||
client:<b>shutdown(</b>mode<b>)</b><br>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Shuts down part of a full-duplex connection.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<p class="parameters">
|
||||
Mode tells which way of the connection should be shut down and can
|
||||
take the value:
|
||||
<ul>
|
||||
<li>"<tt>both</tt>": disallow further sends and receives on the object.
|
||||
This is the default mode;
|
||||
<li>"<tt>send</tt>": disallow further sends on the object;
|
||||
<li>"<tt>receive</tt>": disallow further receives on the object.
|
||||
This is the default mode;</li>
|
||||
<li>"<tt>send</tt>": disallow further sends on the object;</li>
|
||||
<li>"<tt>receive</tt>": disallow further receives on the object.</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
This function returns 1.
|
||||
</p>
|
||||
|
||||
<!-- setfd +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="setfd">
|
||||
<p class="name" id="setfd">
|
||||
master:<b>setfd(</b>fd<b>)</b><br>
|
||||
client:<b>setfd(</b>fd<b>)</b><br>
|
||||
server:<b>setfd(</b>fd<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Sets the underling socket descriptor or handle associated to the object. The current one is simply replaced, not closed, and no other change to the object state is made.
|
||||
<p class="description">
|
||||
Sets the underling socket descriptor or handle associated to the object. The current one
|
||||
is simply replaced, not closed, and no other change to the object state is made.
|
||||
To set it as invalid use <a href="socket.html#socketinvalid"><tt>_SOCKETINVALID</tt></a>.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
No return value.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: <b>This is an internal method. Unlikely to be
|
||||
portable. Use at your own risk. </b>
|
||||
</p>
|
||||
|
||||
<!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="socket.tcp">
|
||||
<p class="name" id="socket.tcp">
|
||||
socket.<b>tcp()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Creates and returns an TCP master object. A master object can
|
||||
be transformed into a server object with the method
|
||||
<a href=#listen><tt>listen</tt></a> (after a call to <a
|
||||
href=#bind><tt>bind</tt></a>) or into a client object with
|
||||
the method <a href=#connect><tt>connect</tt></a>. The only other
|
||||
<a href="#listen"><tt>listen</tt></a> (after a call to <a
|
||||
href="#bind"><tt>bind</tt></a>) or into a client object with
|
||||
the method <a href="#connect"><tt>connect</tt></a>. The only other
|
||||
method supported by a master object is the
|
||||
<a href=#close><tt>close</tt></a> method.</p>
|
||||
<a href="#close"><tt>close</tt></a> method.</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
In case of success, a new master object is returned. In case of error,
|
||||
<b><tt>nil</tt></b> is returned, followed by an error message.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The choice between IPv4 and IPv6 happens during a call to
|
||||
<a href=#bind><tt>bind</tt></a> or <a
|
||||
href=#bind><tt>connect</tt></a>, depending on the address
|
||||
<a href="#bind"><tt>bind</tt></a> or <a
|
||||
href="#bind"><tt>connect</tt></a>, depending on the address
|
||||
family obtained from the resolver.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: Before the choice between IPv4 and IPv6 happens,
|
||||
the internal socket object is invalid and therefore <a
|
||||
href=#setoption><tt>setoption</tt></a> will fail.
|
||||
href="#setoption"><tt>setoption</tt></a> will fail.
|
||||
</p>
|
||||
|
||||
<!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="socket.tcp4">
|
||||
<p class="name" id="socket.tcp4">
|
||||
socket.<b>tcp4()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Creates and returns an IPv4 TCP master object. A master object can
|
||||
be transformed into a server object with the method
|
||||
<a href=#listen><tt>listen</tt></a> (after a call to <a
|
||||
href=#bind><tt>bind</tt></a>) or into a client object with
|
||||
the method <a href=#connect><tt>connect</tt></a>. The only other
|
||||
<a href="#listen"><tt>listen</tt></a> (after a call to <a
|
||||
href="#bind"><tt>bind</tt></a>) or into a client object with
|
||||
the method <a href="#connect"><tt>connect</tt></a>. The only other
|
||||
method supported by a master object is the
|
||||
<a href=#close><tt>close</tt></a> method.</p>
|
||||
<a href="#close"><tt>close</tt></a> method.</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
In case of success, a new master object is returned. In case of error,
|
||||
<b><tt>nil</tt></b> is returned, followed by an error message.
|
||||
</p>
|
||||
|
||||
<!-- socket.tcp6 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="socket.tcp6">
|
||||
<p class="name" id="socket.tcp6">
|
||||
socket.<b>tcp6()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Creates and returns an IPv6 TCP master object. A master object can
|
||||
be transformed into a server object with the method
|
||||
<a href=#listen><tt>listen</tt></a> (after a call to <a
|
||||
href=#bind><tt>bind</tt></a>) or into a client object with
|
||||
the method <a href=#connect><tt>connect</tt></a>. The only other
|
||||
<a href="#listen"><tt>listen</tt></a> (after a call to <a
|
||||
href="#bind"><tt>bind</tt></a>) or into a client object with
|
||||
the method <a href="#connect"><tt>connect</tt></a>. The only other
|
||||
method supported by a master object is the
|
||||
<a href=#close><tt>close</tt></a> method.</p>
|
||||
<a href="#close"><tt>close</tt></a> method.</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
In case of success, a new master object is returned. In case of error,
|
||||
<b><tt>nil</tt></b> is returned, followed by an error message.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The TCP object returned will have the option
|
||||
"<tt>ipv6-v6only</tt>" set to <tt><b>true</b></tt>.
|
||||
</p>
|
||||
@ -698,10 +715,10 @@ Note: The TCP object returned will have the option
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
@ -13,17 +13,17 @@
|
||||
|
||||
<!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<div class="header">
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
<tr><td align="center"><a href="http://www.lua.org">
|
||||
<img width="128" height="128" border="0" alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
<tr><td align="center" valign="top">Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
@ -71,26 +71,26 @@ unconnected:<b>getoption()</b>
|
||||
|
||||
<p class="description">
|
||||
Gets an option value from the UDP object.
|
||||
See <a href=#setoption><tt>setoption</tt></a> for
|
||||
See <a href="#setoption"><tt>setoption</tt></a> for
|
||||
description of the option names and values.
|
||||
</p>
|
||||
|
||||
<p class="parameters"><tt>Option</tt> is a string with the option name.
|
||||
<ul>
|
||||
<li> '<tt>dontroute</tt>'
|
||||
<li> '<tt>broadcast</tt>'
|
||||
<li> '<tt>reuseaddr</tt>'
|
||||
<li> '<tt>reuseport</tt>'
|
||||
<li> '<tt>ip-multicast-loop</tt>'
|
||||
<li> '<tt>ipv6-v6only</tt>'
|
||||
<li> '<tt>ip-multicast-if</tt>'
|
||||
<li> '<tt>ip-multicast-ttl</tt>'
|
||||
<li> '<tt>ip-add-membership</tt>'
|
||||
<li> '<tt>ip-drop-membership</tt>'
|
||||
<li> '<tt>dontroute</tt>'</li>
|
||||
<li> '<tt>broadcast</tt>'</li>
|
||||
<li> '<tt>reuseaddr</tt>'</li>
|
||||
<li> '<tt>reuseport</tt>'</li>
|
||||
<li> '<tt>ip-multicast-loop</tt>'</li>
|
||||
<li> '<tt>ipv6-v6only</tt>'</li>
|
||||
<li> '<tt>ip-multicast-if</tt>'</li>
|
||||
<li> '<tt>ip-multicast-ttl</tt>'</li>
|
||||
<li> '<tt>ip-add-membership</tt>'</li>
|
||||
<li> '<tt>ip-drop-membership</tt>'</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The method returns the option <tt>value</tt> in case of
|
||||
success, or
|
||||
<b><tt>nil</tt></b> followed by an error message otherwise.
|
||||
@ -108,7 +108,7 @@ associated with a connected UDP object.
|
||||
</p>
|
||||
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
Returns a string with the IP address of the peer, the
|
||||
port number that peer is using for the connection,
|
||||
and a string with the family ("<tt>inet</tt>" or "<tt>inet6</tt>").
|
||||
@ -131,7 +131,7 @@ Returns the local address information associated to the object.
|
||||
</p>
|
||||
|
||||
|
||||
<p class=return>
|
||||
<p class="return">
|
||||
The method returns a string with local IP address, a number with
|
||||
the local port,
|
||||
and a string with the family ("<tt>inet</tt>" or "<tt>inet6</tt>").
|
||||
@ -148,12 +148,12 @@ wild-card address).
|
||||
|
||||
<!-- gettimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="gettimeout">
|
||||
<p class="name" id="gettimeout">
|
||||
connected:<b>settimeout(</b>value<b>)</b><br>
|
||||
unconnected:<b>settimeout(</b>value<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<p class="description">
|
||||
Returns the current timeout value.
|
||||
</p>
|
||||
|
||||
@ -180,8 +180,8 @@ the excess bytes are discarded. If there are less then
|
||||
<tt>size</tt> bytes available in the current datagram, the
|
||||
available bytes are returned.
|
||||
If <tt>size</tt> is omitted, the
|
||||
compile-time constant <a
|
||||
href=socket.html#datagramsize><tt>socket._DATAGRAMSIZE</tt></a> is used
|
||||
compile-time constant <a href="socket.html#datagramsize">
|
||||
<tt>socket._DATAGRAMSIZE</tt></a> is used
|
||||
(it defaults to 8192 bytes). Larger sizes will cause a
|
||||
temporary buffer to be allocated for the operation.
|
||||
</p>
|
||||
@ -286,45 +286,45 @@ name, and <tt>value</tt> depends on the option being set:
|
||||
<ul>
|
||||
<li> '<tt>dontroute</tt>': Indicates that outgoing
|
||||
messages should bypass the standard routing facilities.
|
||||
Receives a boolean value;
|
||||
Receives a boolean value;</li>
|
||||
<li> '<tt>broadcast</tt>': Requests permission to send
|
||||
broadcast datagrams on the socket.
|
||||
Receives a boolean value;
|
||||
Receives a boolean value;</li>
|
||||
<li> '<tt>reuseaddr</tt>': Indicates that the rules used in
|
||||
validating addresses supplied in a <tt>bind()</tt> call
|
||||
should allow reuse of local addresses.
|
||||
Receives a boolean value;
|
||||
Receives a boolean value;</li>
|
||||
<li> '<tt>reuseport</tt>': Allows completely duplicate
|
||||
bindings by multiple processes if they all set
|
||||
'<tt>reuseport</tt>' before binding the port.
|
||||
Receives a boolean value;
|
||||
Receives a boolean value;</li>
|
||||
<li> '<tt>ip-multicast-loop</tt>':
|
||||
Specifies whether or not a copy of an outgoing multicast
|
||||
datagram is delivered to the sending host as long as it is a
|
||||
member of the multicast group.
|
||||
Receives a boolean value;
|
||||
Receives a boolean value;</li>
|
||||
<li> '<tt>ipv6-v6only</tt>':
|
||||
Specifies whether to restrict <tt>inet6</tt> sockets to
|
||||
sending and receiving only IPv6 packets.
|
||||
Receive a boolean value;
|
||||
Receive a boolean value;</li>
|
||||
<li> '<tt>ip-multicast-if</tt>':
|
||||
Sets the interface over which outgoing multicast datagrams
|
||||
are sent.
|
||||
Receives an IP address;
|
||||
Receives an IP address;</li>
|
||||
<li> '<tt>ip-multicast-ttl</tt>':
|
||||
Sets the Time To Live in the IP header for outgoing
|
||||
multicast datagrams.
|
||||
Receives a number;
|
||||
Receives a number;</li>
|
||||
<li> '<tt>ip-add-membership</tt>':
|
||||
Joins the multicast group specified.
|
||||
Receives a table with fields
|
||||
<tt>multiaddr</tt> and <tt>interface</tt>, each containing an
|
||||
IP address;
|
||||
IP address;</li>
|
||||
<li> '<tt>ip-drop-membership</tt>': Leaves the multicast
|
||||
group specified.
|
||||
Receives a table with fields
|
||||
<tt>multiaddr</tt> and <tt>interface</tt>, each containing an
|
||||
IP address.
|
||||
IP address.</li>
|
||||
</ul>
|
||||
|
||||
<p class="return">
|
||||
@ -332,7 +332,7 @@ The method returns 1 in case of success, or
|
||||
<b><tt>nil</tt></b> followed by an error message otherwise.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The descriptions above come from the man pages.
|
||||
</p>
|
||||
|
||||
@ -381,11 +381,11 @@ is recommended when the same peer is used for several transmissions
|
||||
and can result in up to 30% performance gains.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: Starting with LuaSocket 3.0, the host name resolution
|
||||
depends on whether the socket was created by <a
|
||||
href=#socket.udp><tt>socket.udp</tt></a> or <a
|
||||
href=#socket.udp6><tt>socket.udp6</tt></a>. Addresses from
|
||||
href="#socket.udp"><tt>socket.udp</tt></a> or <a
|
||||
href="#socket.udp6"><tt>socket.udp6</tt></a>. Addresses from
|
||||
the appropriate family are tried in succession until the
|
||||
first success or until the last failure.
|
||||
</p>
|
||||
@ -492,23 +492,23 @@ returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
|
||||
an error message.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The choice between IPv4 and IPv6 happens during a call to
|
||||
<a href=#sendto><tt>sendto</tt></a>, <a
|
||||
href=#setpeername><tt>setpeername</tt></a>, or <a
|
||||
href=#setsockname><tt>sockname</tt></a>, depending on the address
|
||||
<a href="#sendto"><tt>sendto</tt></a>, <a
|
||||
href="#setpeername"><tt>setpeername</tt></a>, or <a
|
||||
href="#setsockname"><tt>sockname</tt></a>, depending on the address
|
||||
family obtained from the resolver.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: Before the choice between IPv4 and IPv6 happens,
|
||||
the internal socket object is invalid and therefore <a
|
||||
href=#setoption><tt>setoption</tt></a> will fail.
|
||||
href="#setoption"><tt>setoption</tt></a> will fail.
|
||||
</p>
|
||||
|
||||
<!-- socket.udp4 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="socket.udp">
|
||||
<p class="name" id="socket.udp4">
|
||||
socket.<b>udp4()</b>
|
||||
</p>
|
||||
|
||||
@ -564,7 +564,7 @@ returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
|
||||
an error message.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<p class="note">
|
||||
Note: The TCP object returned will have the option
|
||||
"<tt>ipv6-v6only</tt>" set to <tt><b>true</b></tt>.
|
||||
</p>
|
||||
@ -573,10 +573,10 @@ Note: The TCP object returned will have the option
|
||||
|
||||
<!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<div class="footer">
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<p class="bar">
|
||||
<a href="index.html">home</a> ·
|
||||
<a href="index.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
@ -5,7 +5,7 @@ local ltn12 = require"ltn12"
|
||||
|
||||
local token_class = '[^%c%s%(%)%<%>%@%,%;%:%\\%"%/%[%]%?%=%{%}]'
|
||||
|
||||
local function unquote(t, quoted)
|
||||
local function unquote(t, quoted)
|
||||
local n = string.match(t, "%$(%d+)$")
|
||||
if n then n = tonumber(n) end
|
||||
if quoted[n] then return quoted[n]
|
||||
@ -14,19 +14,19 @@ end
|
||||
|
||||
local function parse_set_cookie(c, quoted, cookie_table)
|
||||
c = c .. ";$last=last;"
|
||||
local _, __, n, v, i = string.find(c, "(" .. token_class ..
|
||||
local _, _, n, v, i = string.find(c, "(" .. token_class ..
|
||||
"+)%s*=%s*(.-)%s*;%s*()")
|
||||
local cookie = {
|
||||
name = n,
|
||||
value = unquote(v, quoted),
|
||||
name = n,
|
||||
value = unquote(v, quoted),
|
||||
attributes = {}
|
||||
}
|
||||
while 1 do
|
||||
_, __, n, v, i = string.find(c, "(" .. token_class ..
|
||||
_, _, n, v, i = string.find(c, "(" .. token_class ..
|
||||
"+)%s*=?%s*(.-)%s*;%s*()", i)
|
||||
if not n or n == "$last" then break end
|
||||
cookie.attributes[#cookie.attributes+1] = {
|
||||
name = n,
|
||||
name = n,
|
||||
value = unquote(v, quoted)
|
||||
}
|
||||
end
|
||||
@ -46,8 +46,8 @@ local function split_set_cookie(s, cookie_table)
|
||||
-- split into individual cookies
|
||||
i = 1
|
||||
while 1 do
|
||||
local _, __, cookie, next_token
|
||||
_, __, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" ..
|
||||
local _, _, cookie, next_token
|
||||
_, _, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" ..
|
||||
token_class .. "+)%s*=", i)
|
||||
if not next_token then break end
|
||||
parse_set_cookie(cookie, quoted, cookie_table)
|
||||
@ -62,12 +62,12 @@ local function quote(s)
|
||||
end
|
||||
|
||||
local _empty = {}
|
||||
local function build_cookies(cookies)
|
||||
local function build_cookies(cookies)
|
||||
s = ""
|
||||
for i,v in ipairs(cookies or _empty) do
|
||||
if v.name then
|
||||
s = s .. v.name
|
||||
if v.value and v.value ~= "" then
|
||||
if v.value and v.value ~= "" then
|
||||
s = s .. '=' .. quote(v.value)
|
||||
end
|
||||
end
|
||||
@ -83,6 +83,6 @@ local function build_cookies(cookies)
|
||||
end
|
||||
if i < #cookies then s = s .. ", " end
|
||||
end
|
||||
return s
|
||||
return s
|
||||
end
|
||||
|
||||
|
@ -71,7 +71,7 @@ function stats(size)
|
||||
local current = socket.gettime()
|
||||
if chunk then
|
||||
-- total bytes received
|
||||
got = got + string.len(chunk)
|
||||
got = got + string.len(chunk)
|
||||
-- not enough time for estimate
|
||||
if current - last > 1 then
|
||||
io.stderr:write("\r", gauge(got, current - start, size))
|
||||
|
@ -1,7 +1,7 @@
|
||||
local input = source.chain(
|
||||
source.file(io.open("input.bin", "rb")),
|
||||
source.file(io.open("input.bin", "rb")),
|
||||
encode("base64"))
|
||||
local output = sink.chain(
|
||||
wrap(76),
|
||||
wrap(76),
|
||||
sink.file(io.open("output.b64", "w")))
|
||||
pump.all(input, output)
|
||||
|
@ -7,7 +7,7 @@ local function chainpair(f1, f2)
|
||||
end
|
||||
|
||||
function filter.chain(...)
|
||||
local f = select(1, ...)
|
||||
local f = select(1, ...)
|
||||
for i = 2, select('#', ...) do
|
||||
f = chainpair(f, select(i, ...))
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
local qp = filter.chain(normalize(CRLF), encode("quoted-printable"),
|
||||
local qp = filter.chain(normalize(CRLF), encode("quoted-printable"),
|
||||
wrap("quoted-printable"))
|
||||
local input = source.chain(source.file(io.stdin), qp)
|
||||
local output = sink.file(io.stdout)
|
||||
|
@ -1,105 +0,0 @@
|
||||
package = "LuaSocket"
|
||||
version = "scm-0"
|
||||
source = {
|
||||
url = "https://github.com/diegonehab/luasocket/archive/master.zip",
|
||||
dir = "luasocket-master",
|
||||
}
|
||||
description = {
|
||||
summary = "Network support for the Lua language",
|
||||
detailed = [[
|
||||
LuaSocket is a Lua extension library that is composed by two parts: a C core
|
||||
that provides support for the TCP and UDP transport layers, and a set of Lua
|
||||
modules that add support for functionality commonly needed by applications
|
||||
that deal with the Internet.
|
||||
]],
|
||||
homepage = "http://luaforge.net/projects/luasocket/",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
|
||||
local function make_plat(plat)
|
||||
local defines = {
|
||||
unix = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"LUASOCKET_API=__attribute__((visibility(\"default\")))",
|
||||
"UNIX_API=__attribute__((visibility(\"default\")))",
|
||||
"MIME_API=__attribute__((visibility(\"default\")))"
|
||||
},
|
||||
macosx = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"UNIX_HAS_SUN_LEN",
|
||||
"LUASOCKET_API=__attribute__((visibility(\"default\")))",
|
||||
"UNIX_API=__attribute__((visibility(\"default\")))",
|
||||
"MIME_API=__attribute__((visibility(\"default\")))"
|
||||
},
|
||||
win32 = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"NDEBUG",
|
||||
"LUASOCKET_API=__declspec(dllexport)",
|
||||
"MIME_API=__declspec(dllexport)"
|
||||
},
|
||||
mingw32 = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"LUASOCKET_INET_PTON",
|
||||
"WINVER=0x0501",
|
||||
"LUASOCKET_API=__declspec(dllexport)",
|
||||
"MIME_API=__declspec(dllexport)"
|
||||
}
|
||||
}
|
||||
local modules = {
|
||||
["socket.core"] = {
|
||||
sources = { "src/luasocket.c", "src/timeout.c", "src/buffer.c", "src/io.c", "src/auxiliar.c", "src/options.c", "src/inet.c", "src/except.c", "src/select.c", "src/tcp.c", "src/udp.c", "src/compat.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
},
|
||||
["mime.core"] = {
|
||||
sources = { "src/mime.c", "src/compat.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
},
|
||||
["socket.http"] = "src/http.lua",
|
||||
["socket.url"] = "src/url.lua",
|
||||
["socket.tp"] = "src/tp.lua",
|
||||
["socket.ftp"] = "src/ftp.lua",
|
||||
["socket.headers"] = "src/headers.lua",
|
||||
["socket.smtp"] = "src/smtp.lua",
|
||||
ltn12 = "src/ltn12.lua",
|
||||
socket = "src/socket.lua",
|
||||
mime = "src/mime.lua"
|
||||
}
|
||||
if plat == "unix" or plat == "macosx" or plat == "haiku" then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
|
||||
if plat == "haiku" then
|
||||
modules["socket.core"].libraries = {"network"}
|
||||
end
|
||||
modules["socket.unix"] = {
|
||||
sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/unix.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
modules["socket.serial"] = {
|
||||
sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/serial.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
end
|
||||
if plat == "win32" or plat == "mingw32" then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
|
||||
modules["socket.core"].libraries = { "ws2_32" }
|
||||
end
|
||||
return { modules = modules }
|
||||
end
|
||||
|
||||
build = {
|
||||
type = "builtin",
|
||||
platforms = {
|
||||
unix = make_plat("unix"),
|
||||
macosx = make_plat("macosx"),
|
||||
haiku = make_plat("haiku"),
|
||||
win32 = make_plat("win32"),
|
||||
mingw32 = make_plat("mingw32")
|
||||
},
|
||||
copy_directories = { "doc", "samples", "etc", "test" }
|
||||
}
|
135
luasocket-scm-3.rockspec
Normal file
135
luasocket-scm-3.rockspec
Normal file
@ -0,0 +1,135 @@
|
||||
package = "LuaSocket"
|
||||
version = "scm-3"
|
||||
source = {
|
||||
url = "git+https://github.com/lunarmodules/luasocket.git",
|
||||
branch = "master"
|
||||
}
|
||||
description = {
|
||||
summary = "Network support for the Lua language",
|
||||
detailed = [[
|
||||
LuaSocket is a Lua extension library composed of two parts: a set of C
|
||||
modules that provide support for the TCP and UDP transport layers, and a
|
||||
set of Lua modules that provide functions commonly needed by applications
|
||||
that deal with the Internet.
|
||||
]],
|
||||
homepage = "https://github.com/lunarmodules/luasocket",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
|
||||
local function make_plat(plat)
|
||||
local defines = {
|
||||
unix = {
|
||||
"LUASOCKET_DEBUG"
|
||||
},
|
||||
macosx = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"UNIX_HAS_SUN_LEN"
|
||||
},
|
||||
win32 = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"NDEBUG"
|
||||
},
|
||||
mingw32 = {
|
||||
"LUASOCKET_DEBUG",
|
||||
-- "LUASOCKET_INET_PTON",
|
||||
"WINVER=0x0501"
|
||||
}
|
||||
}
|
||||
local modules = {
|
||||
["socket.core"] = {
|
||||
sources = {
|
||||
"src/luasocket.c"
|
||||
, "src/timeout.c"
|
||||
, "src/buffer.c"
|
||||
, "src/io.c"
|
||||
, "src/auxiliar.c"
|
||||
, "src/options.c"
|
||||
, "src/inet.c"
|
||||
, "src/except.c"
|
||||
, "src/select.c"
|
||||
, "src/tcp.c"
|
||||
, "src/udp.c"
|
||||
, "src/compat.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
},
|
||||
["mime.core"] = {
|
||||
sources = { "src/mime.c", "src/compat.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
},
|
||||
["socket.http"] = "src/http.lua",
|
||||
["socket.url"] = "src/url.lua",
|
||||
["socket.tp"] = "src/tp.lua",
|
||||
["socket.ftp"] = "src/ftp.lua",
|
||||
["socket.headers"] = "src/headers.lua",
|
||||
["socket.smtp"] = "src/smtp.lua",
|
||||
ltn12 = "src/ltn12.lua",
|
||||
socket = "src/socket.lua",
|
||||
mime = "src/mime.lua"
|
||||
}
|
||||
if plat == "unix"
|
||||
or plat == "macosx"
|
||||
or plat == "haiku"
|
||||
then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
|
||||
if plat == "haiku" then
|
||||
modules["socket.core"].libraries = {"network"}
|
||||
end
|
||||
modules["socket.unix"] = {
|
||||
sources = {
|
||||
"src/buffer.c"
|
||||
, "src/compat.c"
|
||||
, "src/auxiliar.c"
|
||||
, "src/options.c"
|
||||
, "src/timeout.c"
|
||||
, "src/io.c"
|
||||
, "src/usocket.c"
|
||||
, "src/unix.c"
|
||||
, "src/unixdgram.c"
|
||||
, "src/unixstream.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
modules["socket.serial"] = {
|
||||
sources = {
|
||||
"src/buffer.c"
|
||||
, "src/compat.c"
|
||||
, "src/auxiliar.c"
|
||||
, "src/options.c"
|
||||
, "src/timeout.c"
|
||||
, "src/io.c"
|
||||
, "src/usocket.c"
|
||||
, "src/serial.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
end
|
||||
if plat == "win32"
|
||||
or plat == "mingw32"
|
||||
then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
|
||||
modules["socket.core"].libraries = { "ws2_32" }
|
||||
modules["socket.core"].libdirs = {}
|
||||
end
|
||||
return { modules = modules }
|
||||
end
|
||||
|
||||
build = {
|
||||
type = "builtin",
|
||||
platforms = {
|
||||
unix = make_plat("unix"),
|
||||
macosx = make_plat("macosx"),
|
||||
haiku = make_plat("haiku"),
|
||||
win32 = make_plat("win32"),
|
||||
mingw32 = make_plat("mingw32")
|
||||
},
|
||||
copy_directories = {
|
||||
"docs"
|
||||
, "samples"
|
||||
, "etc"
|
||||
, "test" }
|
||||
}
|
@ -1 +1 @@
|
||||
make DEBUG=DEBUG PLAT=macosx LUAINC_macosx_base=/Users/diego/build/macosx/include LUAPREFIX_macosx=/Users/diego/build/macosx install-both
|
||||
make DEBUG=DEBUG PLAT=macosx LUAINC_macosx_base=/Users/$USER/build/macosx/include LUAPREFIX_macosx=/Users/$USER/build/macosx install-both
|
||||
|
8
makefile
Normal file → Executable file
8
makefile
Normal file → Executable file
@ -10,7 +10,7 @@
|
||||
# print print the build settings
|
||||
|
||||
PLAT?= linux
|
||||
PLATS= macosx linux win32 mingw freebsd solaris
|
||||
PLATS= macosx linux win32 win64 mingw freebsd solaris
|
||||
|
||||
all: $(PLAT)
|
||||
|
||||
@ -33,6 +33,9 @@ install-both:
|
||||
$(MAKE) clean
|
||||
@cd src; $(MAKE) $(PLAT) LUAV=5.3
|
||||
@cd src; $(MAKE) install LUAV=5.3
|
||||
$(MAKE) clean
|
||||
@cd src; $(MAKE) $(PLAT) LUAV=5.4
|
||||
@cd src; $(MAKE) install LUAV=5.4
|
||||
|
||||
install-both-unix:
|
||||
$(MAKE) clean
|
||||
@ -44,6 +47,9 @@ install-both-unix:
|
||||
$(MAKE) clean
|
||||
@cd src; $(MAKE) $(PLAT) LUAV=5.3
|
||||
@cd src; $(MAKE) install-unix LUAV=5.3
|
||||
$(MAKE) clean
|
||||
@cd src; $(MAKE) $(PLAT) LUAV=5.4
|
||||
@cd src; $(MAKE) install-unix LUAV=5.4
|
||||
|
||||
.PHONY: test
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#--------------------------------------------------------------------------
|
||||
# Distribution makefile
|
||||
#--------------------------------------------------------------------------
|
||||
DIST = luasocket-3.0-rc1
|
||||
DIST = luasocket-3.0.0
|
||||
|
||||
TEST = \
|
||||
test/README \
|
||||
@ -92,29 +92,29 @@ MAKE = \
|
||||
socket.vcxproj \
|
||||
mime.vcxproj
|
||||
|
||||
DOC = \
|
||||
doc/dns.html \
|
||||
doc/ftp.html \
|
||||
doc/index.html \
|
||||
doc/http.html \
|
||||
doc/installation.html \
|
||||
doc/introduction.html \
|
||||
doc/ltn12.html \
|
||||
doc/luasocket.png \
|
||||
doc/mime.html \
|
||||
doc/reference.css \
|
||||
doc/reference.html \
|
||||
doc/smtp.html \
|
||||
doc/socket.html \
|
||||
doc/tcp.html \
|
||||
doc/udp.html \
|
||||
doc/url.html
|
||||
DOCS = \
|
||||
docs/dns.html \
|
||||
docs/ftp.html \
|
||||
docs/index.html \
|
||||
docs/http.html \
|
||||
docs/installation.html \
|
||||
docs/introduction.html \
|
||||
docs/ltn12.html \
|
||||
docs/luasocket.png \
|
||||
docs/mime.html \
|
||||
docs/reference.css \
|
||||
docs/reference.html \
|
||||
docs/smtp.html \
|
||||
docs/socket.html \
|
||||
docs/tcp.html \
|
||||
docs/udp.html \
|
||||
docs/url.html
|
||||
|
||||
dist:
|
||||
mkdir -p $(DIST)
|
||||
cp -vf NEW $(DIST)
|
||||
cp -vf CHANGELOG.md $(DIST)
|
||||
cp -vf LICENSE $(DIST)
|
||||
cp -vf README $(DIST)
|
||||
cp -vf README.md $(DIST)
|
||||
cp -vf $(MAKE) $(DIST)
|
||||
|
||||
mkdir -p $(DIST)/etc
|
||||
@ -123,8 +123,8 @@ dist:
|
||||
mkdir -p $(DIST)/src
|
||||
cp -vf $(SRC) $(DIST)/src
|
||||
|
||||
mkdir -p $(DIST)/doc
|
||||
cp -vf $(DOC) $(DIST)/doc
|
||||
mkdir -p $(DIST)/docs
|
||||
cp -vf $(DOCS) $(DIST)/docs
|
||||
|
||||
mkdir -p $(DIST)/samples
|
||||
cp -vf $(SAMPLES) $(DIST)/samples
|
||||
|
56
mime.vcxproj
56
mime.vcxproj
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
@ -20,19 +20,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\mime.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="src\mime.lua">
|
||||
<FileType>Document</FileType>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy %(FullPath) $(LUALIB_PATH)$(Platform)\$(Configuration)</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy %(FullPath) $(LUALIB_PATH)$(Platform)\$(Configuration)</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
</CustomBuild>
|
||||
<ClCompile Include="src\compat.c" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{128E8BD0-174A-48F0-8771-92B1E8D18713}</ProjectGuid>
|
||||
@ -41,22 +29,22 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
@ -87,7 +75,7 @@
|
||||
<_ProjectFileVersion>11.0.50727.1</_ProjectFileVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(LUABIN_PATH)$(Configuration)\mime\</OutDir>
|
||||
<OutDir>$(Configuration)\mime\</OutDir>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetName>core</TargetName>
|
||||
@ -95,23 +83,23 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetName>core</TargetName>
|
||||
<OutDir>$(LUABIN_PATH)$(Platform)\$(Configuration)\mime\</OutDir>
|
||||
<OutDir>$(Platform)\$(Configuration)\mime\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(LUABIN_PATH)$(Configuration)\mime\</OutDir>
|
||||
<OutDir>$(Configuration)\mime\</OutDir>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>core</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(LUABIN_PATH)$(Platform)\$(Configuration)\mime\</OutDir>
|
||||
<OutDir>$(Platform)\$(Configuration)\mime\</OutDir>
|
||||
<TargetName>core</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(LUAINC_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(LUAINC);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
@ -122,9 +110,9 @@
|
||||
<ProgramDataBaseFileName>$(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(LUALIB);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>$(LUALIBNAME);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)$(TargetName).dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(LUALIB);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(OutDir)mime.pdb</ProgramDatabaseFile>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@ -138,7 +126,7 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(LUAINC_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(LUAINC);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@ -149,9 +137,9 @@
|
||||
<ProgramDataBaseFileName>$(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(LUALIB);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>$(LUALIBNAME);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)$(TargetName).dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(LUALIB);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(OutDir)mime.pdb</ProgramDatabaseFile>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@ -163,7 +151,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(LUAINC_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(LUAINC);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader />
|
||||
@ -172,9 +160,9 @@
|
||||
<ProgramDataBaseFileName>$(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(LUALIB);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>$(LUALIBNAME);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)$(TargetName).dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(LUALIB);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
@ -187,7 +175,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(LUAINC_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(LUAINC);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
@ -198,9 +186,9 @@
|
||||
<ProgramDataBaseFileName>$(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(LUALIB);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>$(LUALIBNAME);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)$(TargetName).dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(LUALIB);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
|
@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\mime.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="cdir">
|
||||
<UniqueIdentifier>{fad87a86-297c-4881-a114-73b967bb3c92}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="src\mime.lua">
|
||||
<Filter>cdir</Filter>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,105 +0,0 @@
|
||||
package = "LuaSocket"
|
||||
version = "3.0rc2-1"
|
||||
source = {
|
||||
url = "git://github.com/diegonehab/luasocket.git",
|
||||
tag = "v3.0-rc2",
|
||||
}
|
||||
description = {
|
||||
summary = "Network support for the Lua language",
|
||||
detailed = [[
|
||||
LuaSocket is a Lua extension library that is composed by two parts: a C core
|
||||
that provides support for the TCP and UDP transport layers, and a set of Lua
|
||||
modules that add support for functionality commonly needed by applications
|
||||
that deal with the Internet.
|
||||
]],
|
||||
homepage = "http://luaforge.net/projects/luasocket/",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
|
||||
local function make_plat(plat)
|
||||
local defines = {
|
||||
unix = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"LUASOCKET_API=__attribute__((visibility(\"default\")))",
|
||||
"UNIX_API=__attribute__((visibility(\"default\")))",
|
||||
"MIME_API=__attribute__((visibility(\"default\")))"
|
||||
},
|
||||
macosx = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"UNIX_HAS_SUN_LEN",
|
||||
"LUASOCKET_API=__attribute__((visibility(\"default\")))",
|
||||
"UNIX_API=__attribute__((visibility(\"default\")))",
|
||||
"MIME_API=__attribute__((visibility(\"default\")))"
|
||||
},
|
||||
win32 = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"NDEBUG",
|
||||
"LUASOCKET_API=__declspec(dllexport)",
|
||||
"MIME_API=__declspec(dllexport)"
|
||||
},
|
||||
mingw32 = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"LUASOCKET_INET_PTON",
|
||||
"WINVER=0x0501",
|
||||
"LUASOCKET_API=__declspec(dllexport)",
|
||||
"MIME_API=__declspec(dllexport)"
|
||||
}
|
||||
}
|
||||
local modules = {
|
||||
["socket.core"] = {
|
||||
sources = { "src/luasocket.c", "src/timeout.c", "src/buffer.c", "src/io.c", "src/auxiliar.c", "src/options.c", "src/inet.c", "src/except.c", "src/select.c", "src/tcp.c", "src/udp.c", "src/compat.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
},
|
||||
["mime.core"] = {
|
||||
sources = { "src/mime.c", "src/compat.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
},
|
||||
["socket.http"] = "src/http.lua",
|
||||
["socket.url"] = "src/url.lua",
|
||||
["socket.tp"] = "src/tp.lua",
|
||||
["socket.ftp"] = "src/ftp.lua",
|
||||
["socket.headers"] = "src/headers.lua",
|
||||
["socket.smtp"] = "src/smtp.lua",
|
||||
ltn12 = "src/ltn12.lua",
|
||||
socket = "src/socket.lua",
|
||||
mime = "src/mime.lua"
|
||||
}
|
||||
if plat == "unix" or plat == "macosx" or plat == "haiku" then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
|
||||
if plat == "haiku" then
|
||||
modules["socket.core"].libraries = {"network"}
|
||||
end
|
||||
modules["socket.unix"] = {
|
||||
sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/unix.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
modules["socket.serial"] = {
|
||||
sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/serial.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
end
|
||||
if plat == "win32" or plat == "mingw32" then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
|
||||
modules["socket.core"].libraries = { "ws2_32" }
|
||||
end
|
||||
return { modules = modules }
|
||||
end
|
||||
|
||||
build = {
|
||||
type = "builtin",
|
||||
platforms = {
|
||||
unix = make_plat("unix"),
|
||||
macosx = make_plat("macosx"),
|
||||
haiku = make_plat("haiku"),
|
||||
win32 = make_plat("win32"),
|
||||
mingw32 = make_plat("mingw32")
|
||||
},
|
||||
copy_directories = { "doc", "samples", "etc", "test" }
|
||||
}
|
134
rockspecs/luasocket-3.0.0-1.rockspec
Normal file
134
rockspecs/luasocket-3.0.0-1.rockspec
Normal file
@ -0,0 +1,134 @@
|
||||
package = "LuaSocket"
|
||||
version = "3.0.0-1"
|
||||
source = {
|
||||
url = "git+https://github.com/lunarmodules/luasocket.git",
|
||||
tag = "v3.0.0"
|
||||
}
|
||||
description = {
|
||||
summary = "Network support for the Lua language",
|
||||
detailed = [[
|
||||
LuaSocket is a Lua extension library composed of two parts: a set of C
|
||||
modules that provide support for the TCP and UDP transport layers, and a
|
||||
set of Lua modules that provide functions commonly needed by applications
|
||||
that deal with the Internet.
|
||||
]],
|
||||
homepage = "https://github.com/lunarmodules/luasocket",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
|
||||
local function make_plat(plat)
|
||||
local defines = {
|
||||
unix = {
|
||||
"LUASOCKET_DEBUG"
|
||||
},
|
||||
macosx = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"UNIX_HAS_SUN_LEN"
|
||||
},
|
||||
win32 = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"NDEBUG"
|
||||
},
|
||||
mingw32 = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"LUASOCKET_INET_PTON",
|
||||
"WINVER=0x0501"
|
||||
}
|
||||
}
|
||||
local modules = {
|
||||
["socket.core"] = {
|
||||
sources = {
|
||||
"src/luasocket.c"
|
||||
, "src/timeout.c"
|
||||
, "src/buffer.c"
|
||||
, "src/io.c"
|
||||
, "src/auxiliar.c"
|
||||
, "src/options.c"
|
||||
, "src/inet.c"
|
||||
, "src/except.c"
|
||||
, "src/select.c"
|
||||
, "src/tcp.c"
|
||||
, "src/udp.c"
|
||||
, "src/compat.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
},
|
||||
["mime.core"] = {
|
||||
sources = { "src/mime.c", "src/compat.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
},
|
||||
["socket.http"] = "src/http.lua",
|
||||
["socket.url"] = "src/url.lua",
|
||||
["socket.tp"] = "src/tp.lua",
|
||||
["socket.ftp"] = "src/ftp.lua",
|
||||
["socket.headers"] = "src/headers.lua",
|
||||
["socket.smtp"] = "src/smtp.lua",
|
||||
ltn12 = "src/ltn12.lua",
|
||||
socket = "src/socket.lua",
|
||||
mime = "src/mime.lua"
|
||||
}
|
||||
if plat == "unix"
|
||||
or plat == "macosx"
|
||||
or plat == "haiku"
|
||||
then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
|
||||
if plat == "haiku" then
|
||||
modules["socket.core"].libraries = {"network"}
|
||||
end
|
||||
modules["socket.unix"] = {
|
||||
sources = {
|
||||
"src/buffer.c"
|
||||
, "src/compat.c"
|
||||
, "src/auxiliar.c"
|
||||
, "src/options.c"
|
||||
, "src/timeout.c"
|
||||
, "src/io.c"
|
||||
, "src/usocket.c"
|
||||
, "src/unix.c"
|
||||
, "src/unixdgram.c"
|
||||
, "src/unixstream.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
modules["socket.serial"] = {
|
||||
sources = {
|
||||
"src/buffer.c"
|
||||
, "src/compat.c"
|
||||
, "src/auxiliar.c"
|
||||
, "src/options.c"
|
||||
, "src/timeout.c"
|
||||
, "src/io.c"
|
||||
, "src/usocket.c"
|
||||
, "src/serial.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
end
|
||||
if plat == "win32"
|
||||
or plat == "mingw32"
|
||||
then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
|
||||
modules["socket.core"].libraries = { "ws2_32" }
|
||||
end
|
||||
return { modules = modules }
|
||||
end
|
||||
|
||||
build = {
|
||||
type = "builtin",
|
||||
platforms = {
|
||||
unix = make_plat("unix"),
|
||||
macosx = make_plat("macosx"),
|
||||
haiku = make_plat("haiku"),
|
||||
win32 = make_plat("win32"),
|
||||
mingw32 = make_plat("mingw32")
|
||||
},
|
||||
copy_directories = {
|
||||
"docs"
|
||||
, "samples"
|
||||
, "etc"
|
||||
, "test" }
|
||||
}
|
108
rockspecs/luasocket-3.0rc1-2.rockspec
Normal file
108
rockspecs/luasocket-3.0rc1-2.rockspec
Normal file
@ -0,0 +1,108 @@
|
||||
package = "LuaSocket"
|
||||
version = "3.0rc1-2"
|
||||
source = {
|
||||
url = "https://github.com/diegonehab/luasocket/archive/v3.0-rc1.zip",
|
||||
dir = "luasocket-3.0-rc1",
|
||||
}
|
||||
description = {
|
||||
summary = "Network support for the Lua language",
|
||||
detailed = [[
|
||||
LuaSocket is a Lua extension library that is composed by two parts: a C core
|
||||
that provides support for the TCP and UDP transport layers, and a set of Lua
|
||||
modules that add support for functionality commonly needed by applications
|
||||
that deal with the Internet.
|
||||
]],
|
||||
homepage = "http://luaforge.net/projects/luasocket/",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
|
||||
local function make_plat(plat)
|
||||
local defines = {
|
||||
unix = {
|
||||
"LUA_COMPAT_APIINTCASTS",
|
||||
"LUASOCKET_DEBUG",
|
||||
"LUASOCKET_API=__attribute__((visibility(\"default\")))",
|
||||
"UNIX_API=__attribute__((visibility(\"default\")))",
|
||||
"MIME_API=__attribute__((visibility(\"default\")))"
|
||||
},
|
||||
macosx = {
|
||||
"LUA_COMPAT_APIINTCASTS",
|
||||
"LUASOCKET_DEBUG",
|
||||
"UNIX_HAS_SUN_LEN",
|
||||
"LUASOCKET_API=__attribute__((visibility(\"default\")))",
|
||||
"UNIX_API=__attribute__((visibility(\"default\")))",
|
||||
"MIME_API=__attribute__((visibility(\"default\")))"
|
||||
},
|
||||
win32 = {
|
||||
"LUA_COMPAT_APIINTCASTS",
|
||||
"LUASOCKET_DEBUG",
|
||||
"NDEBUG",
|
||||
"LUASOCKET_API=__declspec(dllexport)",
|
||||
"MIME_API=__declspec(dllexport)"
|
||||
},
|
||||
mingw32 = {
|
||||
"LUA_COMPAT_APIINTCASTS",
|
||||
"LUASOCKET_DEBUG",
|
||||
"LUASOCKET_INET_PTON",
|
||||
"WINVER=0x0501",
|
||||
"LUASOCKET_API=__declspec(dllexport)",
|
||||
"MIME_API=__declspec(dllexport)"
|
||||
}
|
||||
}
|
||||
local modules = {
|
||||
["socket.core"] = {
|
||||
sources = { "src/luasocket.c", "src/timeout.c", "src/buffer.c", "src/io.c", "src/auxiliar.c",
|
||||
"src/options.c", "src/inet.c", "src/except.c", "src/select.c", "src/tcp.c", "src/udp.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "src"
|
||||
},
|
||||
["mime.core"] = {
|
||||
sources = { "src/mime.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "src"
|
||||
},
|
||||
["socket.http"] = "src/http.lua",
|
||||
["socket.url"] = "src/url.lua",
|
||||
["socket.tp"] = "src/tp.lua",
|
||||
["socket.ftp"] = "src/ftp.lua",
|
||||
["socket.headers"] = "src/headers.lua",
|
||||
["socket.smtp"] = "src/smtp.lua",
|
||||
ltn12 = "src/ltn12.lua",
|
||||
socket = "src/socket.lua",
|
||||
mime = "src/mime.lua"
|
||||
}
|
||||
if plat == "unix" or plat == "macosx" then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
|
||||
modules["socket.unix"] = {
|
||||
sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c",
|
||||
"src/usocket.c", "src/unix.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
modules["socket.serial"] = {
|
||||
sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c",
|
||||
"src/io.c", "src/usocket.c", "src/serial.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
end
|
||||
if plat == "win32" or plat == "mingw32" then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
|
||||
modules["socket.core"].libraries = { "ws2_32" }
|
||||
end
|
||||
return { modules = modules }
|
||||
end
|
||||
|
||||
build = {
|
||||
type = "builtin",
|
||||
platforms = {
|
||||
unix = make_plat("unix"),
|
||||
macosx = make_plat("macosx"),
|
||||
win32 = make_plat("win32"),
|
||||
mingw32 = make_plat("mingw32")
|
||||
},
|
||||
copy_directories = { "doc", "samples", "etc", "test" }
|
||||
}
|
135
rockspecs/luasocket-3.1.0-1.rockspec
Normal file
135
rockspecs/luasocket-3.1.0-1.rockspec
Normal file
@ -0,0 +1,135 @@
|
||||
package = "LuaSocket"
|
||||
version = "3.1.0-1"
|
||||
source = {
|
||||
url = "git+https://github.com/lunarmodules/luasocket.git",
|
||||
tag = "v3.1.0"
|
||||
}
|
||||
description = {
|
||||
summary = "Network support for the Lua language",
|
||||
detailed = [[
|
||||
LuaSocket is a Lua extension library composed of two parts: a set of C
|
||||
modules that provide support for the TCP and UDP transport layers, and a
|
||||
set of Lua modules that provide functions commonly needed by applications
|
||||
that deal with the Internet.
|
||||
]],
|
||||
homepage = "https://github.com/lunarmodules/luasocket",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
|
||||
local function make_plat(plat)
|
||||
local defines = {
|
||||
unix = {
|
||||
"LUASOCKET_DEBUG"
|
||||
},
|
||||
macosx = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"UNIX_HAS_SUN_LEN"
|
||||
},
|
||||
win32 = {
|
||||
"LUASOCKET_DEBUG",
|
||||
"NDEBUG"
|
||||
},
|
||||
mingw32 = {
|
||||
"LUASOCKET_DEBUG",
|
||||
-- "LUASOCKET_INET_PTON",
|
||||
"WINVER=0x0501"
|
||||
}
|
||||
}
|
||||
local modules = {
|
||||
["socket.core"] = {
|
||||
sources = {
|
||||
"src/luasocket.c"
|
||||
, "src/timeout.c"
|
||||
, "src/buffer.c"
|
||||
, "src/io.c"
|
||||
, "src/auxiliar.c"
|
||||
, "src/options.c"
|
||||
, "src/inet.c"
|
||||
, "src/except.c"
|
||||
, "src/select.c"
|
||||
, "src/tcp.c"
|
||||
, "src/udp.c"
|
||||
, "src/compat.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
},
|
||||
["mime.core"] = {
|
||||
sources = { "src/mime.c", "src/compat.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
},
|
||||
["socket.http"] = "src/http.lua",
|
||||
["socket.url"] = "src/url.lua",
|
||||
["socket.tp"] = "src/tp.lua",
|
||||
["socket.ftp"] = "src/ftp.lua",
|
||||
["socket.headers"] = "src/headers.lua",
|
||||
["socket.smtp"] = "src/smtp.lua",
|
||||
ltn12 = "src/ltn12.lua",
|
||||
socket = "src/socket.lua",
|
||||
mime = "src/mime.lua"
|
||||
}
|
||||
if plat == "unix"
|
||||
or plat == "macosx"
|
||||
or plat == "haiku"
|
||||
then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
|
||||
if plat == "haiku" then
|
||||
modules["socket.core"].libraries = {"network"}
|
||||
end
|
||||
modules["socket.unix"] = {
|
||||
sources = {
|
||||
"src/buffer.c"
|
||||
, "src/compat.c"
|
||||
, "src/auxiliar.c"
|
||||
, "src/options.c"
|
||||
, "src/timeout.c"
|
||||
, "src/io.c"
|
||||
, "src/usocket.c"
|
||||
, "src/unix.c"
|
||||
, "src/unixdgram.c"
|
||||
, "src/unixstream.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
modules["socket.serial"] = {
|
||||
sources = {
|
||||
"src/buffer.c"
|
||||
, "src/compat.c"
|
||||
, "src/auxiliar.c"
|
||||
, "src/options.c"
|
||||
, "src/timeout.c"
|
||||
, "src/io.c"
|
||||
, "src/usocket.c"
|
||||
, "src/serial.c" },
|
||||
defines = defines[plat],
|
||||
incdir = "/src"
|
||||
}
|
||||
end
|
||||
if plat == "win32"
|
||||
or plat == "mingw32"
|
||||
then
|
||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
|
||||
modules["socket.core"].libraries = { "ws2_32" }
|
||||
modules["socket.core"].libdirs = {}
|
||||
end
|
||||
return { modules = modules }
|
||||
end
|
||||
|
||||
build = {
|
||||
type = "builtin",
|
||||
platforms = {
|
||||
unix = make_plat("unix"),
|
||||
macosx = make_plat("macosx"),
|
||||
haiku = make_plat("haiku"),
|
||||
win32 = make_plat("win32"),
|
||||
mingw32 = make_plat("mingw32")
|
||||
},
|
||||
copy_directories = {
|
||||
"docs"
|
||||
, "samples"
|
||||
, "etc"
|
||||
, "test" }
|
||||
}
|
@ -26,7 +26,7 @@ function parse(body)
|
||||
data[key] = value
|
||||
end
|
||||
end
|
||||
return data, code, message
|
||||
return data, code, message
|
||||
end
|
||||
|
||||
local host = socket.dns.gethostname()
|
||||
|
135
socket.vcxproj
135
socket.vcxproj
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
@ -21,6 +21,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\auxiliar.c" />
|
||||
<ClCompile Include="src\buffer.c" />
|
||||
<ClCompile Include="src\compat.c" />
|
||||
<ClCompile Include="src\except.c" />
|
||||
<ClCompile Include="src\inet.c" />
|
||||
<ClCompile Include="src\io.c" />
|
||||
@ -32,98 +33,6 @@
|
||||
<ClCompile Include="src\udp.c" />
|
||||
<ClCompile Include="src\wsocket.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="src\ltn12.lua">
|
||||
<FileType>Document</FileType>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\socket.lua">
|
||||
<FileType>Document</FileType>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension)</Outputs>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="src\ftp.lua">
|
||||
<FileType>Document</FileType>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\headers.lua">
|
||||
<FileType>Document</FileType>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\http.lua">
|
||||
<FileType>Document</FileType>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\smtp.lua">
|
||||
<FileType>Document</FileType>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\tp.lua">
|
||||
<FileType>Document</FileType>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\url.lua">
|
||||
<FileType>Document</FileType>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket</Command>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
@ -131,22 +40,22 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
@ -177,7 +86,7 @@
|
||||
<_ProjectFileVersion>11.0.50727.1</_ProjectFileVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(LUALIB_PATH)$(Configuration)\socket\</OutDir>
|
||||
<OutDir>$(Configuration)\socket\</OutDir>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetName>core</TargetName>
|
||||
@ -185,23 +94,23 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetName>core</TargetName>
|
||||
<OutDir>$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\</OutDir>
|
||||
<OutDir>$(Platform)\$(Configuration)\socket\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(LUALIB_PATH)$(Configuration)\socket\</OutDir>
|
||||
<OutDir>$(Configuration)\socket\</OutDir>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>core</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(LUABIN_PATH)$(Platform)\$(Configuration)\socket\</OutDir>
|
||||
<OutDir>$(Platform)\$(Configuration)\socket\</OutDir>
|
||||
<TargetName>core</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(LUAINC_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(LUAINC);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUASOCKET_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
@ -212,9 +121,9 @@
|
||||
<ProgramDataBaseFileName>$(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(LUALIB);ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>$(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)$(TargetName).dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(LUALIB);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(OutDir)mime.pdb</ProgramDatabaseFile>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@ -228,7 +137,7 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(LUAINC_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(LUAINC);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUASOCKET_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@ -239,9 +148,9 @@
|
||||
<ProgramDataBaseFileName>$(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(LUALIB);ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>$(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)$(TargetName).dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(LUALIB);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(OutDir)mime.pdb</ProgramDatabaseFile>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@ -253,7 +162,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(LUAINC_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(LUAINC);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader />
|
||||
@ -262,9 +171,9 @@
|
||||
<ProgramDataBaseFileName>$(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(LUALIB);ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>$(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)$(TargetName).dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(LUALIB);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
@ -277,7 +186,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(LUAINC_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(LUAINC);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
@ -288,9 +197,9 @@
|
||||
<ProgramDataBaseFileName>$(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(LUALIB);ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>$(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)$(TargetName).dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(LUALIB);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
|
@ -1,51 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\auxiliar.c" />
|
||||
<ClCompile Include="src\buffer.c" />
|
||||
<ClCompile Include="src\except.c" />
|
||||
<ClCompile Include="src\inet.c" />
|
||||
<ClCompile Include="src\io.c" />
|
||||
<ClCompile Include="src\luasocket.c" />
|
||||
<ClCompile Include="src\options.c" />
|
||||
<ClCompile Include="src\select.c" />
|
||||
<ClCompile Include="src\tcp.c" />
|
||||
<ClCompile Include="src\timeout.c" />
|
||||
<ClCompile Include="src\udp.c" />
|
||||
<ClCompile Include="src\wsocket.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="src\ltn12.lua">
|
||||
<Filter>cdir</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\socket.lua">
|
||||
<Filter>cdir</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\ftp.lua">
|
||||
<Filter>ldir</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\headers.lua">
|
||||
<Filter>ldir</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\http.lua">
|
||||
<Filter>ldir</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\smtp.lua">
|
||||
<Filter>ldir</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\tp.lua">
|
||||
<Filter>ldir</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="src\url.lua">
|
||||
<Filter>ldir</Filter>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="cdir">
|
||||
<UniqueIdentifier>{b053460d-5439-4e3a-a2eb-c31a95b5691f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="ldir">
|
||||
<UniqueIdentifier>{b301b82c-37cb-4e05-9333-194e92ed7a62}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -2,14 +2,11 @@
|
||||
* Auxiliar routines for class hierarchy manipulation
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include "luasocket.h"
|
||||
#include "auxiliar.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "auxiliar.h"
|
||||
|
||||
/*=========================================================================*\
|
||||
* Exported functions
|
||||
\*=========================================================================*/
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Initializes the module
|
||||
\*-------------------------------------------------------------------------*/
|
||||
@ -155,4 +152,3 @@ int auxiliar_typeerror (lua_State *L, int narg, const char *tname) {
|
||||
luaL_typename(L, narg));
|
||||
return luaL_argerror(L, narg, msg);
|
||||
}
|
||||
|
||||
|
@ -29,20 +29,26 @@
|
||||
* reverse mapping are done using lauxlib.
|
||||
\*=========================================================================*/
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
int auxiliar_open(lua_State *L);
|
||||
void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func);
|
||||
int auxiliar_tostring(lua_State *L);
|
||||
void auxiliar_add2group(lua_State *L, const char *classname, const char *group);
|
||||
void auxiliar_setclass(lua_State *L, const char *classname, int objidx);
|
||||
int auxiliar_checkboolean(lua_State *L, int objidx);
|
||||
void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx);
|
||||
void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx);
|
||||
void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx);
|
||||
void auxiliar_setclass(lua_State *L, const char *classname, int objidx);
|
||||
void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx);
|
||||
int auxiliar_checkboolean(lua_State *L, int objidx);
|
||||
int auxiliar_tostring(lua_State *L);
|
||||
void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx);
|
||||
int auxiliar_typeerror(lua_State *L, int narg, const char *tname);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif /* AUXILIAR_H */
|
||||
|
10
src/buffer.c
10
src/buffer.c
@ -2,10 +2,7 @@
|
||||
* Input/Output interface for Lua programs
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include "luasocket.h"
|
||||
#include "buffer.h"
|
||||
|
||||
/*=========================================================================*\
|
||||
@ -106,11 +103,14 @@ int buffer_meth_send(lua_State *L, p_buffer buf) {
|
||||
* object:receive() interface
|
||||
\*-------------------------------------------------------------------------*/
|
||||
int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
||||
int err = IO_DONE, top = lua_gettop(L);
|
||||
int err = IO_DONE, top;
|
||||
luaL_Buffer b;
|
||||
size_t size;
|
||||
const char *part = luaL_optlstring(L, 3, "", &size);
|
||||
timeout_markstart(buf->tm);
|
||||
/* make sure we don't confuse buffer stuff with arguments */
|
||||
lua_settop(L, 3);
|
||||
top = lua_gettop(L);
|
||||
/* initialize buffer with optional extra prefix
|
||||
* (useful for concatenating previous partial results) */
|
||||
luaL_buffinit(L, &b);
|
||||
|
15
src/buffer.h
15
src/buffer.h
@ -15,8 +15,7 @@
|
||||
* The module is built on top of the I/O abstraction defined in io.h and the
|
||||
* timeout management is done with the timeout.h interface.
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
|
||||
#include "luasocket.h"
|
||||
#include "io.h"
|
||||
#include "timeout.h"
|
||||
|
||||
@ -34,12 +33,20 @@ typedef struct t_buffer_ {
|
||||
} t_buffer;
|
||||
typedef t_buffer *p_buffer;
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
int buffer_open(lua_State *L);
|
||||
void buffer_init(p_buffer buf, p_io io, p_timeout tm);
|
||||
int buffer_meth_send(lua_State *L, p_buffer buf);
|
||||
int buffer_meth_receive(lua_State *L, p_buffer buf);
|
||||
int buffer_meth_getstats(lua_State *L, p_buffer buf);
|
||||
int buffer_meth_setstats(lua_State *L, p_buffer buf);
|
||||
int buffer_meth_send(lua_State *L, p_buffer buf);
|
||||
int buffer_meth_receive(lua_State *L, p_buffer buf);
|
||||
int buffer_isempty(p_buffer buf);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif /* BUF_H */
|
||||
|
@ -1,10 +1,12 @@
|
||||
#include "luasocket.h"
|
||||
#include "compat.h"
|
||||
|
||||
#if LUA_VERSION_NUM==501
|
||||
|
||||
/*
|
||||
** Adapted from Lua 5.2
|
||||
*/
|
||||
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
|
||||
void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
|
||||
luaL_checkstack(L, nup+1, "too many upvalues");
|
||||
for (; l->name != NULL; l++) { /* fill the table with given functions */
|
||||
int i;
|
||||
@ -20,7 +22,7 @@ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
|
||||
/*
|
||||
** Duplicated from Lua 5.2
|
||||
*/
|
||||
void *luaL_testudata (lua_State *L, int ud, const char *tname) {
|
||||
void *luasocket_testudata (lua_State *L, int ud, const char *tname) {
|
||||
void *p = lua_touserdata(L, ud);
|
||||
if (p != NULL) { /* value is a userdata? */
|
||||
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
|
||||
|
20
src/compat.h
20
src/compat.h
@ -1,12 +1,22 @@
|
||||
#ifndef COMPAT_H
|
||||
#define COMPAT_H
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#if LUA_VERSION_NUM==501
|
||||
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);
|
||||
void *luaL_testudata ( lua_State *L, int arg, const char *tname);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup);
|
||||
void *luasocket_testudata ( lua_State *L, int arg, const char *tname);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#define luaL_setfuncs luasocket_setfuncs
|
||||
#define luaL_testudata luasocket_testudata
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -2,13 +2,9 @@
|
||||
* Simple exception support
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include "luasocket.h"
|
||||
#include "except.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if LUA_VERSION_NUM < 502
|
||||
#define lua_pcallk(L, na, nr, err, ctx, cont) \
|
||||
|
10
src/except.h
10
src/except.h
@ -31,8 +31,16 @@
|
||||
* exceptions on error, but that don't interrupt the user script.
|
||||
\*=========================================================================*/
|
||||
|
||||
#include "lua.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
int except_open(lua_State *L);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
14
src/ftp.lua
14
src/ftp.lua
@ -56,7 +56,7 @@ end
|
||||
|
||||
function metat.__index:login(user, password)
|
||||
self.try(self.tp:command("user", user or _M.USER))
|
||||
local code, reply = self.try(self.tp:check{"2..", 331})
|
||||
local code, _ = self.try(self.tp:check{"2..", 331})
|
||||
if code == 331 then
|
||||
self.try(self.tp:command("pass", password or _M.PASSWORD))
|
||||
self.try(self.tp:check("2.."))
|
||||
@ -66,7 +66,7 @@ end
|
||||
|
||||
function metat.__index:pasv()
|
||||
self.try(self.tp:command("pasv"))
|
||||
local code, reply = self.try(self.tp:check("2.."))
|
||||
local _, reply = self.try(self.tp:check("2.."))
|
||||
local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)"
|
||||
local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern))
|
||||
self.try(a and b and c and d and p1 and p2, reply)
|
||||
@ -83,9 +83,9 @@ end
|
||||
|
||||
function metat.__index:epsv()
|
||||
self.try(self.tp:command("epsv"))
|
||||
local code, reply = self.try(self.tp:check("229"))
|
||||
local _, reply = self.try(self.tp:check("229"))
|
||||
local pattern = "%((.)(.-)%1(.-)%1(.-)%1%)"
|
||||
local d, prt, address, port = string.match(reply, pattern)
|
||||
local _, _, _, port = string.match(reply, pattern)
|
||||
self.try(port, "invalid epsv response")
|
||||
self.pasvt = {
|
||||
address = self.tp:getpeername(),
|
||||
@ -102,7 +102,7 @@ end
|
||||
function metat.__index:port(address, port)
|
||||
self.pasvt = nil
|
||||
if not address then
|
||||
address, port = self.try(self.tp:getsockname())
|
||||
address = self.try(self.tp:getsockname())
|
||||
self.server = self.try(socket.bind(address, 0))
|
||||
address, port = self.try(self.server:getsockname())
|
||||
self.try(self.server:settimeout(_M.TIMEOUT))
|
||||
@ -118,7 +118,7 @@ end
|
||||
function metat.__index:eprt(family, address, port)
|
||||
self.pasvt = nil
|
||||
if not address then
|
||||
address, port = self.try(self.tp:getsockname())
|
||||
address = self.try(self.tp:getsockname())
|
||||
self.server = self.try(socket.bind(address, 0))
|
||||
address, port = self.try(self.server:getsockname())
|
||||
self.try(self.server:settimeout(_M.TIMEOUT))
|
||||
@ -142,7 +142,7 @@ function metat.__index:send(sendt)
|
||||
local command = sendt.command or "stor"
|
||||
-- send the transfer command and check the reply
|
||||
self.try(self.tp:command(command, argument))
|
||||
local code, reply = self.try(self.tp:check{"2..", "1.."})
|
||||
local code, _ = self.try(self.tp:check{"2..", "1.."})
|
||||
-- if there is not a pasvt table, then there is a server
|
||||
-- and we already sent a PORT command
|
||||
if not self.pasvt then self:portconnect() end
|
||||
|
88
src/http.lua
88
src/http.lua
@ -26,10 +26,20 @@ _M.TIMEOUT = 60
|
||||
-- user agent field sent in request
|
||||
_M.USERAGENT = socket._VERSION
|
||||
|
||||
-- supported schemes
|
||||
local SCHEMES = { ["http"] = true }
|
||||
-- default port for document retrieval
|
||||
local PORT = 80
|
||||
-- supported schemes and their particulars
|
||||
local SCHEMES = {
|
||||
http = {
|
||||
port = 80
|
||||
, create = function(t)
|
||||
return socket.tcp end }
|
||||
, https = {
|
||||
port = 443
|
||||
, create = function(t)
|
||||
local https = assert(
|
||||
require("ssl.https"), 'LuaSocket: LuaSec not found')
|
||||
local tcp = assert(
|
||||
https.tcp, 'LuaSocket: Function tcp() not available from LuaSec')
|
||||
return tcp(t) end }}
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Reads MIME headers from a connection, unfolding where needed
|
||||
@ -79,7 +89,7 @@ socket.sourcet["http-chunked"] = function(sock, headers)
|
||||
-- was it the last chunk?
|
||||
if size > 0 then
|
||||
-- if not, get chunk and skip terminating CRLF
|
||||
local chunk, err, part = sock:receive(size)
|
||||
local chunk, err, _ = sock:receive(size)
|
||||
if chunk then sock:receive() end
|
||||
return chunk, err
|
||||
else
|
||||
@ -111,13 +121,13 @@ local metat = { __index = {} }
|
||||
|
||||
function _M.open(host, port, create)
|
||||
-- create socket with user connect function, or with default
|
||||
local c = socket.try((create or socket.tcp)())
|
||||
local c = socket.try(create())
|
||||
local h = base.setmetatable({ c = c }, metat)
|
||||
-- create finalized try
|
||||
h.try = socket.newtry(function() h:close() end)
|
||||
-- set timeout before connecting
|
||||
h.try(c:settimeout(_M.TIMEOUT))
|
||||
h.try(c:connect(host, port or PORT))
|
||||
h.try(c:connect(host, port))
|
||||
-- here everything worked
|
||||
return h
|
||||
end
|
||||
@ -147,10 +157,15 @@ function metat.__index:sendbody(headers, source, step)
|
||||
end
|
||||
|
||||
function metat.__index:receivestatusline()
|
||||
local status = self.try(self.c:receive(5))
|
||||
local status,ec = self.try(self.c:receive(5))
|
||||
-- identify HTTP/0.9 responses, which do not contain a status line
|
||||
-- this is just a heuristic, but is what the RFC recommends
|
||||
if status ~= "HTTP/" then return nil, status end
|
||||
if status ~= "HTTP/" then
|
||||
if ec == "timeout" then
|
||||
return 408
|
||||
end
|
||||
return nil, status
|
||||
end
|
||||
-- otherwise proceed reading a status line
|
||||
status = self.try(self.c:receive("*l", status))
|
||||
local code = socket.skip(2, string.find(status, "HTTP/%d*%.%d* (%d%d%d)"))
|
||||
@ -212,7 +227,10 @@ end
|
||||
|
||||
local function adjustheaders(reqt)
|
||||
-- default headers
|
||||
local host = string.gsub(reqt.authority, "^.-@", "")
|
||||
local host = reqt.host
|
||||
local port = tostring(reqt.port)
|
||||
if port ~= tostring(SCHEMES[reqt.scheme].port) then
|
||||
host = host .. ':' .. port end
|
||||
local lower = {
|
||||
["user-agent"] = _M.USERAGENT,
|
||||
["host"] = host,
|
||||
@ -243,10 +261,8 @@ end
|
||||
|
||||
-- default url parts
|
||||
local default = {
|
||||
host = "",
|
||||
port = PORT,
|
||||
path ="/",
|
||||
scheme = "http"
|
||||
path ="/"
|
||||
, scheme = "http"
|
||||
}
|
||||
|
||||
local function adjustrequest(reqt)
|
||||
@ -254,14 +270,26 @@ local function adjustrequest(reqt)
|
||||
local nreqt = reqt.url and url.parse(reqt.url, default) or {}
|
||||
-- explicit components override url
|
||||
for i,v in base.pairs(reqt) do nreqt[i] = v end
|
||||
if nreqt.port == "" then nreqt.port = PORT end
|
||||
if not (nreqt.host and nreqt.host ~= "") then
|
||||
-- default to scheme particulars
|
||||
local schemedefs, host, port, method
|
||||
= SCHEMES[nreqt.scheme], nreqt.host, nreqt.port, nreqt.method
|
||||
if not nreqt.create then nreqt.create = schemedefs.create(nreqt) end
|
||||
if not (port and port ~= '') then nreqt.port = schemedefs.port end
|
||||
if not (method and method ~= '') then nreqt.method = 'GET' end
|
||||
if not (host and host ~= "") then
|
||||
socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'")
|
||||
end
|
||||
-- compute uri if user hasn't overriden
|
||||
nreqt.uri = reqt.uri or adjusturi(nreqt)
|
||||
-- adjust headers in request
|
||||
nreqt.headers = adjustheaders(nreqt)
|
||||
if nreqt.source
|
||||
and not nreqt.headers["content-length"]
|
||||
and not nreqt.headers["transfer-encoding"]
|
||||
then
|
||||
nreqt.headers["transfer-encoding"] = "chunked"
|
||||
end
|
||||
|
||||
-- ajust host and port if there is a proxy
|
||||
nreqt.host, nreqt.port = adjustproxy(nreqt)
|
||||
return nreqt
|
||||
@ -272,12 +300,16 @@ local function shouldredirect(reqt, code, headers)
|
||||
if not location then return false end
|
||||
location = string.gsub(location, "%s", "")
|
||||
if location == "" then return false end
|
||||
local scheme = string.match(location, "^([%w][%w%+%-%.]*)%:")
|
||||
if scheme and not SCHEMES[scheme] then return false end
|
||||
local scheme = url.parse(location).scheme
|
||||
if scheme and (not SCHEMES[scheme]) then return false end
|
||||
-- avoid https downgrades
|
||||
if ('https' == reqt.scheme) and ('https' ~= scheme) then return false end
|
||||
return (reqt.redirect ~= false) and
|
||||
(code == 301 or code == 302 or code == 303 or code == 307) and
|
||||
(not reqt.method or reqt.method == "GET" or reqt.method == "HEAD")
|
||||
and (not reqt.nredirects or reqt.nredirects < 5)
|
||||
and ((false == reqt.maxredirects)
|
||||
or ((reqt.nredirects or 0)
|
||||
< (reqt.maxredirects or 5)))
|
||||
end
|
||||
|
||||
local function shouldreceivebody(reqt, code)
|
||||
@ -291,14 +323,21 @@ end
|
||||
local trequest, tredirect
|
||||
|
||||
--[[local]] function tredirect(reqt, location)
|
||||
-- the RFC says the redirect URL has to be absolute, but some
|
||||
-- servers do not respect that
|
||||
local newurl = url.absolute(reqt.url, location)
|
||||
-- if switching schemes, reset port and create function
|
||||
if url.parse(newurl).scheme ~= reqt.scheme then
|
||||
reqt.port = nil
|
||||
reqt.create = nil end
|
||||
-- make new request
|
||||
local result, code, headers, status = trequest {
|
||||
-- the RFC says the redirect URL has to be absolute, but some
|
||||
-- servers do not respect that
|
||||
url = url.absolute(reqt.url, location),
|
||||
url = newurl,
|
||||
source = reqt.source,
|
||||
sink = reqt.sink,
|
||||
headers = reqt.headers,
|
||||
proxy = reqt.proxy,
|
||||
maxredirects = reqt.maxredirects,
|
||||
nredirects = (reqt.nredirects or 0) + 1,
|
||||
create = reqt.create
|
||||
}
|
||||
@ -325,11 +364,13 @@ end
|
||||
if not code then
|
||||
h:receive09body(status, nreqt.sink, nreqt.step)
|
||||
return 1, 200
|
||||
elseif code == 408 then
|
||||
return 1, code
|
||||
end
|
||||
local headers
|
||||
-- ignore any 100-continue messages
|
||||
while code == 100 do
|
||||
headers = h:receiveheaders()
|
||||
h:receiveheaders()
|
||||
code, status = h:receivestatusline()
|
||||
end
|
||||
headers = h:receiveheaders()
|
||||
@ -379,4 +420,5 @@ _M.request = socket.protect(function(reqt, body)
|
||||
else return trequest(reqt) end
|
||||
end)
|
||||
|
||||
_M.schemes = SCHEMES
|
||||
return _M
|
||||
|
16
src/inet.c
Normal file → Executable file
16
src/inet.c
Normal file → Executable file
@ -2,16 +2,13 @@
|
||||
* Internet domain functions
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include "luasocket.h"
|
||||
#include "inet.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include "inet.h"
|
||||
|
||||
/*=========================================================================*\
|
||||
* Internal function prototypes.
|
||||
\*=========================================================================*/
|
||||
@ -32,9 +29,6 @@ static luaL_Reg func[] = {
|
||||
{ NULL, NULL}
|
||||
};
|
||||
|
||||
/*=========================================================================*\
|
||||
* Exported functions
|
||||
\*=========================================================================*/
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Initializes module
|
||||
\*-------------------------------------------------------------------------*/
|
||||
@ -259,7 +253,7 @@ int inet_meth_getpeername(lua_State *L, p_socket ps, int family)
|
||||
port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
if (err) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, gai_strerror(err));
|
||||
lua_pushstring(L, LUA_GAI_STRERROR(err));
|
||||
return 2;
|
||||
}
|
||||
lua_pushstring(L, name);
|
||||
@ -292,7 +286,7 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
|
||||
name, INET6_ADDRSTRLEN, port, 6, NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
if (err) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, gai_strerror(err));
|
||||
lua_pushstring(L, LUA_GAI_STRERROR(err));
|
||||
return 2;
|
||||
}
|
||||
lua_pushstring(L, name);
|
||||
|
26
src/inet.h
26
src/inet.h
@ -14,7 +14,7 @@
|
||||
*
|
||||
* The Lua functions toip and tohostname are also implemented here.
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "luasocket.h"
|
||||
#include "socket.h"
|
||||
#include "timeout.h"
|
||||
|
||||
@ -22,21 +22,23 @@
|
||||
#define LUASOCKET_INET_ATON
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
int inet_open(lua_State *L);
|
||||
|
||||
const char *inet_trycreate(p_socket ps, int family, int type, int protocol);
|
||||
const char *inet_tryconnect(p_socket ps, int *family, const char *address,
|
||||
const char *serv, p_timeout tm, struct addrinfo *connecthints);
|
||||
const char *inet_trybind(p_socket ps, int *family, const char *address,
|
||||
const char *serv, struct addrinfo *bindhints);
|
||||
const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm);
|
||||
const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm);
|
||||
int inet_optfamily(lua_State* L, int narg, const char* def);
|
||||
int inet_optsocktype(lua_State* L, int narg, const char* def);
|
||||
|
||||
int inet_meth_getpeername(lua_State *L, p_socket ps, int family);
|
||||
int inet_meth_getsockname(lua_State *L, p_socket ps, int family);
|
||||
|
||||
int inet_optfamily(lua_State* L, int narg, const char* def);
|
||||
int inet_optsocktype(lua_State* L, int narg, const char* def);
|
||||
const char *inet_trycreate(p_socket ps, int family, int type, int protocol);
|
||||
const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm);
|
||||
const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *serv, p_timeout tm, struct addrinfo *connecthints);
|
||||
const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm);
|
||||
const char *inet_trybind(p_socket ps, int *family, const char *address, const char *serv, struct addrinfo *bindhints);
|
||||
|
||||
#ifdef LUASOCKET_INET_ATON
|
||||
int inet_aton(const char *cp, struct in_addr *inp);
|
||||
@ -47,4 +49,8 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt);
|
||||
int inet_pton(int af, const char *src, void *dst);
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif /* INET_H */
|
||||
|
4
src/io.c
4
src/io.c
@ -2,11 +2,9 @@
|
||||
* Input/Output abstraction
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include "luasocket.h"
|
||||
#include "io.h"
|
||||
|
||||
/*=========================================================================*\
|
||||
* Exported functions
|
||||
\*=========================================================================*/
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Initializes C structure
|
||||
\*-------------------------------------------------------------------------*/
|
||||
|
13
src/io.h
13
src/io.h
@ -12,9 +12,7 @@
|
||||
* The module socket.h implements this interface, and thus the module tcp.h
|
||||
* is very simple.
|
||||
\*=========================================================================*/
|
||||
#include <stdio.h>
|
||||
#include "lua.h"
|
||||
|
||||
#include "luasocket.h"
|
||||
#include "timeout.h"
|
||||
|
||||
/* IO error codes */
|
||||
@ -58,8 +56,15 @@ typedef struct t_io_ {
|
||||
} t_io;
|
||||
typedef t_io *p_io;
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx);
|
||||
const char *io_strerror(int err);
|
||||
|
||||
#endif /* IO_H */
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif /* IO_H */
|
||||
|
@ -11,9 +11,11 @@ local string = require("string")
|
||||
local table = require("table")
|
||||
local unpack = unpack or table.unpack
|
||||
local base = _G
|
||||
local select = select
|
||||
|
||||
local _M = {}
|
||||
if module then -- heuristic for exporting a global package table
|
||||
ltn12 = _M
|
||||
ltn12 = _M -- luacheck: ignore
|
||||
end
|
||||
local filter,source,sink,pump = {},{},{},{}
|
||||
|
||||
@ -22,9 +24,6 @@ _M.source = source
|
||||
_M.sink = sink
|
||||
_M.pump = pump
|
||||
|
||||
local unpack = unpack or table.unpack
|
||||
local select = base.select
|
||||
|
||||
-- 2048 seems to be better in windows...
|
||||
_M.BLOCKSIZE = 2048
|
||||
_M._VERSION = "LTN12 1.0.3"
|
||||
@ -46,7 +45,7 @@ end
|
||||
-- (thanks to Wim Couwenberg)
|
||||
function filter.chain(...)
|
||||
local arg = {...}
|
||||
local n = base.select('#',...)
|
||||
local n = select('#',...)
|
||||
local top, index = 1, 1
|
||||
local retry = ""
|
||||
return function(chunk)
|
||||
|
12
src/luasocket.c
Normal file → Executable file
12
src/luasocket.c
Normal file → Executable file
@ -12,16 +12,6 @@
|
||||
* standard Lua read and write functions.
|
||||
\*=========================================================================*/
|
||||
|
||||
/*=========================================================================*\
|
||||
* Standard include files
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
|
||||
/*=========================================================================*\
|
||||
* LuaSocket includes
|
||||
\*=========================================================================*/
|
||||
#include "luasocket.h"
|
||||
#include "auxiliar.h"
|
||||
#include "except.h"
|
||||
@ -64,7 +54,7 @@ static luaL_Reg func[] = {
|
||||
* Skip a few arguments
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static int global_skip(lua_State *L) {
|
||||
int amount = luaL_checkinteger(L, 1);
|
||||
int amount = (int) luaL_checkinteger(L, 1);
|
||||
int ret = lua_gettop(L) - amount - 1;
|
||||
return ret >= 0 ? ret : 0;
|
||||
}
|
||||
|
@ -6,20 +6,27 @@
|
||||
* Diego Nehab
|
||||
* 9/11/1999
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
/*-------------------------------------------------------------------------* \
|
||||
* Current socket library version
|
||||
\*-------------------------------------------------------------------------*/
|
||||
#define LUASOCKET_VERSION "LuaSocket 3.0-rc1"
|
||||
#define LUASOCKET_VERSION "LuaSocket 3.0.0"
|
||||
#define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab"
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* This macro prefixes all exported API functions
|
||||
\*-------------------------------------------------------------------------*/
|
||||
#ifndef LUASOCKET_API
|
||||
#define LUASOCKET_API extern
|
||||
#ifdef _WIN32
|
||||
#define LUASOCKET_API __declspec(dllexport)
|
||||
#else
|
||||
#define LUASOCKET_API __attribute__ ((visibility ("default")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Initializes the library.
|
||||
|
131
src/makefile
Normal file → Executable file
131
src/makefile
Normal file → Executable file
@ -12,11 +12,11 @@
|
||||
#
|
||||
# make PLAT=linux DEBUG=DEBUG LUAV=5.2 prefix=/sw
|
||||
|
||||
# PLAT: linux macosx win32 mingw
|
||||
# PLAT: linux macosx win32 win64 mingw
|
||||
# platform to build for
|
||||
PLAT?=linux
|
||||
|
||||
# LUAV: 5.1 5.2
|
||||
# LUAV: 5.1 5.2 5.3 5.4
|
||||
# lua version to build against
|
||||
LUAV?=5.1
|
||||
|
||||
@ -35,7 +35,8 @@ DEBUG?=NODEBUG
|
||||
# LUAINC_macosx:
|
||||
# /opt/local/include
|
||||
LUAINC_macosx_base?=/opt/local/include
|
||||
LUAINC_macosx?=$(LUAINC_macosx_base)/lua/$(LUAV)
|
||||
LUAINC_macosx?=$(LUAINC_macosx_base)/lua/$(LUAV) $(LUAINC_macosx_base)/lua$(LUAV) $(LUAINC_macosx_base)/lua-$(LUAV)
|
||||
|
||||
# FIXME default should this default to fink or to macports?
|
||||
# What happens when more than one Lua version is installed?
|
||||
LUAPREFIX_macosx?=/opt/local
|
||||
@ -48,7 +49,7 @@ LDIR_macosx?=share/lua/$(LUAV)
|
||||
# /usr/local/include/lua$(LUAV)
|
||||
# where lua headers are found for linux builds
|
||||
LUAINC_linux_base?=/usr/include
|
||||
LUAINC_linux?=$(LUAINC_linux_base)/lua/$(LUAV)
|
||||
LUAINC_linux?=$(LUAINC_linux_base)/lua/$(LUAV) $(LUAINC_linux_base)/lua$(LUAV)
|
||||
LUAPREFIX_linux?=/usr/local
|
||||
CDIR_linux?=lib/lua/$(LUAV)
|
||||
LDIR_linux?=share/lua/$(LUAV)
|
||||
@ -57,7 +58,7 @@ LDIR_linux?=share/lua/$(LUAV)
|
||||
# /usr/local/include/lua$(LUAV)
|
||||
# where lua headers are found for freebsd builds
|
||||
LUAINC_freebsd_base?=/usr/local/include/
|
||||
LUAINC_freebsd?=$(LUAINC_freebsd_base)/lua$(LUAV)
|
||||
LUAINC_freebsd?=$(LUAINC_freebsd_base)/lua/$(LUAV) $(LUAINC_freebsd_base)/lua$(LUAV)
|
||||
LUAPREFIX_freebsd?=/usr/local/
|
||||
CDIR_freebsd?=lib/lua/$(LUAV)
|
||||
LDIR_freebsd?=share/lua/$(LUAV)
|
||||
@ -66,7 +67,7 @@ LDIR_freebsd?=share/lua/$(LUAV)
|
||||
# LUAINC_mingw:
|
||||
# /opt/local/include
|
||||
LUAINC_mingw_base?=/usr/include
|
||||
LUAINC_mingw?=$(LUAINC_mingw_base)/lua/$(LUAV)
|
||||
LUAINC_mingw?=$(LUAINC_mingw_base)/lua/$(LUAV) $(LUAINC_mingw_base)/lua$(LUAV)
|
||||
LUALIB_mingw_base?=/usr/bin
|
||||
LUALIB_mingw?=$(LUALIB_mingw_base)/lua/$(LUAV)/lua$(subst .,,$(LUAV)).dll
|
||||
LUAPREFIX_mingw?=/usr
|
||||
@ -78,17 +79,28 @@ LDIR_mingw?=lua/$(LUAV)/lua
|
||||
# LUALIB_win32:
|
||||
# where lua headers and libraries are found for win32 builds
|
||||
LUAPREFIX_win32?=
|
||||
LUAINC_win32?=$(LUAPREFIX_win32)/include/lua/$(LUAV)
|
||||
LUAINC_win32?=$(LUAPREFIX_win32)/include/lua/$(LUAV) $(LUAPREFIX_win32)/include/lua$(LUAV)
|
||||
PLATFORM_win32?=Release
|
||||
CDIR_win32?=bin/lua/$(LUAV)/$(PLATFORM_win32)
|
||||
LDIR_win32?=bin/lua/$(LUAV)/$(PLATFORM_win32)/lua
|
||||
LUALIB_win32?=$(LUAPREFIX_win32)/lib/lua/$(LUAV)/$(PLATFORM_win32)
|
||||
LUALIBNAME_win32?=lua$(subst .,,$(LUAV)).lib
|
||||
LUALIBNAME_win32?=lua$(subst .,,$(LUAV)).lib
|
||||
|
||||
# LUAINC_win64:
|
||||
# LUALIB_win64:
|
||||
# where lua headers and libraries are found for win64 builds
|
||||
LUAPREFIX_win64?=
|
||||
LUAINC_win64?=$(LUAPREFIX_win64)/include/lua/$(LUAV) $(LUAPREFIX_win64)/include/lua$(LUAV)
|
||||
PLATFORM_win64?=x64/Release
|
||||
CDIR_win64?=bin/lua/$(LUAV)/$(PLATFORM_win64)
|
||||
LDIR_win64?=bin/lua/$(LUAV)/$(PLATFORM_win64)/lua
|
||||
LUALIB_win64?=$(LUAPREFIX_win64)/lib/lua/$(LUAV)/$(PLATFORM_win64)
|
||||
LUALIBNAME_win64?=lua$(subst .,,$(LUAV)).lib
|
||||
|
||||
|
||||
# LUAINC_solaris:
|
||||
LUAINC_solaris_base?=/usr/include
|
||||
LUAINC_solaris?=$(LUAINC_solaris_base)/lua/$(LUAV)
|
||||
LUAINC_solaris?=$(LUAINC_solaris_base)/lua/$(LUAV) $(LUAINC_solaris_base)/lua$(LUAV)
|
||||
LUAPREFIX_solaris?=/usr/local
|
||||
CDIR_solaris?=lib/lua/$(LUAV)
|
||||
LDIR_solaris?=share/lua/$(LUAV)
|
||||
@ -141,7 +153,7 @@ print:
|
||||
#------
|
||||
# Supported platforms
|
||||
#
|
||||
PLATS= macosx linux win32 mingw solaris
|
||||
PLATS= macosx linux win32 win64 mingw solaris
|
||||
|
||||
#------
|
||||
# Compiler and linker settings
|
||||
@ -149,14 +161,10 @@ PLATS= macosx linux win32 mingw solaris
|
||||
SO_macosx=so
|
||||
O_macosx=o
|
||||
CC_macosx=gcc
|
||||
DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN \
|
||||
-DLUASOCKET_API='__attribute__((visibility("default")))' \
|
||||
-DUNIX_API='__attribute__((visibility("default")))' \
|
||||
-DMIME_API='__attribute__((visibility("default")))'
|
||||
CFLAGS_macosx= -I$(LUAINC) $(DEF) -Wall -O2 -fno-common \
|
||||
-fvisibility=hidden
|
||||
LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o
|
||||
LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc
|
||||
DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN
|
||||
CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common
|
||||
LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o
|
||||
LD_macosx=gcc
|
||||
SOCKET_macosx=usocket.o
|
||||
|
||||
#------
|
||||
@ -165,13 +173,10 @@ SOCKET_macosx=usocket.o
|
||||
SO_linux=so
|
||||
O_linux=o
|
||||
CC_linux=gcc
|
||||
DEF_linux=-DLUASOCKET_$(DEBUG) \
|
||||
-DLUASOCKET_API='__attribute__((visibility("default")))' \
|
||||
-DUNIX_API='__attribute__((visibility("default")))' \
|
||||
-DMIME_API='__attribute__((visibility("default")))'
|
||||
CFLAGS_linux= -I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \
|
||||
-Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden
|
||||
LDFLAGS_linux=-O -shared -fpic -o
|
||||
DEF_linux=-DLUASOCKET_$(DEBUG)
|
||||
CFLAGS_linux=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
|
||||
-Wimplicit -O2 -ggdb3 -fpic
|
||||
LDFLAGS_linux=-O -shared -fpic -o
|
||||
LD_linux=gcc
|
||||
SOCKET_linux=usocket.o
|
||||
|
||||
@ -181,13 +186,10 @@ SOCKET_linux=usocket.o
|
||||
SO_freebsd=so
|
||||
O_freebsd=o
|
||||
CC_freebsd=gcc
|
||||
DEF_freebsd=-DLUASOCKET_$(DEBUG) \
|
||||
-DLUASOCKET_API='__attribute__((visibility("default")))' \
|
||||
-DUNIX_API='__attribute__((visibility("default")))' \
|
||||
-DMIME_API='__attribute__((visibility("default")))'
|
||||
CFLAGS_freebsd= -I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \
|
||||
-Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden
|
||||
LDFLAGS_freebsd=-O -shared -fpic -o
|
||||
DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN
|
||||
CFLAGS_freebsd=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
|
||||
-Wimplicit -O2 -ggdb3 -fpic
|
||||
LDFLAGS_freebsd=-O -shared -fpic -o
|
||||
LD_freebsd=gcc
|
||||
SOCKET_freebsd=usocket.o
|
||||
|
||||
@ -197,13 +199,10 @@ SOCKET_freebsd=usocket.o
|
||||
SO_solaris=so
|
||||
O_solaris=o
|
||||
CC_solaris=gcc
|
||||
DEF_solaris=-DLUASOCKET_$(DEBUG) \
|
||||
-DLUASOCKET_API='__attribute__((visibility("default")))' \
|
||||
-DUNIX_API='__attribute__((visibility("default")))' \
|
||||
-DMIME_API='__attribute__((visibility("default")))'
|
||||
CFLAGS_solaris=-I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \
|
||||
-Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden
|
||||
LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o
|
||||
DEF_solaris=-DLUASOCKET_$(DEBUG)
|
||||
CFLAGS_solaris=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
|
||||
-Wimplicit -O2 -ggdb3 -fpic
|
||||
LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o
|
||||
LD_solaris=gcc
|
||||
SOCKET_solaris=usocket.o
|
||||
|
||||
@ -213,12 +212,10 @@ SOCKET_solaris=usocket.o
|
||||
SO_mingw=dll
|
||||
O_mingw=o
|
||||
CC_mingw=gcc
|
||||
DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) \
|
||||
-DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \
|
||||
-DMIME_API='__declspec(dllexport)'
|
||||
CFLAGS_mingw= -I$(LUAINC) $(DEF) -Wall -O2 -fno-common \
|
||||
-fvisibility=hidden
|
||||
LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o
|
||||
DEF_mingw= -DLUASOCKET_$(DEBUG) \
|
||||
-DWINVER=0x0501
|
||||
CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common
|
||||
LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o
|
||||
LD_mingw=gcc
|
||||
SOCKET_mingw=wsocket.o
|
||||
|
||||
@ -230,19 +227,41 @@ SO_win32=dll
|
||||
O_win32=obj
|
||||
CC_win32=cl
|
||||
DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \
|
||||
//D "LUASOCKET_API=__declspec(dllexport)" //D "_CRT_SECURE_NO_WARNINGS" \
|
||||
//D "_WINDLL" //D "MIME_API=__declspec(dllexport)" \
|
||||
//D "LUASOCKET_$(DEBUG)"
|
||||
CFLAGS_win32=//I "$(LUAINC)" $(DEF) //O2 //Ot //MD //W3 //nologo
|
||||
//D "_CRT_SECURE_NO_WARNINGS" \
|
||||
//D "_WINDLL" \
|
||||
//D "LUASOCKET_$(DEBUG)"
|
||||
CFLAGS_win32=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo
|
||||
LDFLAGS_win32= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \
|
||||
//MANIFEST //MANIFESTFILE:"intermediate.manifest" \
|
||||
//MANIFESTUAC:"level='asInvoker' uiAccess='false'" \
|
||||
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" \
|
||||
//SUBSYSTEM:WINDOWS //OPT:REF //OPT:ICF //DYNAMICBASE:NO \
|
||||
//MACHINE:X86 /LIBPATH:"$(shell cmd //c echo $(LUALIB))" \
|
||||
//MACHINE:X86 /LIBPATH:"$(LUALIB)" \
|
||||
$(LUALIBNAME_win32) ws2_32.lib //OUT:
|
||||
|
||||
LD_win32=cl
|
||||
SOCKET_win32=wsocket.obj
|
||||
|
||||
#------
|
||||
# Compiler and linker settings
|
||||
# for Win64
|
||||
SO_win64=dll
|
||||
O_win64=obj
|
||||
CC_win64=cl
|
||||
DEF_win64= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \
|
||||
//D "_CRT_SECURE_NO_WARNINGS" \
|
||||
//D "_WINDLL" \
|
||||
//D "LUASOCKET_$(DEBUG)"
|
||||
CFLAGS_win64=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo
|
||||
LDFLAGS_win64= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \
|
||||
//MANIFEST //MANIFESTFILE:"intermediate.manifest" \
|
||||
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" \
|
||||
//SUBSYSTEM:WINDOWS //OPT:REF //OPT:ICF //DYNAMICBASE:NO \
|
||||
/LIBPATH:"$(LUALIB)" \
|
||||
$(LUALIBNAME_win64) ws2_32.lib //OUT:
|
||||
|
||||
LD_win64=cl
|
||||
SOCKET_win64=wsocket.obj
|
||||
|
||||
.SUFFIXES: .obj
|
||||
|
||||
.c.obj:
|
||||
@ -253,7 +272,7 @@ SOCKET_win32=wsocket.obj
|
||||
#
|
||||
SO=$(SO_$(PLAT))
|
||||
O=$(O_$(PLAT))
|
||||
SOCKET_V=3.0-rc1
|
||||
SOCKET_V=3.0.0
|
||||
MIME_V=1.0.3
|
||||
SOCKET_SO=socket-$(SOCKET_V).$(SO)
|
||||
MIME_SO=mime-$(MIME_V).$(SO)
|
||||
@ -317,6 +336,7 @@ UNIX_OBJS=\
|
||||
#
|
||||
SERIAL_OBJS=\
|
||||
buffer.$(O) \
|
||||
compat.$(O) \
|
||||
auxiliar.$(O) \
|
||||
options.$(O) \
|
||||
timeout.$(O) \
|
||||
@ -355,12 +375,15 @@ macosx:
|
||||
win32:
|
||||
$(MAKE) all PLAT=win32
|
||||
|
||||
win64:
|
||||
$(MAKE) all PLAT=win64
|
||||
|
||||
linux:
|
||||
$(MAKE) all-unix PLAT=linux
|
||||
|
||||
mingw:
|
||||
$(MAKE) all PLAT=mingw
|
||||
|
||||
|
||||
solaris:
|
||||
$(MAKE) all-unix PLAT=solaris
|
||||
|
||||
@ -386,7 +409,7 @@ $(UNIX_SO): $(UNIX_OBJS)
|
||||
$(SERIAL_SO): $(SERIAL_OBJS)
|
||||
$(LD) $(SERIAL_OBJS) $(LDFLAGS)$@
|
||||
|
||||
install:
|
||||
install:
|
||||
$(INSTALL_DIR) $(INSTALL_TOP_LDIR)
|
||||
$(INSTALL_DATA) $(TO_TOP_LDIR) $(INSTALL_TOP_LDIR)
|
||||
$(INSTALL_DIR) $(INSTALL_SOCKET_LDIR)
|
||||
|
13
src/mbox.lua
13
src/mbox.lua
@ -1,8 +1,8 @@
|
||||
local _M = {}
|
||||
|
||||
if module then
|
||||
mbox = _M
|
||||
end
|
||||
mbox = _M -- luacheck: ignore
|
||||
end
|
||||
|
||||
function _M.split_message(message_s)
|
||||
local message = {}
|
||||
@ -29,7 +29,7 @@ end
|
||||
function _M.parse_header(header_s)
|
||||
header_s = string.gsub(header_s, "\n[ ]+", " ")
|
||||
header_s = string.gsub(header_s, "\n+", "")
|
||||
local _, __, name, value = string.find(header_s, "([^%s:]-):%s*(.*)")
|
||||
local _, _, name, value = string.find(header_s, "([^%s:]-):%s*(.*)")
|
||||
return name, value
|
||||
end
|
||||
|
||||
@ -49,9 +49,9 @@ function _M.parse_headers(headers_s)
|
||||
end
|
||||
|
||||
function _M.parse_from(from)
|
||||
local _, __, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>")
|
||||
local _, _, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>")
|
||||
if not address then
|
||||
_, __, address = string.find(from, "%s*(.+)%s*")
|
||||
_, _, address = string.find(from, "%s*(.+)%s*")
|
||||
end
|
||||
name = name or ""
|
||||
address = address or ""
|
||||
@ -63,7 +63,8 @@ end
|
||||
function _M.split_mbox(mbox_s)
|
||||
local mbox = {}
|
||||
mbox_s = string.gsub(mbox_s, "\r\n", "\n") .."\n\nFrom \n"
|
||||
local nj, i, j = 1, 1, 1
|
||||
local nj, i
|
||||
local j = 1
|
||||
while 1 do
|
||||
i, nj = string.find(mbox_s, "\n\nFrom .-\n", j)
|
||||
if not i then break end
|
||||
|
164
src/mime.c
Normal file → Executable file
164
src/mime.c
Normal file → Executable file
@ -2,13 +2,10 @@
|
||||
* MIME support functions
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include "luasocket.h"
|
||||
#include "mime.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/*=========================================================================*\
|
||||
* Don't want to trust escape character constants
|
||||
@ -30,12 +27,12 @@ static int mime_global_eol(lua_State *L);
|
||||
static int mime_global_dot(lua_State *L);
|
||||
|
||||
static size_t dot(int c, size_t state, luaL_Buffer *buffer);
|
||||
static void b64setup(UC *base);
|
||||
/*static void b64setup(UC *base);*/
|
||||
static size_t b64encode(UC c, UC *input, size_t size, luaL_Buffer *buffer);
|
||||
static size_t b64pad(const UC *input, size_t size, luaL_Buffer *buffer);
|
||||
static size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer);
|
||||
|
||||
static void qpsetup(UC *class, UC *unbase);
|
||||
/*static void qpsetup(UC *class, UC *unbase);*/
|
||||
static void qpquote(UC c, luaL_Buffer *buffer);
|
||||
static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer);
|
||||
static size_t qpencode(UC c, UC *input, size_t size,
|
||||
@ -58,17 +55,111 @@ static luaL_Reg func[] = {
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Quoted-printable globals
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static UC qpclass[256];
|
||||
static UC qpbase[] = "0123456789ABCDEF";
|
||||
static UC qpunbase[256];
|
||||
enum {QP_PLAIN, QP_QUOTED, QP_CR, QP_IF_LAST};
|
||||
|
||||
static const UC qpclass[] = {
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_IF_LAST, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_CR, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_IF_LAST, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_QUOTED, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN,
|
||||
QP_PLAIN, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED,
|
||||
QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED
|
||||
};
|
||||
|
||||
static const UC qpbase[] = "0123456789ABCDEF";
|
||||
|
||||
static const UC qpunbase[] = {
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255,
|
||||
255, 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 10, 11, 12, 13, 14, 15, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255
|
||||
};
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Base64 globals
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static const UC b64base[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
static UC b64unbase[256];
|
||||
|
||||
static const UC b64unbase[] = {
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 0,
|
||||
255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255,
|
||||
255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
|
||||
51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255
|
||||
};
|
||||
|
||||
/*=========================================================================*\
|
||||
* Exported functions
|
||||
@ -76,7 +167,7 @@ static UC b64unbase[256];
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Initializes module
|
||||
\*-------------------------------------------------------------------------*/
|
||||
MIME_API int luaopen_mime_core(lua_State *L)
|
||||
LUASOCKET_API int luaopen_mime_core(lua_State *L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
luaL_setfuncs(L, func, 0);
|
||||
@ -85,8 +176,8 @@ MIME_API int luaopen_mime_core(lua_State *L)
|
||||
lua_pushstring(L, MIME_VERSION);
|
||||
lua_rawset(L, -3);
|
||||
/* initialize lookup tables */
|
||||
qpsetup(qpclass, qpunbase);
|
||||
b64setup(b64unbase);
|
||||
/*qpsetup(qpclass, qpunbase);*/
|
||||
/*b64setup(b64unbase);*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -142,6 +233,7 @@ static int mime_global_wrp(lua_State *L)
|
||||
return 2;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Fill base64 decode map.
|
||||
\*-------------------------------------------------------------------------*/
|
||||
@ -151,7 +243,14 @@ static void b64setup(UC *unbase)
|
||||
for (i = 0; i <= 255; i++) unbase[i] = (UC) 255;
|
||||
for (i = 0; i < 64; i++) unbase[b64base[i]] = (UC) i;
|
||||
unbase['='] = 0;
|
||||
|
||||
printf("static const UC b64unbase[] = {\n");
|
||||
for (int i = 0; i < 256; i++) {
|
||||
printf("%d, ", unbase[i]);
|
||||
}
|
||||
printf("\n}\n;");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Acumulates bytes in input buffer until 3 bytes are available.
|
||||
@ -345,12 +444,14 @@ static int mime_global_unb64(lua_State *L)
|
||||
* To encode one byte, we need to see the next two.
|
||||
* Worst case is when we see a space, and wonder if a CRLF is comming
|
||||
\*-------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Split quoted-printable characters into classes
|
||||
* Precompute reverse map for encoding
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static void qpsetup(UC *cl, UC *unbase)
|
||||
{
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 256; i++) cl[i] = QP_QUOTED;
|
||||
for (i = 33; i <= 60; i++) cl[i] = QP_PLAIN;
|
||||
@ -367,7 +468,37 @@ static void qpsetup(UC *cl, UC *unbase)
|
||||
unbase['c'] = 12; unbase['D'] = 13; unbase['d'] = 13;
|
||||
unbase['E'] = 14; unbase['e'] = 14; unbase['F'] = 15;
|
||||
unbase['f'] = 15;
|
||||
|
||||
printf("static UC qpclass[] = {");
|
||||
for (int i = 0; i < 256; i++) {
|
||||
if (i % 6 == 0) {
|
||||
printf("\n ");
|
||||
}
|
||||
switch(cl[i]) {
|
||||
case QP_QUOTED:
|
||||
printf("QP_QUOTED, ");
|
||||
break;
|
||||
case QP_PLAIN:
|
||||
printf("QP_PLAIN, ");
|
||||
break;
|
||||
case QP_CR:
|
||||
printf("QP_CR, ");
|
||||
break;
|
||||
case QP_IF_LAST:
|
||||
printf("QP_IF_LAST, ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("\n};\n");
|
||||
|
||||
printf("static const UC qpunbase[] = {");
|
||||
for (int i = 0; i < 256; i++) {
|
||||
int c = qpunbase[i];
|
||||
printf("%d, ", c);
|
||||
}
|
||||
printf("\";\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Output one character in form =XX
|
||||
@ -447,7 +578,6 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer)
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static int mime_global_qp(lua_State *L)
|
||||
{
|
||||
|
||||
size_t asize = 0, isize = 0;
|
||||
UC atom[3];
|
||||
const UC *input = (const UC *) luaL_optlstring(L, 1, NULL, &isize);
|
||||
@ -654,7 +784,7 @@ static int eolprocess(int c, int last, const char *marker,
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static int mime_global_eol(lua_State *L)
|
||||
{
|
||||
int ctx = luaL_checkinteger(L, 1);
|
||||
int ctx = (int) luaL_checkinteger(L, 1);
|
||||
size_t isize = 0;
|
||||
const char *input = luaL_optlstring(L, 2, NULL, &isize);
|
||||
const char *last = input + isize;
|
||||
|
11
src/mime.h
11
src/mime.h
@ -8,7 +8,7 @@
|
||||
* and formatting conforming to RFC 2045. It is used by mime.lua, which
|
||||
* provide a higher level interface to this functionality.
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Current MIME library version
|
||||
@ -17,13 +17,6 @@
|
||||
#define MIME_COPYRIGHT "Copyright (C) 2004-2013 Diego Nehab"
|
||||
#define MIME_AUTHORS "Diego Nehab"
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* This macro prefixes all exported API functions
|
||||
\*-------------------------------------------------------------------------*/
|
||||
#ifndef MIME_API
|
||||
#define MIME_API extern
|
||||
#endif
|
||||
|
||||
MIME_API int luaopen_mime_core(lua_State *L);
|
||||
LUASOCKET_API int luaopen_mime_core(lua_State *L);
|
||||
|
||||
#endif /* MIME_H */
|
||||
|
15
src/mime.lua
15
src/mime.lua
@ -10,8 +10,6 @@
|
||||
local base = _G
|
||||
local ltn12 = require("ltn12")
|
||||
local mime = require("mime.core")
|
||||
local io = require("io")
|
||||
local string = require("string")
|
||||
local _M = mime
|
||||
|
||||
-- encode, decode and wrap algorithm tables
|
||||
@ -19,7 +17,7 @@ local encodet, decodet, wrapt = {},{},{}
|
||||
|
||||
_M.encodet = encodet
|
||||
_M.decodet = decodet
|
||||
_M.wrapt = wrapt
|
||||
_M.wrapt = wrapt
|
||||
|
||||
-- creates a function that chooses a filter by name from a given table
|
||||
local function choose(table)
|
||||
@ -28,7 +26,7 @@ local function choose(table)
|
||||
name, opt1, opt2 = "default", name, opt1
|
||||
end
|
||||
local f = table[name or "nil"]
|
||||
if not f then
|
||||
if not f then
|
||||
base.error("unknown key (" .. base.tostring(name) .. ")", 3)
|
||||
else return f(opt1, opt2) end
|
||||
end
|
||||
@ -53,13 +51,6 @@ decodet['quoted-printable'] = function()
|
||||
return ltn12.filter.cycle(_M.unqp, "")
|
||||
end
|
||||
|
||||
local function format(chunk)
|
||||
if chunk then
|
||||
if chunk == "" then return "''"
|
||||
else return string.len(chunk) end
|
||||
else return "nil" end
|
||||
end
|
||||
|
||||
-- define the line-wrap filters
|
||||
wrapt['text'] = function(length)
|
||||
length = length or 76
|
||||
@ -87,4 +78,4 @@ function _M.stuff()
|
||||
return ltn12.filter.cycle(_M.dot, 2)
|
||||
end
|
||||
|
||||
return _M
|
||||
return _M
|
||||
|
144
src/options.c
144
src/options.c
@ -2,14 +2,11 @@
|
||||
* Common option interface
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "luasocket.h"
|
||||
#include "auxiliar.h"
|
||||
#include "options.h"
|
||||
#include "inet.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*=========================================================================*\
|
||||
* Internal functions prototypes
|
||||
@ -57,6 +54,7 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps)
|
||||
return opt->func(L, ps);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
/* enables reuse of local address */
|
||||
int opt_set_reuseaddr(lua_State *L, p_socket ps)
|
||||
{
|
||||
@ -68,6 +66,7 @@ int opt_get_reuseaddr(lua_State *L, p_socket ps)
|
||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
/* enables reuse of local port */
|
||||
int opt_set_reuseport(lua_State *L, p_socket ps)
|
||||
{
|
||||
@ -79,7 +78,8 @@ int opt_get_reuseport(lua_State *L, p_socket ps)
|
||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEPORT);
|
||||
}
|
||||
|
||||
/* disables the Naggle algorithm */
|
||||
/*------------------------------------------------------*/
|
||||
/* disables the Nagle algorithm */
|
||||
int opt_set_tcp_nodelay(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setboolean(L, ps, IPPROTO_TCP, TCP_NODELAY);
|
||||
@ -90,6 +90,52 @@ int opt_get_tcp_nodelay(lua_State *L, p_socket ps)
|
||||
return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
#ifdef TCP_KEEPIDLE
|
||||
|
||||
int opt_get_tcp_keepidle(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE);
|
||||
}
|
||||
|
||||
int opt_set_tcp_keepidle(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
#ifdef TCP_KEEPCNT
|
||||
|
||||
int opt_get_tcp_keepcnt(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPCNT);
|
||||
}
|
||||
|
||||
int opt_set_tcp_keepcnt(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPCNT);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
#ifdef TCP_KEEPINTVL
|
||||
|
||||
int opt_get_tcp_keepintvl(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL);
|
||||
}
|
||||
|
||||
int opt_set_tcp_keepintvl(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_keepalive(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE);
|
||||
@ -100,6 +146,7 @@ int opt_get_keepalive(lua_State *L, p_socket ps)
|
||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_dontroute(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE);
|
||||
@ -110,6 +157,7 @@ int opt_get_dontroute(lua_State *L, p_socket ps)
|
||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_DONTROUTE);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_broadcast(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setboolean(L, ps, SOL_SOCKET, SO_BROADCAST);
|
||||
@ -120,6 +168,54 @@ int opt_get_broadcast(lua_State *L, p_socket ps)
|
||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_BROADCAST);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_recv_buf_size(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, SOL_SOCKET, SO_RCVBUF);
|
||||
}
|
||||
|
||||
int opt_get_recv_buf_size(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_getint(L, ps, SOL_SOCKET, SO_RCVBUF);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_get_send_buf_size(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_getint(L, ps, SOL_SOCKET, SO_SNDBUF);
|
||||
}
|
||||
|
||||
int opt_set_send_buf_size(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, SOL_SOCKET, SO_SNDBUF);
|
||||
}
|
||||
|
||||
// /*------------------------------------------------------*/
|
||||
|
||||
#ifdef TCP_FASTOPEN
|
||||
int opt_set_tcp_fastopen(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, IPPROTO_TCP, TCP_FASTOPEN);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TCP_FASTOPEN_CONNECT
|
||||
int opt_set_tcp_fastopen_connect(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, IPPROTO_TCP, TCP_FASTOPEN_CONNECT);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
|
||||
#ifdef TCP_DEFER_ACCEPT
|
||||
int opt_set_tcp_defer_accept(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, IPPROTO_TCP, TCP_DEFER_ACCEPT);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);
|
||||
@ -130,6 +226,7 @@ int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps)
|
||||
return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
|
||||
@ -140,6 +237,7 @@ int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps)
|
||||
return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_ip_multicast_loop(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP);
|
||||
@ -150,6 +248,7 @@ int opt_get_ip_multicast_loop(lua_State *L, p_socket ps)
|
||||
return opt_getboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
|
||||
@ -160,6 +259,7 @@ int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps)
|
||||
return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_linger(lua_State *L, p_socket ps)
|
||||
{
|
||||
struct linger li; /* obj, name, table */
|
||||
@ -192,11 +292,13 @@ int opt_get_linger(lua_State *L, p_socket ps)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setint(L, ps, IPPROTO_IP, IP_MULTICAST_TTL);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_ip_multicast_if(lua_State *L, p_socket ps)
|
||||
{
|
||||
const char *address = luaL_checkstring(L, 3); /* obj, name, ip */
|
||||
@ -221,6 +323,7 @@ int opt_get_ip_multicast_if(lua_State *L, p_socket ps)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_ip_add_membership(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setmembership(L, ps, IPPROTO_IP, IP_ADD_MEMBERSHIP);
|
||||
@ -231,6 +334,7 @@ int opt_set_ip_drop_membersip(lua_State *L, p_socket ps)
|
||||
return opt_setmembership(L, ps, IPPROTO_IP, IP_DROP_MEMBERSHIP);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_set_ip6_add_membership(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP);
|
||||
@ -241,6 +345,7 @@ int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps)
|
||||
return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_get_ip6_v6only(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
|
||||
@ -251,6 +356,20 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps)
|
||||
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
int opt_get_error(lua_State *L, p_socket ps)
|
||||
{
|
||||
int val = 0;
|
||||
socklen_t len = sizeof(val);
|
||||
if (getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *) &val, &len) < 0) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, "getsockopt failed");
|
||||
return 2;
|
||||
}
|
||||
lua_pushstring(L, socket_strerror(val));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================================================*\
|
||||
* Auxiliar functions
|
||||
\*=========================================================================*/
|
||||
@ -337,19 +456,6 @@ static int opt_getboolean(lua_State *L, p_socket ps, int level, int name)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int opt_get_error(lua_State *L, p_socket ps)
|
||||
{
|
||||
int val = 0;
|
||||
socklen_t len = sizeof(val);
|
||||
if (getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *) &val, &len) < 0) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, "getsockopt failed");
|
||||
return 2;
|
||||
}
|
||||
lua_pushstring(L, socket_strerror(val));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int opt_setboolean(lua_State *L, p_socket ps, int level, int name)
|
||||
{
|
||||
int val = auxiliar_checkboolean(L, 3); /* obj, name, bool */
|
||||
|
127
src/options.h
127
src/options.h
@ -8,7 +8,7 @@
|
||||
* modules UDP and TCP.
|
||||
\*=========================================================================*/
|
||||
|
||||
#include "lua.h"
|
||||
#include "luasocket.h"
|
||||
#include "socket.h"
|
||||
|
||||
/* option registry */
|
||||
@ -18,45 +18,96 @@ typedef struct t_opt {
|
||||
} t_opt;
|
||||
typedef t_opt *p_opt;
|
||||
|
||||
/* supported options for setoption */
|
||||
int opt_set_dontroute(lua_State *L, p_socket ps);
|
||||
int opt_set_broadcast(lua_State *L, p_socket ps);
|
||||
int opt_set_tcp_nodelay(lua_State *L, p_socket ps);
|
||||
int opt_set_keepalive(lua_State *L, p_socket ps);
|
||||
int opt_set_linger(lua_State *L, p_socket ps);
|
||||
int opt_set_reuseaddr(lua_State *L, p_socket ps);
|
||||
int opt_set_reuseport(lua_State *L, p_socket ps);
|
||||
int opt_set_ip_multicast_if(lua_State *L, p_socket ps);
|
||||
int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps);
|
||||
int opt_set_ip_multicast_loop(lua_State *L, p_socket ps);
|
||||
int opt_set_ip_add_membership(lua_State *L, p_socket ps);
|
||||
int opt_set_ip_drop_membersip(lua_State *L, p_socket ps);
|
||||
int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps);
|
||||
int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps);
|
||||
int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps);
|
||||
int opt_set_ip6_add_membership(lua_State *L, p_socket ps);
|
||||
int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps);
|
||||
int opt_set_ip6_v6only(lua_State *L, p_socket ps);
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
/* supported options for getoption */
|
||||
int opt_get_dontroute(lua_State *L, p_socket ps);
|
||||
int opt_get_broadcast(lua_State *L, p_socket ps);
|
||||
int opt_get_reuseaddr(lua_State *L, p_socket ps);
|
||||
int opt_get_reuseport(lua_State *L, p_socket ps);
|
||||
int opt_get_tcp_nodelay(lua_State *L, p_socket ps);
|
||||
int opt_get_keepalive(lua_State *L, p_socket ps);
|
||||
int opt_get_linger(lua_State *L, p_socket ps);
|
||||
int opt_get_ip_multicast_loop(lua_State *L, p_socket ps);
|
||||
int opt_get_ip_multicast_if(lua_State *L, p_socket ps);
|
||||
int opt_get_error(lua_State *L, p_socket ps);
|
||||
int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps);
|
||||
int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps);
|
||||
int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps);
|
||||
int opt_get_ip6_v6only(lua_State *L, p_socket ps);
|
||||
int opt_get_reuseport(lua_State *L, p_socket ps);
|
||||
|
||||
/* invokes the appropriate option handler */
|
||||
int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps);
|
||||
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);
|
||||
|
||||
int opt_set_reuseport(lua_State *L, p_socket ps);
|
||||
int opt_get_reuseport(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_tcp_nodelay(lua_State *L, p_socket ps);
|
||||
int opt_get_tcp_nodelay(lua_State *L, p_socket ps);
|
||||
|
||||
#ifdef TCP_KEEPIDLE
|
||||
int opt_set_tcp_keepidle(lua_State *L, p_socket ps);
|
||||
int opt_get_tcp_keepidle(lua_State *L, p_socket ps);
|
||||
#endif
|
||||
|
||||
#ifdef TCP_KEEPCNT
|
||||
int opt_set_tcp_keepcnt(lua_State *L, p_socket ps);
|
||||
int opt_get_tcp_keepcnt(lua_State *L, p_socket ps);
|
||||
#endif
|
||||
|
||||
#ifdef TCP_KEEPINTVL
|
||||
int opt_set_tcp_keepintvl(lua_State *L, p_socket ps);
|
||||
int opt_get_tcp_keepintvl(lua_State *L, p_socket ps);
|
||||
#endif
|
||||
|
||||
#ifdef TCP_DEFER_ACCEPT
|
||||
int opt_set_tcp_defer_accept(lua_State *L, p_socket ps);
|
||||
#endif
|
||||
|
||||
int opt_set_keepalive(lua_State *L, p_socket ps);
|
||||
int opt_get_keepalive(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_dontroute(lua_State *L, p_socket ps);
|
||||
int opt_get_dontroute(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_broadcast(lua_State *L, p_socket ps);
|
||||
int opt_get_broadcast(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_recv_buf_size(lua_State *L, p_socket ps);
|
||||
int opt_get_recv_buf_size(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_send_buf_size(lua_State *L, p_socket ps);
|
||||
int opt_get_send_buf_size(lua_State *L, p_socket ps);
|
||||
|
||||
#ifdef TCP_FASTOPEN
|
||||
int opt_set_tcp_fastopen(lua_State *L, p_socket ps);
|
||||
#endif
|
||||
#ifdef TCP_FASTOPEN_CONNECT
|
||||
int opt_set_tcp_fastopen_connect(lua_State *L, p_socket ps);
|
||||
#endif
|
||||
|
||||
int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps);
|
||||
int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps);
|
||||
int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_ip_multicast_loop(lua_State *L, p_socket ps);
|
||||
int opt_get_ip_multicast_loop(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps);
|
||||
int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_linger(lua_State *L, p_socket ps);
|
||||
int opt_get_linger(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_ip_multicast_if(lua_State *L, p_socket ps);
|
||||
int opt_get_ip_multicast_if(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_ip_add_membership(lua_State *L, p_socket ps);
|
||||
int opt_set_ip_drop_membersip(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_ip6_add_membership(lua_State *L, p_socket ps);
|
||||
int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_ip6_v6only(lua_State *L, p_socket ps);
|
||||
int opt_get_ip6_v6only(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_get_error(lua_State *L, p_socket ps);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
12
src/select.c
12
src/select.c
@ -2,16 +2,14 @@
|
||||
* Select implementation
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "socket.h"
|
||||
#include "timeout.h"
|
||||
#include "select.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*=========================================================================*\
|
||||
* Internal function prototypes.
|
||||
\*=========================================================================*/
|
||||
@ -31,9 +29,6 @@ static luaL_Reg func[] = {
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/*=========================================================================*\
|
||||
* Exported functions
|
||||
\*=========================================================================*/
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Initializes module
|
||||
\*-------------------------------------------------------------------------*/
|
||||
@ -217,4 +212,3 @@ static void make_assoc(lua_State *L, int tab) {
|
||||
i = i+1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,14 @@
|
||||
* true if there is data ready for reading (required for buffered input).
|
||||
\*=========================================================================*/
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
int select_open(lua_State *L);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif /* SELECT_H */
|
||||
|
@ -2,15 +2,14 @@
|
||||
* Serial stream
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
#include "options.h"
|
||||
#include "unix.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
/*
|
||||
|
57
src/socket.h
Normal file → Executable file
57
src/socket.h
Normal file → Executable file
@ -16,8 +16,10 @@
|
||||
\*=========================================================================*/
|
||||
#ifdef _WIN32
|
||||
#include "wsocket.h"
|
||||
#define LUA_GAI_STRERROR gai_strerrorA
|
||||
#else
|
||||
#include "usocket.h"
|
||||
#define LUA_GAI_STRERROR gai_strerror
|
||||
#endif
|
||||
|
||||
/*=========================================================================*\
|
||||
@ -28,51 +30,46 @@
|
||||
\*=========================================================================*/
|
||||
#include "timeout.h"
|
||||
|
||||
/* we are lazy... */
|
||||
/* convenient shorthand */
|
||||
typedef struct sockaddr SA;
|
||||
|
||||
/*=========================================================================*\
|
||||
* Functions bellow implement a comfortable platform independent
|
||||
* interface to sockets
|
||||
\*=========================================================================*/
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
int socket_waitfd(p_socket ps, int sw, p_timeout tm);
|
||||
int socket_open(void);
|
||||
int socket_close(void);
|
||||
void socket_destroy(p_socket ps);
|
||||
void socket_shutdown(p_socket ps, int how);
|
||||
int socket_sendto(p_socket ps, const char *data, size_t count,
|
||||
size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm);
|
||||
int socket_recvfrom(p_socket ps, char *data, size_t count,
|
||||
size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm);
|
||||
|
||||
void socket_setnonblocking(p_socket ps);
|
||||
void socket_setblocking(p_socket ps);
|
||||
|
||||
int socket_waitfd(p_socket ps, int sw, p_timeout tm);
|
||||
int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds,
|
||||
p_timeout tm);
|
||||
|
||||
int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm);
|
||||
int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm);
|
||||
int socket_create(p_socket ps, int domain, int type, int protocol);
|
||||
int socket_bind(p_socket ps, SA *addr, socklen_t addr_len);
|
||||
int socket_listen(p_socket ps, int backlog);
|
||||
int socket_accept(p_socket ps, p_socket pa, SA *addr,
|
||||
socklen_t *addr_len, p_timeout tm);
|
||||
|
||||
const char *socket_hoststrerror(int err);
|
||||
const char *socket_gaistrerror(int err);
|
||||
const char *socket_strerror(int err);
|
||||
|
||||
/* these are perfect to use with the io abstraction module
|
||||
and the buffered input module */
|
||||
int socket_send(p_socket ps, const char *data, size_t count,
|
||||
size_t *sent, p_timeout tm);
|
||||
void socket_shutdown(p_socket ps, int how);
|
||||
int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm);
|
||||
int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *addr_len, p_timeout tm);
|
||||
int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm);
|
||||
int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm);
|
||||
int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm);
|
||||
int socket_write(p_socket ps, const char *data, size_t count,
|
||||
size_t *sent, p_timeout tm);
|
||||
int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm);
|
||||
int socket_write(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm);
|
||||
int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm);
|
||||
const char *socket_ioerror(p_socket ps, int err);
|
||||
|
||||
void socket_setblocking(p_socket ps);
|
||||
void socket_setnonblocking(p_socket ps);
|
||||
int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp);
|
||||
int socket_gethostbyname(const char *addr, struct hostent **hp);
|
||||
const char *socket_hoststrerror(int err);
|
||||
const char *socket_strerror(int err);
|
||||
const char *socket_ioerror(p_socket ps, int err);
|
||||
const char *socket_gaistrerror(int err);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif /* SOCKET_H */
|
||||
|
39
src/tcp.c
39
src/tcp.c
@ -2,11 +2,7 @@
|
||||
* TCP object
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
@ -14,6 +10,8 @@
|
||||
#include "options.h"
|
||||
#include "tcp.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*=========================================================================*\
|
||||
* Internal function prototypes
|
||||
\*=========================================================================*/
|
||||
@ -77,8 +75,19 @@ static t_opt optget[] = {
|
||||
{"reuseaddr", opt_get_reuseaddr},
|
||||
{"reuseport", opt_get_reuseport},
|
||||
{"tcp-nodelay", opt_get_tcp_nodelay},
|
||||
#ifdef TCP_KEEPIDLE
|
||||
{"tcp-keepidle", opt_get_tcp_keepidle},
|
||||
#endif
|
||||
#ifdef TCP_KEEPCNT
|
||||
{"tcp-keepcnt", opt_get_tcp_keepcnt},
|
||||
#endif
|
||||
#ifdef TCP_KEEPINTVL
|
||||
{"tcp-keepintvl", opt_get_tcp_keepintvl},
|
||||
#endif
|
||||
{"linger", opt_get_linger},
|
||||
{"error", opt_get_error},
|
||||
{"recv-buffer-size", opt_get_recv_buf_size},
|
||||
{"send-buffer-size", opt_get_send_buf_size},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -87,8 +96,28 @@ static t_opt optset[] = {
|
||||
{"reuseaddr", opt_set_reuseaddr},
|
||||
{"reuseport", opt_set_reuseport},
|
||||
{"tcp-nodelay", opt_set_tcp_nodelay},
|
||||
#ifdef TCP_KEEPIDLE
|
||||
{"tcp-keepidle", opt_set_tcp_keepidle},
|
||||
#endif
|
||||
#ifdef TCP_KEEPCNT
|
||||
{"tcp-keepcnt", opt_set_tcp_keepcnt},
|
||||
#endif
|
||||
#ifdef TCP_KEEPINTVL
|
||||
{"tcp-keepintvl", opt_set_tcp_keepintvl},
|
||||
#endif
|
||||
{"ipv6-v6only", opt_set_ip6_v6only},
|
||||
{"linger", opt_set_linger},
|
||||
{"recv-buffer-size", opt_set_recv_buf_size},
|
||||
{"send-buffer-size", opt_set_send_buf_size},
|
||||
#ifdef TCP_DEFER_ACCEPT
|
||||
{"tcp-defer-accept", opt_set_tcp_defer_accept},
|
||||
#endif
|
||||
#ifdef TCP_FASTOPEN
|
||||
{"tcp-fastopen", opt_set_tcp_fastopen},
|
||||
#endif
|
||||
#ifdef TCP_FASTOPEN_CONNECT
|
||||
{"tcp-fastopen-connect", opt_set_tcp_fastopen_connect},
|
||||
#endif
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
10
src/tcp.h
10
src/tcp.h
@ -14,7 +14,7 @@
|
||||
* tcp objects either connected to some address or returned by the accept
|
||||
* method of a server object.
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "timeout.h"
|
||||
@ -30,6 +30,14 @@ typedef struct t_tcp_ {
|
||||
|
||||
typedef t_tcp *p_tcp;
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
int tcp_open(lua_State *L);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif /* TCP_H */
|
||||
|
@ -2,17 +2,15 @@
|
||||
* Timeout management functions
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "timeout.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Timeout management functions
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
/* timeout control structure */
|
||||
typedef struct t_timeout_ {
|
||||
@ -14,16 +14,27 @@ typedef struct t_timeout_ {
|
||||
} t_timeout;
|
||||
typedef t_timeout *p_timeout;
|
||||
|
||||
int timeout_open(lua_State *L);
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
void timeout_init(p_timeout tm, double block, double total);
|
||||
double timeout_get(p_timeout tm);
|
||||
double timeout_getstart(p_timeout tm);
|
||||
double timeout_getretry(p_timeout tm);
|
||||
p_timeout timeout_markstart(p_timeout tm);
|
||||
double timeout_getstart(p_timeout tm);
|
||||
|
||||
double timeout_gettime(void);
|
||||
|
||||
int timeout_open(lua_State *L);
|
||||
|
||||
int timeout_meth_settimeout(lua_State *L, p_timeout tm);
|
||||
int timeout_meth_gettimeout(lua_State *L, p_timeout tm);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#define timeout_iszero(tm) ((tm)->block == 0.0)
|
||||
|
||||
#endif /* TIMEOUT_H */
|
||||
|
23
src/udp.c
Normal file → Executable file
23
src/udp.c
Normal file → Executable file
@ -2,12 +2,7 @@
|
||||
* UDP object
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
@ -15,6 +10,9 @@
|
||||
#include "options.h"
|
||||
#include "udp.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* min and max macros */
|
||||
#ifndef MIN
|
||||
#define MIN(x, y) ((x) < (y) ? x : y)
|
||||
@ -88,6 +86,8 @@ static t_opt optset[] = {
|
||||
{"ipv6-add-membership", opt_set_ip6_add_membership},
|
||||
{"ipv6-drop-membership", opt_set_ip6_drop_membersip},
|
||||
{"ipv6-v6only", opt_set_ip6_v6only},
|
||||
{"recv-buffer-size", opt_set_recv_buf_size},
|
||||
{"send-buffer-size", opt_set_send_buf_size},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -104,6 +104,8 @@ static t_opt optget[] = {
|
||||
{"ipv6-multicast-hops", opt_get_ip6_unicast_hops},
|
||||
{"ipv6-multicast-loop", opt_get_ip6_multicast_loop},
|
||||
{"ipv6-v6only", opt_get_ip6_v6only},
|
||||
{"recv-buffer-size", opt_get_recv_buf_size},
|
||||
{"send-buffer-size", opt_get_send_buf_size},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -182,11 +184,14 @@ static int meth_sendto(lua_State *L) {
|
||||
memset(&aihint, 0, sizeof(aihint));
|
||||
aihint.ai_family = udp->family;
|
||||
aihint.ai_socktype = SOCK_DGRAM;
|
||||
aihint.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
|
||||
aihint.ai_flags = AI_NUMERICHOST;
|
||||
#ifdef AI_NUMERICSERV
|
||||
aihint.ai_flags |= AI_NUMERICSERV;
|
||||
#endif
|
||||
err = getaddrinfo(ip, port, &aihint, &ai);
|
||||
if (err) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, gai_strerror(err));
|
||||
lua_pushstring(L, LUA_GAI_STRERROR(err));
|
||||
return 2;
|
||||
}
|
||||
|
||||
@ -285,7 +290,7 @@ static int meth_receivefrom(lua_State *L) {
|
||||
INET6_ADDRSTRLEN, portstr, 6, NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
if (err) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, gai_strerror(err));
|
||||
lua_pushstring(L, LUA_GAI_STRERROR(err));
|
||||
if (wanted > sizeof(buf)) free(dgram);
|
||||
return 2;
|
||||
}
|
||||
|
10
src/udp.h
10
src/udp.h
@ -12,7 +12,7 @@
|
||||
* with a call to the setpeername function. The same function can be used to
|
||||
* break the connection.
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "timeout.h"
|
||||
#include "socket.h"
|
||||
@ -26,6 +26,14 @@ typedef struct t_udp_ {
|
||||
} t_udp;
|
||||
typedef t_udp *p_udp;
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
int udp_open(lua_State *L);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif /* UDP_H */
|
||||
|
@ -2,8 +2,7 @@
|
||||
* Unix domain socket
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "unixstream.h"
|
||||
#include "unixdgram.h"
|
||||
@ -45,7 +44,7 @@ static int compat_socket_unix_call(lua_State *L)
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Initializes module
|
||||
\*-------------------------------------------------------------------------*/
|
||||
int luaopen_socket_unix(lua_State *L)
|
||||
LUASOCKET_API int luaopen_socket_unix(lua_State *L)
|
||||
{
|
||||
int i;
|
||||
lua_newtable(L);
|
||||
|
@ -7,16 +7,12 @@
|
||||
* This module is just an example of how to extend LuaSocket with a new
|
||||
* domain.
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "timeout.h"
|
||||
#include "socket.h"
|
||||
|
||||
#ifndef UNIX_API
|
||||
#define UNIX_API extern
|
||||
#endif
|
||||
|
||||
typedef struct t_unix_ {
|
||||
t_socket sock;
|
||||
t_io io;
|
||||
@ -25,6 +21,6 @@ typedef struct t_unix_ {
|
||||
} t_unix;
|
||||
typedef t_unix *p_unix;
|
||||
|
||||
UNIX_API int luaopen_socket_unix(lua_State *L);
|
||||
LUASOCKET_API int luaopen_socket_unix(lua_State *L);
|
||||
|
||||
#endif /* UNIX_H */
|
||||
|
@ -2,21 +2,27 @@
|
||||
* Unix domain socket dgram submodule
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
#include "options.h"
|
||||
#include "unix.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/un.h>
|
||||
|
||||
#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
|
||||
\*=========================================================================*/
|
||||
@ -261,20 +267,15 @@ static int meth_dirty(lua_State *L) {
|
||||
static const char *unixdgram_trybind(p_unix un, const char *path) {
|
||||
struct sockaddr_un local;
|
||||
size_t len = strlen(path);
|
||||
int err;
|
||||
if (len >= sizeof(local.sun_path)) return "path too long";
|
||||
memset(&local, 0, sizeof(local));
|
||||
strcpy(local.sun_path, path);
|
||||
local.sun_family = AF_UNIX;
|
||||
size_t addrlen = SUN_LEN(&local);
|
||||
#ifdef UNIX_HAS_SUN_LEN
|
||||
local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len)
|
||||
+ len + 1;
|
||||
err = socket_bind(&un->sock, (SA *) &local, local.sun_len);
|
||||
|
||||
#else
|
||||
err = socket_bind(&un->sock, (SA *) &local,
|
||||
sizeof(local.sun_family) + len);
|
||||
local.sun_len = addrlen + 1;
|
||||
#endif
|
||||
int err = socket_bind(&un->sock, (SA *) &local, addrlen);
|
||||
if (err != IO_DONE) socket_destroy(&un->sock);
|
||||
return socket_strerror(err);
|
||||
}
|
||||
@ -315,21 +316,17 @@ static int meth_getsockname(lua_State *L)
|
||||
static const char *unixdgram_tryconnect(p_unix un, const char *path)
|
||||
{
|
||||
struct sockaddr_un remote;
|
||||
int err;
|
||||
size_t len = strlen(path);
|
||||
if (len >= sizeof(remote.sun_path)) return "path too long";
|
||||
memset(&remote, 0, sizeof(remote));
|
||||
strcpy(remote.sun_path, path);
|
||||
remote.sun_family = AF_UNIX;
|
||||
timeout_markstart(&un->tm);
|
||||
size_t addrlen = SUN_LEN(&remote);
|
||||
#ifdef UNIX_HAS_SUN_LEN
|
||||
remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len)
|
||||
+ len + 1;
|
||||
err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm);
|
||||
#else
|
||||
err = socket_connect(&un->sock, (SA *) &remote,
|
||||
sizeof(remote.sun_family) + len, &un->tm);
|
||||
remote.sun_len = addrlen + 1;
|
||||
#endif
|
||||
int err = socket_connect(&un->sock, (SA *) &remote, addrlen, &un->tm);
|
||||
if (err != IO_DONE) socket_destroy(&un->sock);
|
||||
return socket_strerror(err);
|
||||
}
|
||||
|
@ -15,6 +15,14 @@
|
||||
|
||||
#include "unix.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
int unixdgram_open(lua_State *L);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif /* UNIXDGRAM_H */
|
||||
|
@ -2,16 +2,14 @@
|
||||
* Unix domain socket stream sub module
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "compat.h"
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
#include "options.h"
|
||||
#include "unixstream.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
/*=========================================================================*\
|
||||
|
@ -16,6 +16,14 @@
|
||||
\*=========================================================================*/
|
||||
#include "unix.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
int unixstream_open(lua_State *L);
|
||||
|
||||
#ifndef _WIN32
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif /* UNIXSTREAM_H */
|
||||
|
70
src/url.lua
70
src/url.lua
@ -76,6 +76,34 @@ function _M.unescape(s)
|
||||
end))
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Removes '..' and '.' components appropriately from a path.
|
||||
-- Input
|
||||
-- path
|
||||
-- Returns
|
||||
-- dot-normalized path
|
||||
local function remove_dot_components(path)
|
||||
local marker = string.char(1)
|
||||
repeat
|
||||
local was = path
|
||||
path = path:gsub('//', '/'..marker..'/', 1)
|
||||
until path == was
|
||||
repeat
|
||||
local was = path
|
||||
path = path:gsub('/%./', '/', 1)
|
||||
until path == was
|
||||
repeat
|
||||
local was = path
|
||||
path = path:gsub('[^/]+/%.%./([^/]+)', '%1', 1)
|
||||
until path == was
|
||||
path = path:gsub('[^/]+/%.%./*$', '')
|
||||
path = path:gsub('/%.%.$', '/')
|
||||
path = path:gsub('/%.$', '/')
|
||||
path = path:gsub('^/%.%./', '/')
|
||||
path = path:gsub(marker, '')
|
||||
return path
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Builds a path from a base path and a relative path
|
||||
-- Input
|
||||
@ -85,23 +113,12 @@ end
|
||||
-- corresponding absolute path
|
||||
-----------------------------------------------------------------------------
|
||||
local function absolute_path(base_path, relative_path)
|
||||
if string.sub(relative_path, 1, 1) == "/" then return relative_path end
|
||||
local path = string.gsub(base_path, "[^/]*$", "")
|
||||
path = path .. relative_path
|
||||
path = string.gsub(path, "([^/]*%./)", function (s)
|
||||
if s ~= "./" then return s else return "" end
|
||||
end)
|
||||
path = string.gsub(path, "/%.$", "/")
|
||||
local reduced
|
||||
while reduced ~= path do
|
||||
reduced = path
|
||||
path = string.gsub(reduced, "([^/]*/%.%./)", function (s)
|
||||
if s ~= "../../" then return "" else return s end
|
||||
end)
|
||||
end
|
||||
path = string.gsub(reduced, "([^/]*/%.%.)$", function (s)
|
||||
if s ~= "../.." then return "" else return s end
|
||||
end)
|
||||
if string.sub(relative_path, 1, 1) == "/" then
|
||||
return remove_dot_components(relative_path) end
|
||||
base_path = base_path:gsub("[^/]*$", "")
|
||||
if not base_path:find'/$' then base_path = base_path .. '/' end
|
||||
local path = base_path .. relative_path
|
||||
path = remove_dot_components(path)
|
||||
return path
|
||||
end
|
||||
|
||||
@ -162,9 +179,9 @@ function _M.parse(url, default)
|
||||
function(u) parsed.userinfo = u; return "" end)
|
||||
authority = string.gsub(authority, ":([^:%]]*)$",
|
||||
function(p) parsed.port = p; return "" end)
|
||||
if authority ~= "" then
|
||||
if authority ~= "" then
|
||||
-- IPv6?
|
||||
parsed.host = string.match(authority, "^%[(.+)%]$") or authority
|
||||
parsed.host = string.match(authority, "^%[(.+)%]$") or authority
|
||||
end
|
||||
local userinfo = parsed.userinfo
|
||||
if not userinfo then return parsed end
|
||||
@ -227,10 +244,14 @@ function _M.absolute(base_url, relative_url)
|
||||
else
|
||||
base_parsed = _M.parse(base_url)
|
||||
end
|
||||
local result
|
||||
local relative_parsed = _M.parse(relative_url)
|
||||
if not base_parsed then return relative_url
|
||||
elseif not relative_parsed then return base_url
|
||||
elseif relative_parsed.scheme then return relative_url
|
||||
if not base_parsed then
|
||||
result = relative_url
|
||||
elseif not relative_parsed then
|
||||
result = base_url
|
||||
elseif relative_parsed.scheme then
|
||||
result = relative_url
|
||||
else
|
||||
relative_parsed.scheme = base_parsed.scheme
|
||||
if not relative_parsed.authority then
|
||||
@ -243,13 +264,14 @@ function _M.absolute(base_url, relative_url)
|
||||
relative_parsed.query = base_parsed.query
|
||||
end
|
||||
end
|
||||
else
|
||||
else
|
||||
relative_parsed.path = absolute_path(base_parsed.path or "",
|
||||
relative_parsed.path)
|
||||
end
|
||||
end
|
||||
return _M.build(relative_parsed)
|
||||
result = _M.build(relative_parsed)
|
||||
end
|
||||
return remove_dot_components(result)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -6,12 +6,14 @@
|
||||
* The penalty of calling select to avoid busy-wait is only paid when
|
||||
* the I/O call fail in the first place.
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "socket.h"
|
||||
#include "pierror.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Wait for readable/writable/connected socket with timeout
|
||||
\*-------------------------------------------------------------------------*/
|
||||
@ -438,14 +440,15 @@ const char *socket_gaistrerror(int err) {
|
||||
case EAI_FAMILY: return PIE_FAMILY;
|
||||
case EAI_MEMORY: return PIE_MEMORY;
|
||||
case EAI_NONAME: return PIE_NONAME;
|
||||
#ifdef EAI_OVERFLOW
|
||||
case EAI_OVERFLOW: return PIE_OVERFLOW;
|
||||
#endif
|
||||
#ifdef EAI_PROTOCOL
|
||||
case EAI_PROTOCOL: return PIE_PROTOCOL;
|
||||
#endif
|
||||
case EAI_SERVICE: return PIE_SERVICE;
|
||||
case EAI_SOCKTYPE: return PIE_SOCKTYPE;
|
||||
case EAI_SYSTEM: return strerror(errno);
|
||||
default: return gai_strerror(err);
|
||||
default: return LUA_GAI_STRERROR(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
29
src/wsocket.c
Normal file → Executable file
29
src/wsocket.c
Normal file → Executable file
@ -5,6 +5,8 @@
|
||||
* The penalty of calling select to avoid busy-wait is only paid when
|
||||
* the I/O call fail in the first place.
|
||||
\*=========================================================================*/
|
||||
#include "luasocket.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "socket.h"
|
||||
@ -131,11 +133,11 @@ int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {
|
||||
/* we wait until something happens */
|
||||
err = socket_waitfd(ps, WAITFD_C, tm);
|
||||
if (err == IO_CLOSED) {
|
||||
int len = sizeof(err);
|
||||
int elen = sizeof(err);
|
||||
/* give windows time to set the error (yes, disgusting) */
|
||||
Sleep(10);
|
||||
/* find out why we failed */
|
||||
getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &len);
|
||||
getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &elen);
|
||||
/* we KNOW there was an error. if 'why' is 0, we will return
|
||||
* "unknown error", but it's not really our fault */
|
||||
return err > 0? err: IO_UNKNOWN;
|
||||
@ -358,7 +360,7 @@ const char *socket_ioerror(p_socket ps, int err) {
|
||||
static const char *wstrerror(int err) {
|
||||
switch (err) {
|
||||
case WSAEINTR: return "Interrupted function call";
|
||||
case WSAEACCES: return PIE_ACCESS; // "Permission denied";
|
||||
case WSAEACCES: return PIE_ACCESS; /* "Permission denied"; */
|
||||
case WSAEFAULT: return "Bad address";
|
||||
case WSAEINVAL: return "Invalid argument";
|
||||
case WSAEMFILE: return "Too many open files";
|
||||
@ -371,23 +373,23 @@ static const char *wstrerror(int err) {
|
||||
case WSAEPROTOTYPE: return "Protocol wrong type for socket";
|
||||
case WSAENOPROTOOPT: return "Bad protocol option";
|
||||
case WSAEPROTONOSUPPORT: return "Protocol not supported";
|
||||
case WSAESOCKTNOSUPPORT: return PIE_SOCKTYPE; // "Socket type not supported";
|
||||
case WSAESOCKTNOSUPPORT: return PIE_SOCKTYPE; /* "Socket type not supported"; */
|
||||
case WSAEOPNOTSUPP: return "Operation not supported";
|
||||
case WSAEPFNOSUPPORT: return "Protocol family not supported";
|
||||
case WSAEAFNOSUPPORT: return PIE_FAMILY; // "Address family not supported by protocol family";
|
||||
case WSAEADDRINUSE: return PIE_ADDRINUSE; // "Address already in use";
|
||||
case WSAEAFNOSUPPORT: return PIE_FAMILY; /* "Address family not supported by protocol family"; */
|
||||
case WSAEADDRINUSE: return PIE_ADDRINUSE; /* "Address already in use"; */
|
||||
case WSAEADDRNOTAVAIL: return "Cannot assign requested address";
|
||||
case WSAENETDOWN: return "Network is down";
|
||||
case WSAENETUNREACH: return "Network is unreachable";
|
||||
case WSAENETRESET: return "Network dropped connection on reset";
|
||||
case WSAECONNABORTED: return "Software caused connection abort";
|
||||
case WSAECONNRESET: return PIE_CONNRESET; // "Connection reset by peer";
|
||||
case WSAECONNRESET: return PIE_CONNRESET; /* "Connection reset by peer"; */
|
||||
case WSAENOBUFS: return "No buffer space available";
|
||||
case WSAEISCONN: return PIE_ISCONN; // "Socket is already connected";
|
||||
case WSAEISCONN: return PIE_ISCONN; /* "Socket is already connected"; */
|
||||
case WSAENOTCONN: return "Socket is not connected";
|
||||
case WSAESHUTDOWN: return "Cannot send after socket shutdown";
|
||||
case WSAETIMEDOUT: return PIE_TIMEDOUT; // "Connection timed out";
|
||||
case WSAECONNREFUSED: return PIE_CONNREFUSED; // "Connection refused";
|
||||
case WSAETIMEDOUT: return PIE_TIMEDOUT; /* "Connection timed out"; */
|
||||
case WSAECONNREFUSED: return PIE_CONNREFUSED; /* "Connection refused"; */
|
||||
case WSAEHOSTDOWN: return "Host is down";
|
||||
case WSAEHOSTUNREACH: return "No route to host";
|
||||
case WSAEPROCLIM: return "Too many processes";
|
||||
@ -396,9 +398,9 @@ static const char *wstrerror(int err) {
|
||||
case WSANOTINITIALISED:
|
||||
return "Successful WSAStartup not yet performed";
|
||||
case WSAEDISCON: return "Graceful shutdown in progress";
|
||||
case WSAHOST_NOT_FOUND: return PIE_HOST_NOT_FOUND; // "Host not found";
|
||||
case WSAHOST_NOT_FOUND: return PIE_HOST_NOT_FOUND; /* "Host not found"; */
|
||||
case WSATRY_AGAIN: return "Nonauthoritative host not found";
|
||||
case WSANO_RECOVERY: return PIE_FAIL; // "Nonrecoverable name lookup error";
|
||||
case WSANO_RECOVERY: return PIE_FAIL; /* "Nonrecoverable name lookup error"; */
|
||||
case WSANO_DATA: return "Valid name, no data record of requested type";
|
||||
default: return "Unknown error";
|
||||
}
|
||||
@ -427,7 +429,6 @@ const char *socket_gaistrerror(int err) {
|
||||
#ifdef EAI_SYSTEM
|
||||
case EAI_SYSTEM: return strerror(errno);
|
||||
#endif
|
||||
default: return gai_strerror(err);
|
||||
default: return LUA_GAI_STRERROR(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ ulimit -n
|
||||
You'll probably need to be root to do this.
|
||||
]]
|
||||
|
||||
require "socket"
|
||||
socket = require "socket"
|
||||
|
||||
host = arg[1] or "google.com"
|
||||
port = arg[2] or 80
|
||||
|
@ -38,7 +38,7 @@ local function named(f, name)
|
||||
end
|
||||
|
||||
--------------------------------
|
||||
local function split(size)
|
||||
local function split(size)
|
||||
local buffer = ""
|
||||
local last_out = ""
|
||||
local last_in = ""
|
||||
@ -50,12 +50,12 @@ local function split(size)
|
||||
return last_out
|
||||
end
|
||||
return function(chunk, done)
|
||||
if done then
|
||||
return not last_in and not last_out
|
||||
if done then
|
||||
return not last_in and not last_out
|
||||
end
|
||||
-- check if argument is consistent with state
|
||||
if not chunk then
|
||||
if last_in and last_in ~= "" and last_out ~= "" then
|
||||
if last_in and last_in ~= "" and last_out ~= "" then
|
||||
error("nil chunk following data chunk", 2)
|
||||
end
|
||||
if not last_out then error("extra nil chunk", 2) end
|
||||
@ -67,8 +67,8 @@ local function split(size)
|
||||
return output(chunk)
|
||||
else
|
||||
if not last_in then error("data chunk following nil chunk", 2) end
|
||||
if last_in ~= "" and last_out ~= "" then
|
||||
error("data chunk following data chunk", 2)
|
||||
if last_in ~= "" and last_out ~= "" then
|
||||
error("data chunk following data chunk", 2)
|
||||
end
|
||||
buffer = chunk
|
||||
return output(chunk)
|
||||
@ -85,7 +85,7 @@ local function format(chunk)
|
||||
end
|
||||
|
||||
--------------------------------
|
||||
local function merge(size)
|
||||
local function merge(size)
|
||||
local buffer = ""
|
||||
local last_out = ""
|
||||
local last_in = ""
|
||||
@ -102,12 +102,12 @@ local function merge(size)
|
||||
return last_out
|
||||
end
|
||||
return function(chunk, done)
|
||||
if done then
|
||||
return not last_in and not last_out
|
||||
if done then
|
||||
return not last_in and not last_out
|
||||
end
|
||||
-- check if argument is consistent with state
|
||||
if not chunk then
|
||||
if last_in and last_in ~= "" and last_out ~= "" then
|
||||
if last_in and last_in ~= "" and last_out ~= "" then
|
||||
error("nil chunk following data chunk", 2)
|
||||
end
|
||||
if not last_out then error("extra nil chunk", 2) end
|
||||
@ -119,8 +119,8 @@ local function merge(size)
|
||||
return output(chunk)
|
||||
else
|
||||
if not last_in then error("data chunk following nil chunk", 2) end
|
||||
if last_in ~= "" and last_out ~= "" then
|
||||
error("data chunk following data chunk", 2)
|
||||
if last_in ~= "" and last_out ~= "" then
|
||||
error("data chunk following data chunk", 2)
|
||||
end
|
||||
buffer = buffer .. chunk
|
||||
return output(chunk)
|
||||
|
@ -15,27 +15,27 @@ local eb64test = "b64test.bin2"
|
||||
local db64test = "b64test.bin3"
|
||||
|
||||
|
||||
-- from Machado de Assis, "A M<>o e a Rosa"
|
||||
-- from Machado de Assis, "A M<>o e a Rosa"
|
||||
local mao = [[
|
||||
Cursavam estes dois mo<6D>os a academia de S. Paulo, estando
|
||||
Lu<4C>s Alves no quarto ano e Est<73>v<EFBFBD>o no terceiro.
|
||||
Conheceram-se na academia, e ficaram amigos <20>ntimos, tanto
|
||||
quanto podiam s<>-lo dois esp<73>ritos diferentes, ou talvez por
|
||||
isso mesmo que o eram. Est<73>v<EFBFBD>o, dotado de extrema
|
||||
sensibilidade, e n<>o menor fraqueza de <20>nimo, afetuoso e
|
||||
bom, n<>o daquela bondade varonil, que <20> apan<61>gio de uma alma
|
||||
forte, mas dessa outra bondade mole e de cera, que vai <20>
|
||||
merc<72> de todas as circunst<73>ncias, tinha, al<61>m de tudo isso,
|
||||
o infort<72>nio de trazer ainda sobre o nariz os <20>culos
|
||||
cor-de-rosa de suas virginais ilus<75>es. Lu<4C>s Alves via bem
|
||||
com os olhos da cara. N<>o era mau rapaz, mas tinha o seu
|
||||
gr<67>o de ego<67>smo, e se n<>o era incapaz de afei<65><69>es, sabia
|
||||
reg<65>-las, moder<65>-las, e sobretudo gui<75>-las ao seu pr<70>prio
|
||||
Cursavam estes dois mo<6D>os a academia de S. Paulo, estando
|
||||
Lu<4C>s Alves no quarto ano e Est<73>v<EFBFBD>o no terceiro.
|
||||
Conheceram-se na academia, e ficaram amigos <20>ntimos, tanto
|
||||
quanto podiam s<>-lo dois esp<73>ritos diferentes, ou talvez por
|
||||
isso mesmo que o eram. Est<73>v<EFBFBD>o, dotado de extrema
|
||||
sensibilidade, e n<>o menor fraqueza de <20>nimo, afetuoso e
|
||||
bom, n<>o daquela bondade varonil, que <20> apan<61>gio de uma alma
|
||||
forte, mas dessa outra bondade mole e de cera, que vai <20>
|
||||
merc<72> de todas as circunst<73>ncias, tinha, al<61>m de tudo isso,
|
||||
o infort<72>nio de trazer ainda sobre o nariz os <20>culos
|
||||
cor-de-rosa de suas virginais ilus<75>es. Lu<4C>s Alves via bem
|
||||
com os olhos da cara. N<>o era mau rapaz, mas tinha o seu
|
||||
gr<67>o de ego<67>smo, e se n<>o era incapaz de afei<65><69>es, sabia
|
||||
reg<65>-las, moder<65>-las, e sobretudo gui<75>-las ao seu pr<70>prio
|
||||
interesse. Entre estes dois homens travara-se amizade
|
||||
<20>ntima, nascida para um na simpatia, para outro no costume.
|
||||
<20>ntima, nascida para um na simpatia, para outro no costume.
|
||||
Eram eles os naturais confidentes um do outro, com a
|
||||
diferen<65>a que Lu<4C>s Alves dava menos do que recebia, e, ainda
|
||||
assim, nem tudo o que dava exprimia grande confian<61>a.
|
||||
diferen<65>a que Lu<4C>s Alves dava menos do que recebia, e, ainda
|
||||
assim, nem tudo o que dava exprimia grande confian<61>a.
|
||||
]]
|
||||
|
||||
local function random(handle, io_err)
|
||||
@ -44,8 +44,8 @@ local function random(handle, io_err)
|
||||
if not handle then error("source is empty!", 2) end
|
||||
local len = math.random(0, 1024)
|
||||
local chunk = handle:read(len)
|
||||
if not chunk then
|
||||
handle:close()
|
||||
if not chunk then
|
||||
handle:close()
|
||||
handle = nil
|
||||
end
|
||||
return chunk
|
||||
@ -62,7 +62,7 @@ local what = nil
|
||||
local function transform(input, output, filter)
|
||||
local source = random(io.open(input, "rb"))
|
||||
local sink = ltn12.sink.file(io.open(output, "wb"))
|
||||
if what then
|
||||
if what then
|
||||
sink = ltn12.sink.chain(filter, sink)
|
||||
else
|
||||
source = ltn12.source.chain(source, filter)
|
||||
@ -147,7 +147,7 @@ local function create_qptest()
|
||||
f:write(' ',string.char(32))
|
||||
end
|
||||
f:write("\r\n")
|
||||
|
||||
|
||||
f:close()
|
||||
end
|
||||
|
||||
@ -157,7 +157,7 @@ local function cleanup_qptest()
|
||||
os.remove(dqptest)
|
||||
end
|
||||
|
||||
-- create test file
|
||||
-- create test file
|
||||
local function create_b64test()
|
||||
local f = assert(io.open(b64test, "wb"))
|
||||
local t = {}
|
||||
|
@ -27,8 +27,8 @@ local total = function()
|
||||
end
|
||||
|
||||
local similar = function(s1, s2)
|
||||
return
|
||||
string.lower(string.gsub(s1, "%s", "")) ==
|
||||
return
|
||||
string.lower(string.gsub(s1, "%s", "")) ==
|
||||
string.lower(string.gsub(s2, "%s", ""))
|
||||
end
|
||||
|
||||
@ -40,9 +40,9 @@ end
|
||||
|
||||
local readfile = function(name)
|
||||
local f = io.open(name, "r")
|
||||
if not f then
|
||||
if not f then
|
||||
fail("unable to open file!")
|
||||
return nil
|
||||
return nil
|
||||
end
|
||||
local s = f:read("*a")
|
||||
f:close()
|
||||
@ -52,7 +52,7 @@ end
|
||||
local empty = function()
|
||||
for i,v in ipairs(files) do
|
||||
local f = io.open(v, "w")
|
||||
if not f then
|
||||
if not f then
|
||||
fail("unable to open file!")
|
||||
end
|
||||
f:close()
|
||||
@ -116,8 +116,8 @@ local wait = function(sentinel, n)
|
||||
while 1 do
|
||||
local mbox = parse(get())
|
||||
if n == #mbox then break end
|
||||
if socket.time() - sentinel.time > 50 then
|
||||
to = 1
|
||||
if socket.time() - sentinel.time > 50 then
|
||||
to = 1
|
||||
break
|
||||
end
|
||||
socket.sleep(1)
|
||||
@ -132,7 +132,7 @@ local stuffed_body = [[
|
||||
This message body needs to be
|
||||
stuffed because it has a dot
|
||||
.
|
||||
by itself on a line.
|
||||
by itself on a line.
|
||||
Otherwise the mailer would
|
||||
think that the dot
|
||||
.
|
||||
@ -219,7 +219,7 @@ else print("ok") end
|
||||
|
||||
io.write("testing invalid from: ")
|
||||
local ret, err = socket.smtp.mail{
|
||||
from = ' " " (( _ * ',
|
||||
from = ' " " (( _ * ',
|
||||
rcpt = rcpt,
|
||||
}
|
||||
if ret or not err then fail("wrong error message")
|
||||
@ -227,7 +227,7 @@ else print(err) end
|
||||
|
||||
io.write("testing no rcpt: ")
|
||||
local ret, err = socket.smtp.mail{
|
||||
from = from,
|
||||
from = from,
|
||||
}
|
||||
if ret or not err then fail("wrong error message")
|
||||
else print(err) end
|
||||
|
@ -1,19 +1,35 @@
|
||||
#!/usr/bin/env lua
|
||||
|
||||
require"socket"
|
||||
local socket = require"socket"
|
||||
|
||||
port = 8765
|
||||
|
||||
function pcalltest(msg, o, opt)
|
||||
local a = { pcall(o.getoption, o, opt) }
|
||||
if a[1] then
|
||||
print(msg, opt, unpack(a))
|
||||
else
|
||||
print(msg, opt, 'fail: ' .. a[2])
|
||||
end
|
||||
end
|
||||
|
||||
function options(o)
|
||||
print("options for", o)
|
||||
|
||||
for _, opt in ipairs{"keepalive", "reuseaddr", "tcp-nodelay"} do
|
||||
print("getoption", opt, o:getoption(opt))
|
||||
for _, opt in ipairs{
|
||||
"keepalive", "reuseaddr",
|
||||
"tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do
|
||||
pcalltest("getoption", o, opt)
|
||||
end
|
||||
|
||||
print("getoption", "linger",
|
||||
"on", o:getoption("linger").on,
|
||||
"timeout", o:getoption("linger").timeout)
|
||||
r = o:getoption'linger'
|
||||
if r then
|
||||
print("getoption", "linger",
|
||||
"on", r.on,
|
||||
"timeout", r.timeout)
|
||||
else
|
||||
print("getoption", "linger", "no result")
|
||||
end
|
||||
end
|
||||
|
||||
local m = socket.tcp()
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user