mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 04:28:20 +01:00
Merge pull request #270 from ewestbrook/functionvisibility
Tag functions explicitly for shared library visibility
This commit is contained in:
commit
c0fba03e4f
@ -1,8 +1,8 @@
|
|||||||
package = "LuaSocket"
|
package = "LuaSocket"
|
||||||
version = "scm-0"
|
version = "scm-0"
|
||||||
source = {
|
source = {
|
||||||
url = "https://github.com/diegonehab/luasocket/archive/master.zip",
|
url = "git://github.com/diegonehab/luasocket.git"
|
||||||
dir = "luasocket-master",
|
, branch="master"
|
||||||
}
|
}
|
||||||
description = {
|
description = {
|
||||||
summary = "Network support for the Lua language",
|
summary = "Network support for the Lua language",
|
||||||
@ -22,35 +22,37 @@ dependencies = {
|
|||||||
local function make_plat(plat)
|
local function make_plat(plat)
|
||||||
local defines = {
|
local defines = {
|
||||||
unix = {
|
unix = {
|
||||||
"LUASOCKET_DEBUG",
|
"LUASOCKET_DEBUG"
|
||||||
"LUASOCKET_API=__attribute__((visibility(\"default\")))",
|
|
||||||
"UNIX_API=__attribute__((visibility(\"default\")))",
|
|
||||||
"MIME_API=__attribute__((visibility(\"default\")))"
|
|
||||||
},
|
},
|
||||||
macosx = {
|
macosx = {
|
||||||
"LUASOCKET_DEBUG",
|
"LUASOCKET_DEBUG",
|
||||||
"UNIX_HAS_SUN_LEN",
|
"UNIX_HAS_SUN_LEN"
|
||||||
"LUASOCKET_API=__attribute__((visibility(\"default\")))",
|
|
||||||
"UNIX_API=__attribute__((visibility(\"default\")))",
|
|
||||||
"MIME_API=__attribute__((visibility(\"default\")))"
|
|
||||||
},
|
},
|
||||||
win32 = {
|
win32 = {
|
||||||
"LUASOCKET_DEBUG",
|
"LUASOCKET_DEBUG",
|
||||||
"NDEBUG",
|
"NDEBUG"
|
||||||
"LUASOCKET_API=__declspec(dllexport)",
|
|
||||||
"MIME_API=__declspec(dllexport)"
|
|
||||||
},
|
},
|
||||||
mingw32 = {
|
mingw32 = {
|
||||||
"LUASOCKET_DEBUG",
|
"LUASOCKET_DEBUG",
|
||||||
"LUASOCKET_INET_PTON",
|
"LUASOCKET_INET_PTON",
|
||||||
"WINVER=0x0501",
|
"WINVER=0x0501"
|
||||||
"LUASOCKET_API=__declspec(dllexport)",
|
|
||||||
"MIME_API=__declspec(dllexport)"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
local modules = {
|
local modules = {
|
||||||
["socket.core"] = {
|
["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" },
|
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],
|
defines = defines[plat],
|
||||||
incdir = "/src"
|
incdir = "/src"
|
||||||
},
|
},
|
||||||
@ -69,23 +71,44 @@ local function make_plat(plat)
|
|||||||
socket = "src/socket.lua",
|
socket = "src/socket.lua",
|
||||||
mime = "src/mime.lua"
|
mime = "src/mime.lua"
|
||||||
}
|
}
|
||||||
if plat == "unix" or plat == "macosx" or plat == "haiku" then
|
if plat == "unix"
|
||||||
|
or plat == "macosx"
|
||||||
|
or plat == "haiku"
|
||||||
|
then
|
||||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
|
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
|
||||||
if plat == "haiku" then
|
if plat == "haiku" then
|
||||||
modules["socket.core"].libraries = {"network"}
|
modules["socket.core"].libraries = {"network"}
|
||||||
end
|
end
|
||||||
modules["socket.unix"] = {
|
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", "src/unixdgram.c", "src/unixstream.c" },
|
sources = {
|
||||||
|
"src/buffer.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],
|
defines = defines[plat],
|
||||||
incdir = "/src"
|
incdir = "/src"
|
||||||
}
|
}
|
||||||
modules["socket.serial"] = {
|
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" },
|
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],
|
defines = defines[plat],
|
||||||
incdir = "/src"
|
incdir = "/src"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
if plat == "win32" or plat == "mingw32" then
|
if plat == "win32"
|
||||||
|
or plat == "mingw32"
|
||||||
|
then
|
||||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
|
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
|
||||||
modules["socket.core"].libraries = { "ws2_32" }
|
modules["socket.core"].libraries = { "ws2_32" }
|
||||||
end
|
end
|
||||||
@ -101,5 +124,9 @@ build = {
|
|||||||
win32 = make_plat("win32"),
|
win32 = make_plat("win32"),
|
||||||
mingw32 = make_plat("mingw32")
|
mingw32 = make_plat("mingw32")
|
||||||
},
|
},
|
||||||
copy_directories = { "doc", "samples", "etc", "test" }
|
copy_directories = {
|
||||||
|
"doc"
|
||||||
|
, "samples"
|
||||||
|
, "etc"
|
||||||
|
, "test" }
|
||||||
}
|
}
|
||||||
|
@ -22,35 +22,37 @@ dependencies = {
|
|||||||
local function make_plat(plat)
|
local function make_plat(plat)
|
||||||
local defines = {
|
local defines = {
|
||||||
unix = {
|
unix = {
|
||||||
"LUASOCKET_DEBUG",
|
"LUASOCKET_DEBUG"
|
||||||
"LUASOCKET_API=__attribute__((visibility(\"default\")))",
|
|
||||||
"UNIX_API=__attribute__((visibility(\"default\")))",
|
|
||||||
"MIME_API=__attribute__((visibility(\"default\")))"
|
|
||||||
},
|
},
|
||||||
macosx = {
|
macosx = {
|
||||||
"LUASOCKET_DEBUG",
|
"LUASOCKET_DEBUG",
|
||||||
"UNIX_HAS_SUN_LEN",
|
"UNIX_HAS_SUN_LEN"
|
||||||
"LUASOCKET_API=__attribute__((visibility(\"default\")))",
|
|
||||||
"UNIX_API=__attribute__((visibility(\"default\")))",
|
|
||||||
"MIME_API=__attribute__((visibility(\"default\")))"
|
|
||||||
},
|
},
|
||||||
win32 = {
|
win32 = {
|
||||||
"LUASOCKET_DEBUG",
|
"LUASOCKET_DEBUG",
|
||||||
"NDEBUG",
|
"NDEBUG"
|
||||||
"LUASOCKET_API=__declspec(dllexport)",
|
|
||||||
"MIME_API=__declspec(dllexport)"
|
|
||||||
},
|
},
|
||||||
mingw32 = {
|
mingw32 = {
|
||||||
"LUASOCKET_DEBUG",
|
"LUASOCKET_DEBUG",
|
||||||
"LUASOCKET_INET_PTON",
|
"LUASOCKET_INET_PTON",
|
||||||
"WINVER=0x0501",
|
"WINVER=0x0501"
|
||||||
"LUASOCKET_API=__declspec(dllexport)",
|
|
||||||
"MIME_API=__declspec(dllexport)"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
local modules = {
|
local modules = {
|
||||||
["socket.core"] = {
|
["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" },
|
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],
|
defines = defines[plat],
|
||||||
incdir = "/src"
|
incdir = "/src"
|
||||||
},
|
},
|
||||||
@ -69,23 +71,44 @@ local function make_plat(plat)
|
|||||||
socket = "src/socket.lua",
|
socket = "src/socket.lua",
|
||||||
mime = "src/mime.lua"
|
mime = "src/mime.lua"
|
||||||
}
|
}
|
||||||
if plat == "unix" or plat == "macosx" or plat == "haiku" then
|
if plat == "unix"
|
||||||
|
or plat == "macosx"
|
||||||
|
or plat == "haiku"
|
||||||
|
then
|
||||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
|
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
|
||||||
if plat == "haiku" then
|
if plat == "haiku" then
|
||||||
modules["socket.core"].libraries = {"network"}
|
modules["socket.core"].libraries = {"network"}
|
||||||
end
|
end
|
||||||
modules["socket.unix"] = {
|
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" },
|
sources = {
|
||||||
|
"src/buffer.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],
|
defines = defines[plat],
|
||||||
incdir = "/src"
|
incdir = "/src"
|
||||||
}
|
}
|
||||||
modules["socket.serial"] = {
|
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" },
|
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],
|
defines = defines[plat],
|
||||||
incdir = "/src"
|
incdir = "/src"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
if plat == "win32" or plat == "mingw32" then
|
if plat == "win32"
|
||||||
|
or plat == "mingw32"
|
||||||
|
then
|
||||||
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
|
modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
|
||||||
modules["socket.core"].libraries = { "ws2_32" }
|
modules["socket.core"].libraries = { "ws2_32" }
|
||||||
end
|
end
|
||||||
@ -101,5 +124,9 @@ build = {
|
|||||||
win32 = make_plat("win32"),
|
win32 = make_plat("win32"),
|
||||||
mingw32 = make_plat("mingw32")
|
mingw32 = make_plat("mingw32")
|
||||||
},
|
},
|
||||||
copy_directories = { "doc", "samples", "etc", "test" }
|
copy_directories = {
|
||||||
|
"doc"
|
||||||
|
, "samples"
|
||||||
|
, "etc"
|
||||||
|
, "test" }
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,18 @@
|
|||||||
* Auxiliar routines for class hierarchy manipulation
|
* Auxiliar routines for class hierarchy manipulation
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
|
#include "luasocket.h"
|
||||||
|
#include "auxiliar.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "auxiliar.h"
|
|
||||||
|
|
||||||
/*=========================================================================*\
|
/*=========================================================================*\
|
||||||
* Exported functions
|
* Exported functions
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes the module
|
* Initializes the module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int auxiliar_open(lua_State *L) {
|
LUASOCKET_PRIVATE int auxiliar_open(lua_State *L) {
|
||||||
(void) L;
|
(void) L;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -22,7 +22,7 @@ int auxiliar_open(lua_State *L) {
|
|||||||
* Creates a new class with given methods
|
* Creates a new class with given methods
|
||||||
* Methods whose names start with __ are passed directly to the metatable.
|
* Methods whose names start with __ are passed directly to the metatable.
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) {
|
LUASOCKET_PRIVATE void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) {
|
||||||
luaL_newmetatable(L, classname); /* mt */
|
luaL_newmetatable(L, classname); /* mt */
|
||||||
/* create __index table to place methods */
|
/* create __index table to place methods */
|
||||||
lua_pushstring(L, "__index"); /* mt,"__index" */
|
lua_pushstring(L, "__index"); /* mt,"__index" */
|
||||||
@ -45,7 +45,7 @@ void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Prints the value of a class in a nice way
|
* Prints the value of a class in a nice way
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int auxiliar_tostring(lua_State *L) {
|
LUASOCKET_PRIVATE int auxiliar_tostring(lua_State *L) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
if (!lua_getmetatable(L, 1)) goto error;
|
if (!lua_getmetatable(L, 1)) goto error;
|
||||||
lua_pushstring(L, "__index");
|
lua_pushstring(L, "__index");
|
||||||
@ -66,7 +66,7 @@ error:
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Insert class into group
|
* Insert class into group
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void auxiliar_add2group(lua_State *L, const char *classname, const char *groupname) {
|
LUASOCKET_PRIVATE void auxiliar_add2group(lua_State *L, const char *classname, const char *groupname) {
|
||||||
luaL_getmetatable(L, classname);
|
luaL_getmetatable(L, classname);
|
||||||
lua_pushstring(L, groupname);
|
lua_pushstring(L, groupname);
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
@ -77,7 +77,7 @@ void auxiliar_add2group(lua_State *L, const char *classname, const char *groupna
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Make sure argument is a boolean
|
* Make sure argument is a boolean
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int auxiliar_checkboolean(lua_State *L, int objidx) {
|
LUASOCKET_PRIVATE int auxiliar_checkboolean(lua_State *L, int objidx) {
|
||||||
if (!lua_isboolean(L, objidx))
|
if (!lua_isboolean(L, objidx))
|
||||||
auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN));
|
auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN));
|
||||||
return lua_toboolean(L, objidx);
|
return lua_toboolean(L, objidx);
|
||||||
@ -87,7 +87,7 @@ int auxiliar_checkboolean(lua_State *L, int objidx) {
|
|||||||
* Return userdata pointer if object belongs to a given class, abort with
|
* Return userdata pointer if object belongs to a given class, abort with
|
||||||
* error otherwise
|
* error otherwise
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) {
|
LUASOCKET_PRIVATE void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) {
|
||||||
void *data = auxiliar_getclassudata(L, classname, objidx);
|
void *data = auxiliar_getclassudata(L, classname, objidx);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
char msg[45];
|
char msg[45];
|
||||||
@ -101,7 +101,7 @@ void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) {
|
|||||||
* Return userdata pointer if object belongs to a given group, abort with
|
* Return userdata pointer if object belongs to a given group, abort with
|
||||||
* error otherwise
|
* error otherwise
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) {
|
LUASOCKET_PRIVATE void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) {
|
||||||
void *data = auxiliar_getgroupudata(L, groupname, objidx);
|
void *data = auxiliar_getgroupudata(L, groupname, objidx);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
char msg[45];
|
char msg[45];
|
||||||
@ -114,7 +114,7 @@ void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Set object class
|
* Set object class
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void auxiliar_setclass(lua_State *L, const char *classname, int objidx) {
|
LUASOCKET_PRIVATE void auxiliar_setclass(lua_State *L, const char *classname, int objidx) {
|
||||||
luaL_getmetatable(L, classname);
|
luaL_getmetatable(L, classname);
|
||||||
if (objidx < 0) objidx--;
|
if (objidx < 0) objidx--;
|
||||||
lua_setmetatable(L, objidx);
|
lua_setmetatable(L, objidx);
|
||||||
@ -124,7 +124,7 @@ void auxiliar_setclass(lua_State *L, const char *classname, int objidx) {
|
|||||||
* Get a userdata pointer if object belongs to a given group. Return NULL
|
* Get a userdata pointer if object belongs to a given group. Return NULL
|
||||||
* otherwise
|
* otherwise
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) {
|
LUASOCKET_PRIVATE void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) {
|
||||||
if (!lua_getmetatable(L, objidx))
|
if (!lua_getmetatable(L, objidx))
|
||||||
return NULL;
|
return NULL;
|
||||||
lua_pushstring(L, groupname);
|
lua_pushstring(L, groupname);
|
||||||
@ -142,7 +142,7 @@ void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) {
|
|||||||
* Get a userdata pointer if object belongs to a given class. Return NULL
|
* Get a userdata pointer if object belongs to a given class. Return NULL
|
||||||
* otherwise
|
* otherwise
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) {
|
LUASOCKET_PRIVATE void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) {
|
||||||
return luaL_testudata(L, objidx, classname);
|
return luaL_testudata(L, objidx, classname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) {
|
|||||||
* Throws error when argument does not have correct type.
|
* Throws error when argument does not have correct type.
|
||||||
* Used to be part of lauxlib in Lua 5.1, was dropped from 5.2.
|
* Used to be part of lauxlib in Lua 5.1, was dropped from 5.2.
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int auxiliar_typeerror (lua_State *L, int narg, const char *tname) {
|
LUASOCKET_PRIVATE int auxiliar_typeerror (lua_State *L, int narg, const char *tname) {
|
||||||
const char *msg = lua_pushfstring(L, "%s expected, got %s", tname,
|
const char *msg = lua_pushfstring(L, "%s expected, got %s", tname,
|
||||||
luaL_typename(L, narg));
|
luaL_typename(L, narg));
|
||||||
return luaL_argerror(L, narg, msg);
|
return luaL_argerror(L, narg, msg);
|
||||||
|
16
src/buffer.c
16
src/buffer.c
@ -2,6 +2,8 @@
|
|||||||
* Input/Output interface for Lua programs
|
* Input/Output interface for Lua programs
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
|
#include "luasocket.h"
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
@ -32,7 +34,7 @@ static int sendraw(p_buffer buf, const char *data, size_t count, size_t *sent);
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int buffer_open(lua_State *L) {
|
LUASOCKET_PRIVATE int buffer_open(lua_State *L) {
|
||||||
(void) L;
|
(void) L;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -40,7 +42,7 @@ int buffer_open(lua_State *L) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes C structure
|
* Initializes C structure
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void buffer_init(p_buffer buf, p_io io, p_timeout tm) {
|
LUASOCKET_PRIVATE void buffer_init(p_buffer buf, p_io io, p_timeout tm) {
|
||||||
buf->first = buf->last = 0;
|
buf->first = buf->last = 0;
|
||||||
buf->io = io;
|
buf->io = io;
|
||||||
buf->tm = tm;
|
buf->tm = tm;
|
||||||
@ -51,7 +53,7 @@ void buffer_init(p_buffer buf, p_io io, p_timeout tm) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* object:getstats() interface
|
* object:getstats() interface
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int buffer_meth_getstats(lua_State *L, p_buffer buf) {
|
LUASOCKET_PRIVATE int buffer_meth_getstats(lua_State *L, p_buffer buf) {
|
||||||
lua_pushnumber(L, (lua_Number) buf->received);
|
lua_pushnumber(L, (lua_Number) buf->received);
|
||||||
lua_pushnumber(L, (lua_Number) buf->sent);
|
lua_pushnumber(L, (lua_Number) buf->sent);
|
||||||
lua_pushnumber(L, timeout_gettime() - buf->birthday);
|
lua_pushnumber(L, timeout_gettime() - buf->birthday);
|
||||||
@ -61,7 +63,7 @@ int buffer_meth_getstats(lua_State *L, p_buffer buf) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* object:setstats() interface
|
* object:setstats() interface
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int buffer_meth_setstats(lua_State *L, p_buffer buf) {
|
LUASOCKET_PRIVATE int buffer_meth_setstats(lua_State *L, p_buffer buf) {
|
||||||
buf->received = (long) luaL_optnumber(L, 2, (lua_Number) buf->received);
|
buf->received = (long) luaL_optnumber(L, 2, (lua_Number) buf->received);
|
||||||
buf->sent = (long) luaL_optnumber(L, 3, (lua_Number) buf->sent);
|
buf->sent = (long) luaL_optnumber(L, 3, (lua_Number) buf->sent);
|
||||||
if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4);
|
if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4);
|
||||||
@ -72,7 +74,7 @@ int buffer_meth_setstats(lua_State *L, p_buffer buf) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* object:send() interface
|
* object:send() interface
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int buffer_meth_send(lua_State *L, p_buffer buf) {
|
LUASOCKET_PRIVATE int buffer_meth_send(lua_State *L, p_buffer buf) {
|
||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
int err = IO_DONE;
|
int err = IO_DONE;
|
||||||
size_t size = 0, sent = 0;
|
size_t size = 0, sent = 0;
|
||||||
@ -105,7 +107,7 @@ int buffer_meth_send(lua_State *L, p_buffer buf) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* object:receive() interface
|
* object:receive() interface
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
LUASOCKET_PRIVATE int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
||||||
int err = IO_DONE, top = lua_gettop(L);
|
int err = IO_DONE, top = lua_gettop(L);
|
||||||
luaL_Buffer b;
|
luaL_Buffer b;
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -154,7 +156,7 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Determines if there is any data in the read buffer
|
* Determines if there is any data in the read buffer
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int buffer_isempty(p_buffer buf) {
|
LUASOCKET_PRIVATE int buffer_isempty(p_buffer buf) {
|
||||||
return buf->first >= buf->last;
|
return buf->first >= buf->last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
|
#include "luasocket.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
|
||||||
#if LUA_VERSION_NUM==501
|
#if LUA_VERSION_NUM==501
|
||||||
/*
|
/*
|
||||||
** Adapted from Lua 5.2
|
** Adapted from Lua 5.2
|
||||||
*/
|
*/
|
||||||
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
|
LUASOCKET_PRIVATE void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
|
||||||
luaL_checkstack(L, nup+1, "too many upvalues");
|
luaL_checkstack(L, nup+1, "too many upvalues");
|
||||||
for (; l->name != NULL; l++) { /* fill the table with given functions */
|
for (; l->name != NULL; l++) { /* fill the table with given functions */
|
||||||
int i;
|
int i;
|
||||||
@ -20,7 +21,7 @@ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
|
|||||||
/*
|
/*
|
||||||
** Duplicated from Lua 5.2
|
** Duplicated from Lua 5.2
|
||||||
*/
|
*/
|
||||||
void *luaL_testudata (lua_State *L, int ud, const char *tname) {
|
LUASOCKET_PRIVATE void *luaL_testudata (lua_State *L, int ud, const char *tname) {
|
||||||
void *p = lua_touserdata(L, ud);
|
void *p = lua_touserdata(L, ud);
|
||||||
if (p != NULL) { /* value is a userdata? */
|
if (p != NULL) { /* value is a userdata? */
|
||||||
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
|
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
* Simple exception support
|
* Simple exception support
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
|
#include "luasocket.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
@ -124,7 +126,7 @@ static int global_protect(lua_State *L) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Init module
|
* Init module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int except_open(lua_State *L) {
|
LUASOCKET_PRIVATE int except_open(lua_State *L) {
|
||||||
lua_newtable(L); /* metatable for wrapped exceptions */
|
lua_newtable(L); /* metatable for wrapped exceptions */
|
||||||
lua_pushboolean(L, 0);
|
lua_pushboolean(L, 0);
|
||||||
lua_setfield(L, -2, "__metatable");
|
lua_setfield(L, -2, "__metatable");
|
||||||
|
26
src/inet.c
26
src/inet.c
@ -2,6 +2,8 @@
|
|||||||
* Internet domain functions
|
* Internet domain functions
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
|
#include "luasocket.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -38,7 +40,7 @@ static luaL_Reg func[] = {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int inet_open(lua_State *L)
|
LUASOCKET_PRIVATE int inet_open(lua_State *L)
|
||||||
{
|
{
|
||||||
lua_pushstring(L, "dns");
|
lua_pushstring(L, "dns");
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
@ -143,7 +145,7 @@ static int inet_global_toip(lua_State *L)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int inet_optfamily(lua_State* L, int narg, const char* def)
|
LUASOCKET_PRIVATE int inet_optfamily(lua_State* L, int narg, const char* def)
|
||||||
{
|
{
|
||||||
static const char* optname[] = { "unspec", "inet", "inet6", NULL };
|
static const char* optname[] = { "unspec", "inet", "inet6", NULL };
|
||||||
static int optvalue[] = { AF_UNSPEC, AF_INET, AF_INET6, 0 };
|
static int optvalue[] = { AF_UNSPEC, AF_INET, AF_INET6, 0 };
|
||||||
@ -151,7 +153,7 @@ int inet_optfamily(lua_State* L, int narg, const char* def)
|
|||||||
return optvalue[luaL_checkoption(L, narg, def, optname)];
|
return optvalue[luaL_checkoption(L, narg, def, optname)];
|
||||||
}
|
}
|
||||||
|
|
||||||
int inet_optsocktype(lua_State* L, int narg, const char* def)
|
LUASOCKET_PRIVATE int inet_optsocktype(lua_State* L, int narg, const char* def)
|
||||||
{
|
{
|
||||||
static const char* optname[] = { "stream", "dgram", NULL };
|
static const char* optname[] = { "stream", "dgram", NULL };
|
||||||
static int optvalue[] = { SOCK_STREAM, SOCK_DGRAM, 0 };
|
static int optvalue[] = { SOCK_STREAM, SOCK_DGRAM, 0 };
|
||||||
@ -242,7 +244,7 @@ static int inet_global_gethostname(lua_State *L)
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Retrieves socket peer name
|
* Retrieves socket peer name
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int inet_meth_getpeername(lua_State *L, p_socket ps, int family)
|
LUASOCKET_PRIVATE int inet_meth_getpeername(lua_State *L, p_socket ps, int family)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct sockaddr_storage peer;
|
struct sockaddr_storage peer;
|
||||||
@ -276,7 +278,7 @@ int inet_meth_getpeername(lua_State *L, p_socket ps, int family)
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Retrieves socket local name
|
* Retrieves socket local name
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
|
LUASOCKET_PRIVATE int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct sockaddr_storage peer;
|
struct sockaddr_storage peer;
|
||||||
@ -352,7 +354,7 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp)
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Tries to create a new inet socket
|
* Tries to create a new inet socket
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
const char *inet_trycreate(p_socket ps, int family, int type, int protocol) {
|
LUASOCKET_PRIVATE const char *inet_trycreate(p_socket ps, int family, int type, int protocol) {
|
||||||
const char *err = socket_strerror(socket_create(ps, family, type, protocol));
|
const char *err = socket_strerror(socket_create(ps, family, type, protocol));
|
||||||
if (err == NULL && family == AF_INET6) {
|
if (err == NULL && family == AF_INET6) {
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
@ -364,7 +366,7 @@ const char *inet_trycreate(p_socket ps, int family, int type, int protocol) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* "Disconnects" a DGRAM socket
|
* "Disconnects" a DGRAM socket
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm)
|
LUASOCKET_PRIVATE const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm)
|
||||||
{
|
{
|
||||||
switch (family) {
|
switch (family) {
|
||||||
case AF_INET: {
|
case AF_INET: {
|
||||||
@ -391,7 +393,7 @@ const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm)
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Tries to connect to remote address (address, port)
|
* Tries to connect to remote address (address, port)
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
const char *inet_tryconnect(p_socket ps, int *family, const char *address,
|
LUASOCKET_PRIVATE const char *inet_tryconnect(p_socket ps, int *family, const char *address,
|
||||||
const char *serv, p_timeout tm, struct addrinfo *connecthints)
|
const char *serv, p_timeout tm, struct addrinfo *connecthints)
|
||||||
{
|
{
|
||||||
struct addrinfo *iterator = NULL, *resolved = NULL;
|
struct addrinfo *iterator = NULL, *resolved = NULL;
|
||||||
@ -437,7 +439,7 @@ const char *inet_tryconnect(p_socket ps, int *family, const char *address,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Tries to accept a socket
|
* Tries to accept a socket
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
const char *inet_tryaccept(p_socket server, int family, p_socket client,
|
LUASOCKET_PRIVATE const char *inet_tryaccept(p_socket server, int family, p_socket client,
|
||||||
p_timeout tm) {
|
p_timeout tm) {
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
t_sockaddr_storage addr;
|
t_sockaddr_storage addr;
|
||||||
@ -453,7 +455,7 @@ const char *inet_tryaccept(p_socket server, int family, p_socket client,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Tries to bind socket to (address, port)
|
* Tries to bind socket to (address, port)
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
const char *inet_trybind(p_socket ps, int *family, const char *address,
|
LUASOCKET_PRIVATE const char *inet_trybind(p_socket ps, int *family, const char *address,
|
||||||
const char *serv, struct addrinfo *bindhints) {
|
const char *serv, struct addrinfo *bindhints) {
|
||||||
struct addrinfo *iterator = NULL, *resolved = NULL;
|
struct addrinfo *iterator = NULL, *resolved = NULL;
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
@ -497,7 +499,7 @@ const char *inet_trybind(p_socket ps, int *family, const char *address,
|
|||||||
* Some systems do not provide these so that we provide our own.
|
* Some systems do not provide these so that we provide our own.
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
#ifdef LUASOCKET_INET_ATON
|
#ifdef LUASOCKET_INET_ATON
|
||||||
int inet_aton(const char *cp, struct in_addr *inp)
|
LUASOCKET_PRIVATE int inet_aton(const char *cp, struct in_addr *inp)
|
||||||
{
|
{
|
||||||
unsigned int a = 0, b = 0, c = 0, d = 0;
|
unsigned int a = 0, b = 0, c = 0, d = 0;
|
||||||
int n = 0, r;
|
int n = 0, r;
|
||||||
@ -519,7 +521,7 @@ int inet_aton(const char *cp, struct in_addr *inp)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LUASOCKET_INET_PTON
|
#ifdef LUASOCKET_INET_PTON
|
||||||
int inet_pton(int af, const char *src, void *dst)
|
LUASOCKET_PRIVATE int inet_pton(int af, const char *src, void *dst)
|
||||||
{
|
{
|
||||||
struct addrinfo hints, *res;
|
struct addrinfo hints, *res;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
5
src/io.c
5
src/io.c
@ -2,6 +2,7 @@
|
|||||||
* Input/Output abstraction
|
* Input/Output abstraction
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
|
#include "luasocket.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|
||||||
/*=========================================================================*\
|
/*=========================================================================*\
|
||||||
@ -10,7 +11,7 @@
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes C structure
|
* Initializes C structure
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) {
|
LUASOCKET_PRIVATE void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) {
|
||||||
io->send = send;
|
io->send = send;
|
||||||
io->recv = recv;
|
io->recv = recv;
|
||||||
io->error = error;
|
io->error = error;
|
||||||
@ -20,7 +21,7 @@ void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* I/O error strings
|
* I/O error strings
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
const char *io_strerror(int err) {
|
LUASOCKET_PRIVATE const char *io_strerror(int err) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case IO_DONE: return NULL;
|
case IO_DONE: return NULL;
|
||||||
case IO_CLOSED: return "closed";
|
case IO_CLOSED: return "closed";
|
||||||
|
@ -18,7 +18,19 @@
|
|||||||
* This macro prefixes all exported API functions
|
* This macro prefixes all exported API functions
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
#ifndef LUASOCKET_API
|
#ifndef LUASOCKET_API
|
||||||
#define LUASOCKET_API extern
|
#ifdef _WIN32
|
||||||
|
#define LUASOCKET_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define LUASOCKET_API __attribute__ ((visibility ("default")))
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LUASOCKET_PRIVATE
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define LUASOCKET_PRIVATE
|
||||||
|
#else
|
||||||
|
#define LUASOCKET_PRIVATE __attribute__ ((visibility ("hidden")))
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
|
39
src/makefile
39
src/makefile
@ -149,12 +149,8 @@ PLATS= macosx linux win32 mingw solaris
|
|||||||
SO_macosx=so
|
SO_macosx=so
|
||||||
O_macosx=o
|
O_macosx=o
|
||||||
CC_macosx=gcc
|
CC_macosx=gcc
|
||||||
DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN \
|
DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN
|
||||||
-DLUASOCKET_API='__attribute__((visibility("default")))' \
|
CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common
|
||||||
-DUNIX_API='__attribute__((visibility("default")))' \
|
|
||||||
-DMIME_API='__attribute__((visibility("default")))'
|
|
||||||
CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common \
|
|
||||||
-fvisibility=hidden
|
|
||||||
LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o
|
LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o
|
||||||
LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc
|
LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc
|
||||||
SOCKET_macosx=usocket.o
|
SOCKET_macosx=usocket.o
|
||||||
@ -165,12 +161,9 @@ SOCKET_macosx=usocket.o
|
|||||||
SO_linux=so
|
SO_linux=so
|
||||||
O_linux=o
|
O_linux=o
|
||||||
CC_linux=gcc
|
CC_linux=gcc
|
||||||
DEF_linux=-DLUASOCKET_$(DEBUG) \
|
DEF_linux=-DLUASOCKET_$(DEBUG)
|
||||||
-DLUASOCKET_API='__attribute__((visibility("default")))' \
|
|
||||||
-DUNIX_API='__attribute__((visibility("default")))' \
|
|
||||||
-DMIME_API='__attribute__((visibility("default")))'
|
|
||||||
CFLAGS_linux=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
|
CFLAGS_linux=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
|
||||||
-Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden
|
-Wimplicit -O2 -ggdb3 -fpic
|
||||||
LDFLAGS_linux=-O -shared -fpic -o
|
LDFLAGS_linux=-O -shared -fpic -o
|
||||||
LD_linux=gcc
|
LD_linux=gcc
|
||||||
SOCKET_linux=usocket.o
|
SOCKET_linux=usocket.o
|
||||||
@ -181,12 +174,9 @@ SOCKET_linux=usocket.o
|
|||||||
SO_freebsd=so
|
SO_freebsd=so
|
||||||
O_freebsd=o
|
O_freebsd=o
|
||||||
CC_freebsd=gcc
|
CC_freebsd=gcc
|
||||||
DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN \
|
DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN
|
||||||
-DLUASOCKET_API='__attribute__((visibility("default")))' \
|
|
||||||
-DUNIX_API='__attribute__((visibility("default")))' \
|
|
||||||
-DMIME_API='__attribute__((visibility("default")))'
|
|
||||||
CFLAGS_freebsd=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
|
CFLAGS_freebsd=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
|
||||||
-Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden
|
-Wimplicit -O2 -ggdb3 -fpic
|
||||||
LDFLAGS_freebsd=-O -shared -fpic -o
|
LDFLAGS_freebsd=-O -shared -fpic -o
|
||||||
LD_freebsd=gcc
|
LD_freebsd=gcc
|
||||||
SOCKET_freebsd=usocket.o
|
SOCKET_freebsd=usocket.o
|
||||||
@ -197,12 +187,9 @@ SOCKET_freebsd=usocket.o
|
|||||||
SO_solaris=so
|
SO_solaris=so
|
||||||
O_solaris=o
|
O_solaris=o
|
||||||
CC_solaris=gcc
|
CC_solaris=gcc
|
||||||
DEF_solaris=-DLUASOCKET_$(DEBUG) \
|
DEF_solaris=-DLUASOCKET_$(DEBUG)
|
||||||
-DLUASOCKET_API='__attribute__((visibility("default")))' \
|
|
||||||
-DUNIX_API='__attribute__((visibility("default")))' \
|
|
||||||
-DMIME_API='__attribute__((visibility("default")))'
|
|
||||||
CFLAGS_solaris=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
|
CFLAGS_solaris=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
|
||||||
-Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden
|
-Wimplicit -O2 -ggdb3 -fpic
|
||||||
LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o
|
LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o
|
||||||
LD_solaris=gcc
|
LD_solaris=gcc
|
||||||
SOCKET_solaris=usocket.o
|
SOCKET_solaris=usocket.o
|
||||||
@ -214,10 +201,8 @@ SO_mingw=dll
|
|||||||
O_mingw=o
|
O_mingw=o
|
||||||
CC_mingw=gcc
|
CC_mingw=gcc
|
||||||
DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) \
|
DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) \
|
||||||
-DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \
|
-DWINVER=0x0501
|
||||||
-DMIME_API='__declspec(dllexport)'
|
CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common
|
||||||
CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common \
|
|
||||||
-fvisibility=hidden
|
|
||||||
LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o
|
LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o
|
||||||
LD_mingw=gcc
|
LD_mingw=gcc
|
||||||
SOCKET_mingw=wsocket.o
|
SOCKET_mingw=wsocket.o
|
||||||
@ -230,8 +215,8 @@ SO_win32=dll
|
|||||||
O_win32=obj
|
O_win32=obj
|
||||||
CC_win32=cl
|
CC_win32=cl
|
||||||
DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \
|
DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \
|
||||||
//D "LUASOCKET_API=__declspec(dllexport)" //D "_CRT_SECURE_NO_WARNINGS" \
|
//D "_CRT_SECURE_NO_WARNINGS" \
|
||||||
//D "_WINDLL" //D "MIME_API=__declspec(dllexport)" \
|
//D "_WINDLL" \
|
||||||
//D "LUASOCKET_$(DEBUG)"
|
//D "LUASOCKET_$(DEBUG)"
|
||||||
CFLAGS_win32=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo
|
CFLAGS_win32=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo
|
||||||
LDFLAGS_win32= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \
|
LDFLAGS_win32= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \
|
||||||
|
@ -76,7 +76,7 @@ static UC b64unbase[256];
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
MIME_API int luaopen_mime_core(lua_State *L)
|
LUASOCKET_API int luaopen_mime_core(lua_State *L)
|
||||||
{
|
{
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
luaL_setfuncs(L, func, 0);
|
luaL_setfuncs(L, func, 0);
|
||||||
|
10
src/mime.h
10
src/mime.h
@ -8,6 +8,7 @@
|
|||||||
* and formatting conforming to RFC 2045. It is used by mime.lua, which
|
* and formatting conforming to RFC 2045. It is used by mime.lua, which
|
||||||
* provide a higher level interface to this functionality.
|
* provide a higher level interface to this functionality.
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
|
#include "luasocket.h"
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
@ -17,13 +18,6 @@
|
|||||||
#define MIME_COPYRIGHT "Copyright (C) 2004-2013 Diego Nehab"
|
#define MIME_COPYRIGHT "Copyright (C) 2004-2013 Diego Nehab"
|
||||||
#define MIME_AUTHORS "Diego Nehab"
|
#define MIME_AUTHORS "Diego Nehab"
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
LUASOCKET_API int luaopen_mime_core(lua_State *L);
|
||||||
* This macro prefixes all exported API functions
|
|
||||||
\*-------------------------------------------------------------------------*/
|
|
||||||
#ifndef MIME_API
|
|
||||||
#define MIME_API extern
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MIME_API int luaopen_mime_core(lua_State *L);
|
|
||||||
|
|
||||||
#endif /* MIME_H */
|
#endif /* MIME_H */
|
||||||
|
@ -2,14 +2,12 @@
|
|||||||
* Common option interface
|
* Common option interface
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
#include <string.h>
|
#include "luasocket.h"
|
||||||
|
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
|
|
||||||
#include "auxiliar.h"
|
#include "auxiliar.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "inet.h"
|
#include "inet.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/*=========================================================================*\
|
/*=========================================================================*\
|
||||||
* Internal functions prototypes
|
* Internal functions prototypes
|
||||||
@ -31,7 +29,7 @@ static int opt_get(lua_State *L, p_socket ps, int level, int name,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Calls appropriate option handler
|
* Calls appropriate option handler
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps)
|
LUASOCKET_PRIVATE int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps)
|
||||||
{
|
{
|
||||||
const char *name = luaL_checkstring(L, 2); /* obj, name, ... */
|
const char *name = luaL_checkstring(L, 2); /* obj, name, ... */
|
||||||
while (opt->name && strcmp(name, opt->name))
|
while (opt->name && strcmp(name, opt->name))
|
||||||
@ -44,7 +42,7 @@ int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps)
|
|||||||
return opt->func(L, ps);
|
return opt->func(L, ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps)
|
LUASOCKET_PRIVATE int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps)
|
||||||
{
|
{
|
||||||
const char *name = luaL_checkstring(L, 2); /* obj, name, ... */
|
const char *name = luaL_checkstring(L, 2); /* obj, name, ... */
|
||||||
while (opt->name && strcmp(name, opt->name))
|
while (opt->name && strcmp(name, opt->name))
|
||||||
@ -58,165 +56,165 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* enables reuse of local address */
|
/* enables reuse of local address */
|
||||||
int opt_set_reuseaddr(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_reuseaddr(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEADDR);
|
return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_reuseaddr(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_reuseaddr(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR);
|
return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enables reuse of local port */
|
/* enables reuse of local port */
|
||||||
int opt_set_reuseport(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_reuseport(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEPORT);
|
return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEPORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_reuseport(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_reuseport(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEPORT);
|
return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEPORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* disables the Naggle algorithm */
|
/* disables the Naggle algorithm */
|
||||||
int opt_set_tcp_nodelay(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_tcp_nodelay(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setboolean(L, ps, IPPROTO_TCP, TCP_NODELAY);
|
return opt_setboolean(L, ps, IPPROTO_TCP, TCP_NODELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_tcp_nodelay(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_tcp_nodelay(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY);
|
return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TCP_KEEPIDLE
|
#ifdef TCP_KEEPIDLE
|
||||||
int opt_get_tcp_keepidle(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_tcp_keepidle(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE);
|
return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_tcp_keepidle(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_tcp_keepidle(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE);
|
return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TCP_KEEPCNT
|
#ifdef TCP_KEEPCNT
|
||||||
int opt_get_tcp_keepcnt(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_tcp_keepcnt(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPCNT);
|
return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPCNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_tcp_keepcnt(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_tcp_keepcnt(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPCNT);
|
return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPCNT);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TCP_KEEPINTVL
|
#ifdef TCP_KEEPINTVL
|
||||||
int opt_get_tcp_keepintvl(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_tcp_keepintvl(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL);
|
return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_tcp_keepintvl(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_tcp_keepintvl(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL);
|
return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int opt_set_keepalive(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_keepalive(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE);
|
return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_keepalive(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_keepalive(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE);
|
return opt_getboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_dontroute(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_dontroute(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE);
|
return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_dontroute(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_dontroute(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_DONTROUTE);
|
return opt_getboolean(L, ps, SOL_SOCKET, SO_DONTROUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_broadcast(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_broadcast(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setboolean(L, ps, SOL_SOCKET, SO_BROADCAST);
|
return opt_setboolean(L, ps, SOL_SOCKET, SO_BROADCAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_recv_buf_size(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_recv_buf_size(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setint(L, ps, SOL_SOCKET, SO_RCVBUF);
|
return opt_setint(L, ps, SOL_SOCKET, SO_RCVBUF);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_recv_buf_size(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_recv_buf_size(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getint(L, ps, SOL_SOCKET, SO_RCVBUF);
|
return opt_getint(L, ps, SOL_SOCKET, SO_RCVBUF);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_send_buf_size(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_send_buf_size(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getint(L, ps, SOL_SOCKET, SO_SNDBUF);
|
return opt_getint(L, ps, SOL_SOCKET, SO_SNDBUF);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_send_buf_size(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_send_buf_size(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setint(L, ps, SOL_SOCKET, SO_SNDBUF);
|
return opt_setint(L, ps, SOL_SOCKET, SO_SNDBUF);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_broadcast(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_broadcast(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getboolean(L, ps, SOL_SOCKET, SO_BROADCAST);
|
return opt_getboolean(L, ps, SOL_SOCKET, SO_BROADCAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);
|
return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);
|
return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
|
return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
|
return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip_multicast_loop(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip_multicast_loop(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP);
|
return opt_setboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_ip_multicast_loop(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_ip_multicast_loop(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP);
|
return opt_getboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
|
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
|
return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_linger(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_linger(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
struct linger li; /* obj, name, table */
|
struct linger li; /* obj, name, table */
|
||||||
if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE));
|
if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE));
|
||||||
@ -233,7 +231,7 @@ int opt_set_linger(lua_State *L, p_socket ps)
|
|||||||
return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li));
|
return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li));
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_linger(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_linger(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
struct linger li; /* obj, name */
|
struct linger li; /* obj, name */
|
||||||
int len = sizeof(li);
|
int len = sizeof(li);
|
||||||
@ -248,12 +246,12 @@ int opt_get_linger(lua_State *L, p_socket ps)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setint(L, ps, IPPROTO_IP, IP_MULTICAST_TTL);
|
return opt_setint(L, ps, IPPROTO_IP, IP_MULTICAST_TTL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip_multicast_if(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip_multicast_if(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
const char *address = luaL_checkstring(L, 3); /* obj, name, ip */
|
const char *address = luaL_checkstring(L, 3); /* obj, name, ip */
|
||||||
struct in_addr val;
|
struct in_addr val;
|
||||||
@ -264,7 +262,7 @@ int opt_set_ip_multicast_if(lua_State *L, p_socket ps)
|
|||||||
(char *) &val, sizeof(val));
|
(char *) &val, sizeof(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_ip_multicast_if(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_ip_multicast_if(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
struct in_addr val;
|
struct in_addr val;
|
||||||
socklen_t len = sizeof(val);
|
socklen_t len = sizeof(val);
|
||||||
@ -277,32 +275,32 @@ int opt_get_ip_multicast_if(lua_State *L, p_socket ps)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip_add_membership(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip_add_membership(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setmembership(L, ps, IPPROTO_IP, IP_ADD_MEMBERSHIP);
|
return opt_setmembership(L, ps, IPPROTO_IP, IP_ADD_MEMBERSHIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip_drop_membersip(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip_drop_membersip(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setmembership(L, ps, IPPROTO_IP, IP_DROP_MEMBERSHIP);
|
return opt_setmembership(L, ps, IPPROTO_IP, IP_DROP_MEMBERSHIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip6_add_membership(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip6_add_membership(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP);
|
return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP);
|
return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_ip6_v6only(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_ip6_v6only(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
|
return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_set_ip6_v6only(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_set_ip6_v6only(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
|
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
|
||||||
}
|
}
|
||||||
@ -393,7 +391,7 @@ static int opt_getboolean(lua_State *L, p_socket ps, int level, int name)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_get_error(lua_State *L, p_socket ps)
|
LUASOCKET_PRIVATE int opt_get_error(lua_State *L, p_socket ps)
|
||||||
{
|
{
|
||||||
int val = 0;
|
int val = 0;
|
||||||
socklen_t len = sizeof(val);
|
socklen_t len = sizeof(val);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* Select implementation
|
* Select implementation
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
#include <string.h>
|
#include "luasocket.h"
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
@ -12,6 +12,8 @@
|
|||||||
#include "timeout.h"
|
#include "timeout.h"
|
||||||
#include "select.h"
|
#include "select.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/*=========================================================================*\
|
/*=========================================================================*\
|
||||||
* Internal function prototypes.
|
* Internal function prototypes.
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
@ -37,7 +39,7 @@ static luaL_Reg func[] = {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int select_open(lua_State *L) {
|
LUASOCKET_PRIVATE int select_open(lua_State *L) {
|
||||||
lua_pushstring(L, "_SETSIZE");
|
lua_pushstring(L, "_SETSIZE");
|
||||||
lua_pushinteger(L, FD_SETSIZE);
|
lua_pushinteger(L, FD_SETSIZE);
|
||||||
lua_rawset(L, -3);
|
lua_rawset(L, -3);
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
* Serial stream
|
* Serial stream
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
|
#include "luasocket.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
@ -2,18 +2,21 @@
|
|||||||
* TCP object
|
* TCP object
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
#include <string.h>
|
#include "luasocket.h"
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
#include "compat.h"
|
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
#include "auxiliar.h"
|
#include "auxiliar.h"
|
||||||
|
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "inet.h"
|
#include "inet.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "tcp.h"
|
#include "tcp.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/*=========================================================================*\
|
/*=========================================================================*\
|
||||||
* Internal function prototypes
|
* Internal function prototypes
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
@ -126,7 +129,7 @@ static luaL_Reg func[] = {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int tcp_open(lua_State *L)
|
LUASOCKET_PRIVATE int tcp_open(lua_State *L)
|
||||||
{
|
{
|
||||||
/* create classes */
|
/* create classes */
|
||||||
auxiliar_newclass(L, "tcp{master}", tcp_methods);
|
auxiliar_newclass(L, "tcp{master}", tcp_methods);
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
* Timeout management functions
|
* Timeout management functions
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
#include <stdio.h>
|
#include "luasocket.h"
|
||||||
#include <limits.h>
|
|
||||||
#include <float.h>
|
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
@ -13,6 +11,10 @@
|
|||||||
#include "auxiliar.h"
|
#include "auxiliar.h"
|
||||||
#include "timeout.h"
|
#include "timeout.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
@ -46,7 +48,7 @@ static luaL_Reg func[] = {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initialize structure
|
* Initialize structure
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void timeout_init(p_timeout tm, double block, double total) {
|
LUASOCKET_PRIVATE void timeout_init(p_timeout tm, double block, double total) {
|
||||||
tm->block = block;
|
tm->block = block;
|
||||||
tm->total = total;
|
tm->total = total;
|
||||||
}
|
}
|
||||||
@ -59,7 +61,7 @@ void timeout_init(p_timeout tm, double block, double total) {
|
|||||||
* Returns
|
* Returns
|
||||||
* the number of ms left or -1 if there is no time limit
|
* the number of ms left or -1 if there is no time limit
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
double timeout_get(p_timeout tm) {
|
LUASOCKET_PRIVATE double timeout_get(p_timeout tm) {
|
||||||
if (tm->block < 0.0 && tm->total < 0.0) {
|
if (tm->block < 0.0 && tm->total < 0.0) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (tm->block < 0.0) {
|
} else if (tm->block < 0.0) {
|
||||||
@ -80,7 +82,7 @@ double timeout_get(p_timeout tm) {
|
|||||||
* Returns
|
* Returns
|
||||||
* start field of structure
|
* start field of structure
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
double timeout_getstart(p_timeout tm) {
|
LUASOCKET_PRIVATE double timeout_getstart(p_timeout tm) {
|
||||||
return tm->start;
|
return tm->start;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +94,7 @@ double timeout_getstart(p_timeout tm) {
|
|||||||
* Returns
|
* Returns
|
||||||
* the number of ms left or -1 if there is no time limit
|
* the number of ms left or -1 if there is no time limit
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
double timeout_getretry(p_timeout tm) {
|
LUASOCKET_PRIVATE double timeout_getretry(p_timeout tm) {
|
||||||
if (tm->block < 0.0 && tm->total < 0.0) {
|
if (tm->block < 0.0 && tm->total < 0.0) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (tm->block < 0.0) {
|
} else if (tm->block < 0.0) {
|
||||||
@ -112,7 +114,7 @@ double timeout_getretry(p_timeout tm) {
|
|||||||
* Input
|
* Input
|
||||||
* tm: timeout control structure
|
* tm: timeout control structure
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
p_timeout timeout_markstart(p_timeout tm) {
|
LUASOCKET_PRIVATE p_timeout timeout_markstart(p_timeout tm) {
|
||||||
tm->start = timeout_gettime();
|
tm->start = timeout_gettime();
|
||||||
return tm;
|
return tm;
|
||||||
}
|
}
|
||||||
@ -123,7 +125,7 @@ p_timeout timeout_markstart(p_timeout tm) {
|
|||||||
* time in s.
|
* time in s.
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
double timeout_gettime(void) {
|
LUASOCKET_PRIVATE double timeout_gettime(void) {
|
||||||
FILETIME ft;
|
FILETIME ft;
|
||||||
double t;
|
double t;
|
||||||
GetSystemTimeAsFileTime(&ft);
|
GetSystemTimeAsFileTime(&ft);
|
||||||
@ -133,7 +135,7 @@ double timeout_gettime(void) {
|
|||||||
return (t - 11644473600.0);
|
return (t - 11644473600.0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
double timeout_gettime(void) {
|
LUASOCKET_PRIVATE double timeout_gettime(void) {
|
||||||
struct timeval v;
|
struct timeval v;
|
||||||
gettimeofday(&v, (struct timezone *) NULL);
|
gettimeofday(&v, (struct timezone *) NULL);
|
||||||
/* Unix Epoch time (time since January 1, 1970 (UTC)) */
|
/* Unix Epoch time (time since January 1, 1970 (UTC)) */
|
||||||
@ -144,7 +146,7 @@ double timeout_gettime(void) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int timeout_open(lua_State *L) {
|
LUASOCKET_PRIVATE int timeout_open(lua_State *L) {
|
||||||
luaL_setfuncs(L, func, 0);
|
luaL_setfuncs(L, func, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -155,7 +157,7 @@ int timeout_open(lua_State *L) {
|
|||||||
* time: time out value in seconds
|
* time: time out value in seconds
|
||||||
* mode: "b" for block timeout, "t" for total timeout. (default: b)
|
* mode: "b" for block timeout, "t" for total timeout. (default: b)
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int timeout_meth_settimeout(lua_State *L, p_timeout tm) {
|
LUASOCKET_PRIVATE int timeout_meth_settimeout(lua_State *L, p_timeout tm) {
|
||||||
double t = luaL_optnumber(L, 2, -1);
|
double t = luaL_optnumber(L, 2, -1);
|
||||||
const char *mode = luaL_optstring(L, 3, "b");
|
const char *mode = luaL_optstring(L, 3, "b");
|
||||||
switch (*mode) {
|
switch (*mode) {
|
||||||
@ -177,7 +179,7 @@ int timeout_meth_settimeout(lua_State *L, p_timeout tm) {
|
|||||||
* Gets timeout values for IO operations
|
* Gets timeout values for IO operations
|
||||||
* Lua Output: block, total
|
* Lua Output: block, total
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int timeout_meth_gettimeout(lua_State *L, p_timeout tm) {
|
LUASOCKET_PRIVATE int timeout_meth_gettimeout(lua_State *L, p_timeout tm) {
|
||||||
lua_pushnumber(L, tm->block);
|
lua_pushnumber(L, tm->block);
|
||||||
lua_pushnumber(L, tm->total);
|
lua_pushnumber(L, tm->total);
|
||||||
return 2;
|
return 2;
|
||||||
@ -199,7 +201,7 @@ static int timeout_lua_gettime(lua_State *L)
|
|||||||
* Sleep for n seconds.
|
* Sleep for n seconds.
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int timeout_lua_sleep(lua_State *L)
|
LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L)
|
||||||
{
|
{
|
||||||
double n = luaL_checknumber(L, 1);
|
double n = luaL_checknumber(L, 1);
|
||||||
if (n < 0.0) n = 0.0;
|
if (n < 0.0) n = 0.0;
|
||||||
@ -209,7 +211,7 @@ int timeout_lua_sleep(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int timeout_lua_sleep(lua_State *L)
|
LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L)
|
||||||
{
|
{
|
||||||
double n = luaL_checknumber(L, 1);
|
double n = luaL_checknumber(L, 1);
|
||||||
struct timespec t, r;
|
struct timespec t, r;
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
* UDP object
|
* UDP object
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
#include <string.h>
|
#include "luasocket.h"
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
@ -15,6 +14,9 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "udp.h"
|
#include "udp.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* min and max macros */
|
/* min and max macros */
|
||||||
#ifndef MIN
|
#ifndef MIN
|
||||||
#define MIN(x, y) ((x) < (y) ? x : y)
|
#define MIN(x, y) ((x) < (y) ? x : y)
|
||||||
@ -122,7 +124,7 @@ static luaL_Reg func[] = {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int udp_open(lua_State *L) {
|
LUASOCKET_PRIVATE int udp_open(lua_State *L) {
|
||||||
/* create classes */
|
/* create classes */
|
||||||
auxiliar_newclass(L, "udp{connected}", udp_methods);
|
auxiliar_newclass(L, "udp{connected}", udp_methods);
|
||||||
auxiliar_newclass(L, "udp{unconnected}", udp_methods);
|
auxiliar_newclass(L, "udp{unconnected}", udp_methods);
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
* Unix domain socket
|
* Unix domain socket
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
|
#include "luasocket.h"
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ static int compat_socket_unix_call(lua_State *L)
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int luaopen_socket_unix(lua_State *L)
|
LUASOCKET_API int luaopen_socket_unix(lua_State *L)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
@ -7,16 +7,13 @@
|
|||||||
* This module is just an example of how to extend LuaSocket with a new
|
* This module is just an example of how to extend LuaSocket with a new
|
||||||
* domain.
|
* domain.
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
|
#include "luasocket.h"
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "timeout.h"
|
#include "timeout.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
#ifndef UNIX_API
|
|
||||||
#define UNIX_API extern
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct t_unix_ {
|
typedef struct t_unix_ {
|
||||||
t_socket sock;
|
t_socket sock;
|
||||||
t_io io;
|
t_io io;
|
||||||
@ -25,6 +22,6 @@ typedef struct t_unix_ {
|
|||||||
} t_unix;
|
} t_unix;
|
||||||
typedef t_unix *p_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 */
|
#endif /* UNIX_H */
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
* Unix domain socket dgram submodule
|
* Unix domain socket dgram submodule
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
#include <string.h>
|
#include "luasocket.h"
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
@ -13,6 +12,10 @@
|
|||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "unix.h"
|
#include "unix.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
#define UNIXDGRAM_DATAGRAMSIZE 8192
|
#define UNIXDGRAM_DATAGRAMSIZE 8192
|
||||||
@ -83,7 +86,7 @@ static luaL_Reg func[] = {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int unixdgram_open(lua_State *L)
|
LUASOCKET_PRIVATE int unixdgram_open(lua_State *L)
|
||||||
{
|
{
|
||||||
/* create classes */
|
/* create classes */
|
||||||
auxiliar_newclass(L, "unixdgram{connected}", unixdgram_methods);
|
auxiliar_newclass(L, "unixdgram{connected}", unixdgram_methods);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* Unix domain socket stream sub module
|
* Unix domain socket stream sub module
|
||||||
* LuaSocket toolkit
|
* LuaSocket toolkit
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
#include <string.h>
|
#include "luasocket.h"
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
@ -12,6 +12,8 @@
|
|||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "unixstream.h"
|
#include "unixstream.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
/*=========================================================================*\
|
/*=========================================================================*\
|
||||||
@ -80,7 +82,7 @@ static luaL_Reg func[] = {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int unixstream_open(lua_State *L)
|
LUASOCKET_PRIVATE int unixstream_open(lua_State *L)
|
||||||
{
|
{
|
||||||
/* create classes */
|
/* create classes */
|
||||||
auxiliar_newclass(L, "unixstream{master}", unixstream_methods);
|
auxiliar_newclass(L, "unixstream{master}", unixstream_methods);
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
* The penalty of calling select to avoid busy-wait is only paid when
|
* The penalty of calling select to avoid busy-wait is only paid when
|
||||||
* the I/O call fail in the first place.
|
* the I/O call fail in the first place.
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
#include <string.h>
|
#include "luasocket.h"
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "pierror.h"
|
#include "pierror.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Wait for readable/writable/connected socket with timeout
|
* Wait for readable/writable/connected socket with timeout
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
@ -21,7 +23,7 @@
|
|||||||
#define WAITFD_R POLLIN
|
#define WAITFD_R POLLIN
|
||||||
#define WAITFD_W POLLOUT
|
#define WAITFD_W POLLOUT
|
||||||
#define WAITFD_C (POLLIN|POLLOUT)
|
#define WAITFD_C (POLLIN|POLLOUT)
|
||||||
int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
|
LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
|
||||||
int ret;
|
int ret;
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
pfd.fd = *ps;
|
pfd.fd = *ps;
|
||||||
@ -43,7 +45,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
|
|||||||
#define WAITFD_W 2
|
#define WAITFD_W 2
|
||||||
#define WAITFD_C (WAITFD_R|WAITFD_W)
|
#define WAITFD_C (WAITFD_R|WAITFD_W)
|
||||||
|
|
||||||
int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
|
LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
|
||||||
int ret;
|
int ret;
|
||||||
fd_set rfds, wfds, *rp, *wp;
|
fd_set rfds, wfds, *rp, *wp;
|
||||||
struct timeval tv, *tp;
|
struct timeval tv, *tp;
|
||||||
@ -75,7 +77,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_open(void) {
|
LUASOCKET_PRIVATE int socket_open(void) {
|
||||||
/* installs a handler to ignore sigpipe or it will crash us */
|
/* installs a handler to ignore sigpipe or it will crash us */
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
return 1;
|
return 1;
|
||||||
@ -84,14 +86,14 @@ int socket_open(void) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Close module
|
* Close module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_close(void) {
|
LUASOCKET_PRIVATE int socket_close(void) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Close and inutilize socket
|
* Close and inutilize socket
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void socket_destroy(p_socket ps) {
|
LUASOCKET_PRIVATE void socket_destroy(p_socket ps) {
|
||||||
if (*ps != SOCKET_INVALID) {
|
if (*ps != SOCKET_INVALID) {
|
||||||
close(*ps);
|
close(*ps);
|
||||||
*ps = SOCKET_INVALID;
|
*ps = SOCKET_INVALID;
|
||||||
@ -101,7 +103,7 @@ void socket_destroy(p_socket ps) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Select with timeout control
|
* Select with timeout control
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds,
|
LUASOCKET_PRIVATE int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds,
|
||||||
p_timeout tm) {
|
p_timeout tm) {
|
||||||
int ret;
|
int ret;
|
||||||
do {
|
do {
|
||||||
@ -118,7 +120,7 @@ int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Creates and sets up a socket
|
* Creates and sets up a socket
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_create(p_socket ps, int domain, int type, int protocol) {
|
LUASOCKET_PRIVATE int socket_create(p_socket ps, int domain, int type, int protocol) {
|
||||||
*ps = socket(domain, type, protocol);
|
*ps = socket(domain, type, protocol);
|
||||||
if (*ps != SOCKET_INVALID) return IO_DONE;
|
if (*ps != SOCKET_INVALID) return IO_DONE;
|
||||||
else return errno;
|
else return errno;
|
||||||
@ -127,7 +129,7 @@ int socket_create(p_socket ps, int domain, int type, int protocol) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Binds or returns error message
|
* Binds or returns error message
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_bind(p_socket ps, SA *addr, socklen_t len) {
|
LUASOCKET_PRIVATE int socket_bind(p_socket ps, SA *addr, socklen_t len) {
|
||||||
int err = IO_DONE;
|
int err = IO_DONE;
|
||||||
socket_setblocking(ps);
|
socket_setblocking(ps);
|
||||||
if (bind(*ps, addr, len) < 0) err = errno;
|
if (bind(*ps, addr, len) < 0) err = errno;
|
||||||
@ -138,7 +140,7 @@ int socket_bind(p_socket ps, SA *addr, socklen_t len) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
*
|
*
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_listen(p_socket ps, int backlog) {
|
LUASOCKET_PRIVATE int socket_listen(p_socket ps, int backlog) {
|
||||||
int err = IO_DONE;
|
int err = IO_DONE;
|
||||||
if (listen(*ps, backlog)) err = errno;
|
if (listen(*ps, backlog)) err = errno;
|
||||||
return err;
|
return err;
|
||||||
@ -147,14 +149,14 @@ int socket_listen(p_socket ps, int backlog) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
*
|
*
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void socket_shutdown(p_socket ps, int how) {
|
LUASOCKET_PRIVATE void socket_shutdown(p_socket ps, int how) {
|
||||||
shutdown(*ps, how);
|
shutdown(*ps, how);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Connects or returns error message
|
* Connects or returns error message
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {
|
LUASOCKET_PRIVATE int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {
|
||||||
int err;
|
int err;
|
||||||
/* avoid calling on closed sockets */
|
/* avoid calling on closed sockets */
|
||||||
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
||||||
@ -176,7 +178,7 @@ int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Accept with timeout
|
* Accept with timeout
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout tm) {
|
LUASOCKET_PRIVATE int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout tm) {
|
||||||
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
int err;
|
int err;
|
||||||
@ -193,7 +195,7 @@ int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Send with timeout
|
* Send with timeout
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_send(p_socket ps, const char *data, size_t count,
|
LUASOCKET_PRIVATE int socket_send(p_socket ps, const char *data, size_t count,
|
||||||
size_t *sent, p_timeout tm)
|
size_t *sent, p_timeout tm)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -227,7 +229,7 @@ int socket_send(p_socket ps, const char *data, size_t count,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Sendto with timeout
|
* Sendto with timeout
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent,
|
LUASOCKET_PRIVATE int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent,
|
||||||
SA *addr, socklen_t len, p_timeout tm)
|
SA *addr, socklen_t len, p_timeout tm)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -252,7 +254,7 @@ int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Receive with timeout
|
* Receive with timeout
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) {
|
LUASOCKET_PRIVATE int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) {
|
||||||
int err;
|
int err;
|
||||||
*got = 0;
|
*got = 0;
|
||||||
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
||||||
@ -274,7 +276,7 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Recvfrom with timeout
|
* Recvfrom with timeout
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
LUASOCKET_PRIVATE int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
||||||
SA *addr, socklen_t *len, p_timeout tm) {
|
SA *addr, socklen_t *len, p_timeout tm) {
|
||||||
int err;
|
int err;
|
||||||
*got = 0;
|
*got = 0;
|
||||||
@ -302,7 +304,7 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
|||||||
* with send/recv replaced with write/read. We can't just use write/read
|
* with send/recv replaced with write/read. We can't just use write/read
|
||||||
* in the socket version, because behaviour when size is zero is different.
|
* in the socket version, because behaviour when size is zero is different.
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_write(p_socket ps, const char *data, size_t count,
|
LUASOCKET_PRIVATE int socket_write(p_socket ps, const char *data, size_t count,
|
||||||
size_t *sent, p_timeout tm)
|
size_t *sent, p_timeout tm)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -337,7 +339,7 @@ int socket_write(p_socket ps, const char *data, size_t count,
|
|||||||
* Read with timeout
|
* Read with timeout
|
||||||
* See note for socket_write
|
* See note for socket_write
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) {
|
LUASOCKET_PRIVATE int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) {
|
||||||
int err;
|
int err;
|
||||||
*got = 0;
|
*got = 0;
|
||||||
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
||||||
@ -359,7 +361,7 @@ int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Put socket into blocking mode
|
* Put socket into blocking mode
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void socket_setblocking(p_socket ps) {
|
LUASOCKET_PRIVATE void socket_setblocking(p_socket ps) {
|
||||||
int flags = fcntl(*ps, F_GETFL, 0);
|
int flags = fcntl(*ps, F_GETFL, 0);
|
||||||
flags &= (~(O_NONBLOCK));
|
flags &= (~(O_NONBLOCK));
|
||||||
fcntl(*ps, F_SETFL, flags);
|
fcntl(*ps, F_SETFL, flags);
|
||||||
@ -368,7 +370,7 @@ void socket_setblocking(p_socket ps) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Put socket into non-blocking mode
|
* Put socket into non-blocking mode
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void socket_setnonblocking(p_socket ps) {
|
LUASOCKET_PRIVATE void socket_setnonblocking(p_socket ps) {
|
||||||
int flags = fcntl(*ps, F_GETFL, 0);
|
int flags = fcntl(*ps, F_GETFL, 0);
|
||||||
flags |= O_NONBLOCK;
|
flags |= O_NONBLOCK;
|
||||||
fcntl(*ps, F_SETFL, flags);
|
fcntl(*ps, F_SETFL, flags);
|
||||||
@ -377,7 +379,7 @@ void socket_setnonblocking(p_socket ps) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* DNS helpers
|
* DNS helpers
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) {
|
LUASOCKET_PRIVATE int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) {
|
||||||
*hp = gethostbyaddr(addr, len, AF_INET);
|
*hp = gethostbyaddr(addr, len, AF_INET);
|
||||||
if (*hp) return IO_DONE;
|
if (*hp) return IO_DONE;
|
||||||
else if (h_errno) return h_errno;
|
else if (h_errno) return h_errno;
|
||||||
@ -385,7 +387,7 @@ int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) {
|
|||||||
else return IO_UNKNOWN;
|
else return IO_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
int socket_gethostbyname(const char *addr, struct hostent **hp) {
|
LUASOCKET_PRIVATE int socket_gethostbyname(const char *addr, struct hostent **hp) {
|
||||||
*hp = gethostbyname(addr);
|
*hp = gethostbyname(addr);
|
||||||
if (*hp) return IO_DONE;
|
if (*hp) return IO_DONE;
|
||||||
else if (h_errno) return h_errno;
|
else if (h_errno) return h_errno;
|
||||||
@ -397,7 +399,7 @@ int socket_gethostbyname(const char *addr, struct hostent **hp) {
|
|||||||
* Error translation functions
|
* Error translation functions
|
||||||
* Make sure important error messages are standard
|
* Make sure important error messages are standard
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
const char *socket_hoststrerror(int err) {
|
LUASOCKET_PRIVATE const char *socket_hoststrerror(int err) {
|
||||||
if (err <= 0) return io_strerror(err);
|
if (err <= 0) return io_strerror(err);
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case HOST_NOT_FOUND: return PIE_HOST_NOT_FOUND;
|
case HOST_NOT_FOUND: return PIE_HOST_NOT_FOUND;
|
||||||
@ -405,7 +407,7 @@ const char *socket_hoststrerror(int err) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *socket_strerror(int err) {
|
LUASOCKET_PRIVATE const char *socket_strerror(int err) {
|
||||||
if (err <= 0) return io_strerror(err);
|
if (err <= 0) return io_strerror(err);
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case EADDRINUSE: return PIE_ADDRINUSE;
|
case EADDRINUSE: return PIE_ADDRINUSE;
|
||||||
@ -421,12 +423,12 @@ const char *socket_strerror(int err) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *socket_ioerror(p_socket ps, int err) {
|
LUASOCKET_PRIVATE const char *socket_ioerror(p_socket ps, int err) {
|
||||||
(void) ps;
|
(void) ps;
|
||||||
return socket_strerror(err);
|
return socket_strerror(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *socket_gaistrerror(int err) {
|
LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) {
|
||||||
if (err == 0) return NULL;
|
if (err == 0) return NULL;
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case EAI_AGAIN: return PIE_AGAIN;
|
case EAI_AGAIN: return PIE_AGAIN;
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
* The penalty of calling select to avoid busy-wait is only paid when
|
* The penalty of calling select to avoid busy-wait is only paid when
|
||||||
* the I/O call fail in the first place.
|
* the I/O call fail in the first place.
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
|
#include "luasocket.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
@ -16,7 +18,7 @@ static const char *wstrerror(int err);
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Initializes module
|
* Initializes module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_open(void) {
|
LUASOCKET_PRIVATE int socket_open(void) {
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
WORD wVersionRequested = MAKEWORD(2, 0);
|
WORD wVersionRequested = MAKEWORD(2, 0);
|
||||||
int err = WSAStartup(wVersionRequested, &wsaData );
|
int err = WSAStartup(wVersionRequested, &wsaData );
|
||||||
@ -32,7 +34,7 @@ int socket_open(void) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Close module
|
* Close module
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_close(void) {
|
LUASOCKET_PRIVATE int socket_close(void) {
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -45,7 +47,7 @@ int socket_close(void) {
|
|||||||
#define WAITFD_E 4
|
#define WAITFD_E 4
|
||||||
#define WAITFD_C (WAITFD_E|WAITFD_W)
|
#define WAITFD_C (WAITFD_E|WAITFD_W)
|
||||||
|
|
||||||
int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
|
LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
|
||||||
int ret;
|
int ret;
|
||||||
fd_set rfds, wfds, efds, *rp = NULL, *wp = NULL, *ep = NULL;
|
fd_set rfds, wfds, efds, *rp = NULL, *wp = NULL, *ep = NULL;
|
||||||
struct timeval tv, *tp = NULL;
|
struct timeval tv, *tp = NULL;
|
||||||
@ -73,7 +75,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Select with int timeout in ms
|
* Select with int timeout in ms
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds,
|
LUASOCKET_PRIVATE int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds,
|
||||||
p_timeout tm) {
|
p_timeout tm) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
double t = timeout_get(tm);
|
double t = timeout_get(tm);
|
||||||
@ -88,7 +90,7 @@ int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Close and inutilize socket
|
* Close and inutilize socket
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void socket_destroy(p_socket ps) {
|
LUASOCKET_PRIVATE void socket_destroy(p_socket ps) {
|
||||||
if (*ps != SOCKET_INVALID) {
|
if (*ps != SOCKET_INVALID) {
|
||||||
socket_setblocking(ps); /* close can take a long time on WIN32 */
|
socket_setblocking(ps); /* close can take a long time on WIN32 */
|
||||||
closesocket(*ps);
|
closesocket(*ps);
|
||||||
@ -99,7 +101,7 @@ void socket_destroy(p_socket ps) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
*
|
*
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void socket_shutdown(p_socket ps, int how) {
|
LUASOCKET_PRIVATE void socket_shutdown(p_socket ps, int how) {
|
||||||
socket_setblocking(ps);
|
socket_setblocking(ps);
|
||||||
shutdown(*ps, how);
|
shutdown(*ps, how);
|
||||||
socket_setnonblocking(ps);
|
socket_setnonblocking(ps);
|
||||||
@ -108,7 +110,7 @@ void socket_shutdown(p_socket ps, int how) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Creates and sets up a socket
|
* Creates and sets up a socket
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_create(p_socket ps, int domain, int type, int protocol) {
|
LUASOCKET_PRIVATE int socket_create(p_socket ps, int domain, int type, int protocol) {
|
||||||
*ps = socket(domain, type, protocol);
|
*ps = socket(domain, type, protocol);
|
||||||
if (*ps != SOCKET_INVALID) return IO_DONE;
|
if (*ps != SOCKET_INVALID) return IO_DONE;
|
||||||
else return WSAGetLastError();
|
else return WSAGetLastError();
|
||||||
@ -117,7 +119,7 @@ int socket_create(p_socket ps, int domain, int type, int protocol) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Connects or returns error message
|
* Connects or returns error message
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {
|
LUASOCKET_PRIVATE int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {
|
||||||
int err;
|
int err;
|
||||||
/* don't call on closed socket */
|
/* don't call on closed socket */
|
||||||
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
||||||
@ -146,7 +148,7 @@ int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Binds or returns error message
|
* Binds or returns error message
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_bind(p_socket ps, SA *addr, socklen_t len) {
|
LUASOCKET_PRIVATE int socket_bind(p_socket ps, SA *addr, socklen_t len) {
|
||||||
int err = IO_DONE;
|
int err = IO_DONE;
|
||||||
socket_setblocking(ps);
|
socket_setblocking(ps);
|
||||||
if (bind(*ps, addr, len) < 0) err = WSAGetLastError();
|
if (bind(*ps, addr, len) < 0) err = WSAGetLastError();
|
||||||
@ -157,7 +159,7 @@ int socket_bind(p_socket ps, SA *addr, socklen_t len) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
*
|
*
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_listen(p_socket ps, int backlog) {
|
LUASOCKET_PRIVATE int socket_listen(p_socket ps, int backlog) {
|
||||||
int err = IO_DONE;
|
int err = IO_DONE;
|
||||||
socket_setblocking(ps);
|
socket_setblocking(ps);
|
||||||
if (listen(*ps, backlog) < 0) err = WSAGetLastError();
|
if (listen(*ps, backlog) < 0) err = WSAGetLastError();
|
||||||
@ -168,7 +170,7 @@ int socket_listen(p_socket ps, int backlog) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Accept with timeout
|
* Accept with timeout
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len,
|
LUASOCKET_PRIVATE int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len,
|
||||||
p_timeout tm) {
|
p_timeout tm) {
|
||||||
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
if (*ps == SOCKET_INVALID) return IO_CLOSED;
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
@ -190,7 +192,7 @@ int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len,
|
|||||||
* this can take an awful lot of time and we will end up blocked.
|
* this can take an awful lot of time and we will end up blocked.
|
||||||
* Therefore, whoever calls this function should not pass a huge buffer.
|
* Therefore, whoever calls this function should not pass a huge buffer.
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_send(p_socket ps, const char *data, size_t count,
|
LUASOCKET_PRIVATE int socket_send(p_socket ps, const char *data, size_t count,
|
||||||
size_t *sent, p_timeout tm)
|
size_t *sent, p_timeout tm)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -218,7 +220,7 @@ int socket_send(p_socket ps, const char *data, size_t count,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Sendto with timeout
|
* Sendto with timeout
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent,
|
LUASOCKET_PRIVATE int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent,
|
||||||
SA *addr, socklen_t len, p_timeout tm)
|
SA *addr, socklen_t len, p_timeout tm)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -239,7 +241,7 @@ int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Receive with timeout
|
* Receive with timeout
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_recv(p_socket ps, char *data, size_t count, size_t *got,
|
LUASOCKET_PRIVATE int socket_recv(p_socket ps, char *data, size_t count, size_t *got,
|
||||||
p_timeout tm)
|
p_timeout tm)
|
||||||
{
|
{
|
||||||
int err, prev = IO_DONE;
|
int err, prev = IO_DONE;
|
||||||
@ -268,7 +270,7 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Recvfrom with timeout
|
* Recvfrom with timeout
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
LUASOCKET_PRIVATE int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
||||||
SA *addr, socklen_t *len, p_timeout tm)
|
SA *addr, socklen_t *len, p_timeout tm)
|
||||||
{
|
{
|
||||||
int err, prev = IO_DONE;
|
int err, prev = IO_DONE;
|
||||||
@ -297,7 +299,7 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Put socket into blocking mode
|
* Put socket into blocking mode
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void socket_setblocking(p_socket ps) {
|
LUASOCKET_PRIVATE void socket_setblocking(p_socket ps) {
|
||||||
u_long argp = 0;
|
u_long argp = 0;
|
||||||
ioctlsocket(*ps, FIONBIO, &argp);
|
ioctlsocket(*ps, FIONBIO, &argp);
|
||||||
}
|
}
|
||||||
@ -305,7 +307,7 @@ void socket_setblocking(p_socket ps) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Put socket into non-blocking mode
|
* Put socket into non-blocking mode
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
void socket_setnonblocking(p_socket ps) {
|
LUASOCKET_PRIVATE void socket_setnonblocking(p_socket ps) {
|
||||||
u_long argp = 1;
|
u_long argp = 1;
|
||||||
ioctlsocket(*ps, FIONBIO, &argp);
|
ioctlsocket(*ps, FIONBIO, &argp);
|
||||||
}
|
}
|
||||||
@ -313,13 +315,13 @@ void socket_setnonblocking(p_socket ps) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* DNS helpers
|
* DNS helpers
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) {
|
LUASOCKET_PRIVATE int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) {
|
||||||
*hp = gethostbyaddr(addr, len, AF_INET);
|
*hp = gethostbyaddr(addr, len, AF_INET);
|
||||||
if (*hp) return IO_DONE;
|
if (*hp) return IO_DONE;
|
||||||
else return WSAGetLastError();
|
else return WSAGetLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
int socket_gethostbyname(const char *addr, struct hostent **hp) {
|
LUASOCKET_PRIVATE int socket_gethostbyname(const char *addr, struct hostent **hp) {
|
||||||
*hp = gethostbyname(addr);
|
*hp = gethostbyname(addr);
|
||||||
if (*hp) return IO_DONE;
|
if (*hp) return IO_DONE;
|
||||||
else return WSAGetLastError();
|
else return WSAGetLastError();
|
||||||
@ -328,7 +330,7 @@ int socket_gethostbyname(const char *addr, struct hostent **hp) {
|
|||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
* Error translation functions
|
* Error translation functions
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
const char *socket_hoststrerror(int err) {
|
LUASOCKET_PRIVATE const char *socket_hoststrerror(int err) {
|
||||||
if (err <= 0) return io_strerror(err);
|
if (err <= 0) return io_strerror(err);
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case WSAHOST_NOT_FOUND: return PIE_HOST_NOT_FOUND;
|
case WSAHOST_NOT_FOUND: return PIE_HOST_NOT_FOUND;
|
||||||
@ -336,7 +338,7 @@ const char *socket_hoststrerror(int err) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *socket_strerror(int err) {
|
LUASOCKET_PRIVATE const char *socket_strerror(int err) {
|
||||||
if (err <= 0) return io_strerror(err);
|
if (err <= 0) return io_strerror(err);
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case WSAEADDRINUSE: return PIE_ADDRINUSE;
|
case WSAEADDRINUSE: return PIE_ADDRINUSE;
|
||||||
@ -350,12 +352,12 @@ const char *socket_strerror(int err) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *socket_ioerror(p_socket ps, int err) {
|
LUASOCKET_PRIVATE const char *socket_ioerror(p_socket ps, int err) {
|
||||||
(void) ps;
|
(void) ps;
|
||||||
return socket_strerror(err);
|
return socket_strerror(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *wstrerror(int err) {
|
LUASOCKET_PRIVATE static const char *wstrerror(int err) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case WSAEINTR: return "Interrupted function call";
|
case WSAEINTR: return "Interrupted function call";
|
||||||
case WSAEACCES: return PIE_ACCESS; // "Permission denied";
|
case WSAEACCES: return PIE_ACCESS; // "Permission denied";
|
||||||
@ -404,7 +406,7 @@ static const char *wstrerror(int err) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *socket_gaistrerror(int err) {
|
LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) {
|
||||||
if (err == 0) return NULL;
|
if (err == 0) return NULL;
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case EAI_AGAIN: return PIE_AGAIN;
|
case EAI_AGAIN: return PIE_AGAIN;
|
||||||
|
Loading…
Reference in New Issue
Block a user