From f06b17c4c918e1132ae78d1075c8c9654fdc016d Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:54:09 -0700 Subject: [PATCH 01/23] luasocket.h: define LUASOCKET_API and LUASOCKET_PRIVATE for export visibility --- src/luasocket.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/luasocket.h b/src/luasocket.h index f75d21f..0121a15 100644 --- a/src/luasocket.h +++ b/src/luasocket.h @@ -18,7 +18,19 @@ * This macro prefixes all exported API functions \*-------------------------------------------------------------------------*/ #ifndef LUASOCKET_API -#define LUASOCKET_API extern +#ifdef _WIN32 +#define LUASOCKET_API __declspec(dllexport) +#else +#define LUASOCKET_API __attribute__ ((visibility ("default"))) +#endif +#endif + +#ifndef LUASOCKET_PRIVATE +#ifdef _WIN32 +#define LUASOCKET_PRIVATE +#else +#define LUASOCKET_PRIVATE __attribute__ ((visibility ("hidden"))) +#endif #endif /*-------------------------------------------------------------------------*\ From efc4bb3e2df90732d46b8b1cdae18c8173bad07b Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:55:04 -0700 Subject: [PATCH 02/23] mime.h: use LUASOCKET_API --- src/mime.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/mime.h b/src/mime.h index 99968a5..e57fc9c 100644 --- a/src/mime.h +++ b/src/mime.h @@ -8,6 +8,7 @@ * and formatting conforming to RFC 2045. It is used by mime.lua, which * provide a higher level interface to this functionality. \*=========================================================================*/ +#include "luasocket.h" #include "lua.h" /*-------------------------------------------------------------------------*\ @@ -17,13 +18,6 @@ #define MIME_COPYRIGHT "Copyright (C) 2004-2013 Diego Nehab" #define MIME_AUTHORS "Diego Nehab" -/*-------------------------------------------------------------------------*\ -* This macro prefixes all exported API functions -\*-------------------------------------------------------------------------*/ -#ifndef MIME_API -#define MIME_API extern -#endif - -MIME_API int luaopen_mime_core(lua_State *L); +LUASOCKET_API int luaopen_mime_core(lua_State *L); #endif /* MIME_H */ From c23bf865ce32666e8f3bb0abd7d82f84a891ce82 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:55:36 -0700 Subject: [PATCH 03/23] unix.h: use LUASOCKET_API --- src/unix.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/unix.h b/src/unix.h index 8cc7a79..a1674ef 100644 --- a/src/unix.h +++ b/src/unix.h @@ -7,16 +7,13 @@ * This module is just an example of how to extend LuaSocket with a new * domain. \*=========================================================================*/ +#include "luasocket.h" #include "lua.h" #include "buffer.h" #include "timeout.h" #include "socket.h" -#ifndef UNIX_API -#define UNIX_API extern -#endif - typedef struct t_unix_ { t_socket sock; t_io io; @@ -25,6 +22,6 @@ typedef struct t_unix_ { } t_unix; typedef t_unix *p_unix; -UNIX_API int luaopen_socket_unix(lua_State *L); +LUASOCKET_API int luaopen_socket_unix(lua_State *L); #endif /* UNIX_H */ From 1f6035070fd5e2185dfb3a3bf48e1d12668c6599 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:56:17 -0700 Subject: [PATCH 04/23] mime.c: use LUASOCKET_API --- src/mime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mime.c b/src/mime.c index 338ecd4..6e359af 100755 --- a/src/mime.c +++ b/src/mime.c @@ -76,7 +76,7 @@ static UC b64unbase[256]; /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -MIME_API int luaopen_mime_core(lua_State *L) +LUASOCKET_API int luaopen_mime_core(lua_State *L) { lua_newtable(L); luaL_setfuncs(L, func, 0); From 16b0026e27d4c77fc5e723d52b811ebc23dddc0c Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:56:28 -0700 Subject: [PATCH 05/23] unix.c: use LUASOCKET_API --- src/unix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/unix.c b/src/unix.c index dbc8710..c618a20 100644 --- a/src/unix.c +++ b/src/unix.c @@ -2,6 +2,8 @@ * Unix domain socket * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" + #include "lua.h" #include "lauxlib.h" @@ -45,7 +47,7 @@ static int compat_socket_unix_call(lua_State *L) /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int luaopen_socket_unix(lua_State *L) +LUASOCKET_API int luaopen_socket_unix(lua_State *L) { int i; lua_newtable(L); From c0374dd46ff7b3a8c1913ade4a3746873d6060c1 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:57:01 -0700 Subject: [PATCH 06/23] auxiliar.c: use LUASOCKET_PRIVATE --- src/auxiliar.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/auxiliar.c b/src/auxiliar.c index 5251549..0bd7927 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c @@ -2,18 +2,18 @@ * Auxiliar routines for class hierarchy manipulation * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" +#include "auxiliar.h" #include #include -#include "auxiliar.h" - /*=========================================================================*\ * Exported functions \*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Initializes the module \*-------------------------------------------------------------------------*/ -int auxiliar_open(lua_State *L) { +LUASOCKET_PRIVATE int auxiliar_open(lua_State *L) { (void) L; return 0; } @@ -22,7 +22,7 @@ int auxiliar_open(lua_State *L) { * Creates a new class with given methods * 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 */ /* create __index table to place methods */ 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 \*-------------------------------------------------------------------------*/ -int auxiliar_tostring(lua_State *L) { +LUASOCKET_PRIVATE int auxiliar_tostring(lua_State *L) { char buf[32]; if (!lua_getmetatable(L, 1)) goto error; lua_pushstring(L, "__index"); @@ -66,7 +66,7 @@ error: /*-------------------------------------------------------------------------*\ * 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); lua_pushstring(L, groupname); 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 \*-------------------------------------------------------------------------*/ -int auxiliar_checkboolean(lua_State *L, int objidx) { +LUASOCKET_PRIVATE int auxiliar_checkboolean(lua_State *L, int objidx) { if (!lua_isboolean(L, objidx)) auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN)); 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 * 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); if (!data) { 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 * 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); if (!data) { char msg[45]; @@ -114,7 +114,7 @@ void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) { /*-------------------------------------------------------------------------*\ * 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); if (objidx < 0) 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 * 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)) return NULL; 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 * 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); } @@ -150,7 +150,7 @@ void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { * Throws error when argument does not have correct type. * 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, luaL_typename(L, narg)); return luaL_argerror(L, narg, msg); From b95527e140fd0ec573ca0e83c5f64dffadd7e228 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:57:25 -0700 Subject: [PATCH 07/23] buffer.c: use LUASOCKET_PRIVATE --- src/buffer.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index fff1634..357730a 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -2,6 +2,8 @@ * Input/Output interface for Lua programs * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" + #include "lua.h" #include "lauxlib.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 \*-------------------------------------------------------------------------*/ -int buffer_open(lua_State *L) { +LUASOCKET_PRIVATE int buffer_open(lua_State *L) { (void) L; return 0; } @@ -40,7 +42,7 @@ int buffer_open(lua_State *L) { /*-------------------------------------------------------------------------*\ * 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->io = io; buf->tm = tm; @@ -51,7 +53,7 @@ void buffer_init(p_buffer buf, p_io io, p_timeout tm) { /*-------------------------------------------------------------------------*\ * 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->sent); lua_pushnumber(L, timeout_gettime() - buf->birthday); @@ -61,7 +63,7 @@ int buffer_meth_getstats(lua_State *L, p_buffer buf) { /*-------------------------------------------------------------------------*\ * 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->sent = (long) luaL_optnumber(L, 3, (lua_Number) buf->sent); 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 \*-------------------------------------------------------------------------*/ -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 err = IO_DONE; size_t size = 0, sent = 0; @@ -105,7 +107,7 @@ int buffer_meth_send(lua_State *L, p_buffer buf) { /*-------------------------------------------------------------------------*\ * 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); luaL_Buffer b; 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 \*-------------------------------------------------------------------------*/ -int buffer_isempty(p_buffer buf) { +LUASOCKET_PRIVATE int buffer_isempty(p_buffer buf) { return buf->first >= buf->last; } From 2bf6730fd559e06727903eec77e52b29637c2af1 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:58:30 -0700 Subject: [PATCH 08/23] pragma.c: use LUASOCKET_PRIVATE --- src/compat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compat.c b/src/compat.c index 988fa68..1290f70 100644 --- a/src/compat.c +++ b/src/compat.c @@ -1,10 +1,11 @@ +#include "luasocket.h" #include "compat.h" #if LUA_VERSION_NUM==501 /* ** Adapted from Lua 5.2 */ -void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { +LUASOCKET_PRIVATE void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { luaL_checkstack(L, nup+1, "too many upvalues"); for (; l->name != NULL; l++) { /* fill the table with given functions */ int i; @@ -20,7 +21,7 @@ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { /* ** Duplicated from Lua 5.2 */ -void *luaL_testudata (lua_State *L, int ud, const char *tname) { +LUASOCKET_PRIVATE void *luaL_testudata (lua_State *L, int ud, const char *tname) { void *p = lua_touserdata(L, ud); if (p != NULL) { /* value is a userdata? */ if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ From 395729d4314dfeda2a095760cf2de042af7581f8 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:58:45 -0700 Subject: [PATCH 09/23] except.c: use LUASOCKET_PRIVATE --- src/except.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/except.c b/src/except.c index 60b5005..dab70e7 100644 --- a/src/except.c +++ b/src/except.c @@ -2,6 +2,8 @@ * Simple exception support * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" + #include #include "lua.h" @@ -124,7 +126,7 @@ static int global_protect(lua_State *L) { /*-------------------------------------------------------------------------*\ * Init module \*-------------------------------------------------------------------------*/ -int except_open(lua_State *L) { +LUASOCKET_PRIVATE int except_open(lua_State *L) { lua_newtable(L); /* metatable for wrapped exceptions */ lua_pushboolean(L, 0); lua_setfield(L, -2, "__metatable"); From 731b23bc891fdf6136af7457972b8a8f8f1b55ec Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:58:54 -0700 Subject: [PATCH 10/23] inet.c: use LUASOCKET_PRIVATE --- src/inet.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/inet.c b/src/inet.c index f4c8404..bed8a7c 100644 --- a/src/inet.c +++ b/src/inet.c @@ -2,6 +2,8 @@ * Internet domain functions * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" + #include #include #include @@ -38,7 +40,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int inet_open(lua_State *L) +LUASOCKET_PRIVATE int inet_open(lua_State *L) { lua_pushstring(L, "dns"); lua_newtable(L); @@ -143,7 +145,7 @@ static int inet_global_toip(lua_State *L) 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 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)]; } -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 int optvalue[] = { SOCK_STREAM, SOCK_DGRAM, 0 }; @@ -242,7 +244,7 @@ static int inet_global_gethostname(lua_State *L) /*-------------------------------------------------------------------------*\ * 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; struct sockaddr_storage peer; @@ -276,7 +278,7 @@ int inet_meth_getpeername(lua_State *L, p_socket ps, int family) /*-------------------------------------------------------------------------*\ * 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; 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 \*-------------------------------------------------------------------------*/ -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)); if (err == NULL && family == AF_INET6) { int yes = 1; @@ -364,7 +366,7 @@ const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { /*-------------------------------------------------------------------------*\ * "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) { 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) \*-------------------------------------------------------------------------*/ -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) { 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 \*-------------------------------------------------------------------------*/ -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) { socklen_t len; 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) \*-------------------------------------------------------------------------*/ -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) { struct addrinfo *iterator = NULL, *resolved = 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. \*-------------------------------------------------------------------------*/ #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; int n = 0, r; @@ -519,7 +521,7 @@ int inet_aton(const char *cp, struct in_addr *inp) #endif #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; int ret = 1; From 3f19a052e8f0c014365e9a07aaf82afd586f3ee1 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:59:09 -0700 Subject: [PATCH 11/23] io.c: use LUASOCKET_PRIVATE --- src/io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/io.c b/src/io.c index a4230ce..f1a2b9d 100644 --- a/src/io.c +++ b/src/io.c @@ -2,6 +2,7 @@ * Input/Output abstraction * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" #include "io.h" /*=========================================================================*\ @@ -10,7 +11,7 @@ /*-------------------------------------------------------------------------*\ * 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->recv = recv; 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 \*-------------------------------------------------------------------------*/ -const char *io_strerror(int err) { +LUASOCKET_PRIVATE const char *io_strerror(int err) { switch (err) { case IO_DONE: return NULL; case IO_CLOSED: return "closed"; From ef2a3fcedb8c03a2e64942cb794f4ffd6a9beef7 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:59:19 -0700 Subject: [PATCH 12/23] options.c: use LUASOCKET_PRIVATE --- src/options.c | 94 +++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/src/options.c b/src/options.c index bbadec3..b0bacbf 100644 --- a/src/options.c +++ b/src/options.c @@ -2,14 +2,12 @@ * Common option interface * LuaSocket toolkit \*=========================================================================*/ -#include - +#include "luasocket.h" #include "lauxlib.h" - #include "auxiliar.h" #include "options.h" #include "inet.h" - +#include /*=========================================================================*\ * 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 \*-------------------------------------------------------------------------*/ -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, ... */ 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); } -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, ... */ 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 */ -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); } -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); } /* 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); } -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); } /* 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); } -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); } #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); } -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); } #endif #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); } -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); } #endif #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); } -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); } #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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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); } -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 */ 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)); } -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 */ int len = sizeof(li); @@ -248,12 +246,12 @@ int opt_get_linger(lua_State *L, p_socket ps) 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); } -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 */ struct in_addr val; @@ -264,7 +262,7 @@ int opt_set_ip_multicast_if(lua_State *L, p_socket ps) (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; socklen_t len = sizeof(val); @@ -277,32 +275,32 @@ int opt_get_ip_multicast_if(lua_State *L, p_socket ps) return 1; } -int opt_set_ip_add_membership(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip_add_membership(lua_State *L, p_socket ps) { 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); } -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); } -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); } -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); } -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); } @@ -393,7 +391,7 @@ static int opt_getboolean(lua_State *L, p_socket ps, int level, int name) return 1; } -int opt_get_error(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_error(lua_State *L, p_socket ps) { int val = 0; socklen_t len = sizeof(val); From fae993c118cd1b88b35d5760b233b790ac9e1109 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:59:29 -0700 Subject: [PATCH 13/23] select.c: use LUASOCKET_PRIVATE --- src/select.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/select.c b/src/select.c index 9d133b7..b615b19 100644 --- a/src/select.c +++ b/src/select.c @@ -2,7 +2,7 @@ * Select implementation * LuaSocket toolkit \*=========================================================================*/ -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" @@ -12,6 +12,8 @@ #include "timeout.h" #include "select.h" +#include + /*=========================================================================*\ * Internal function prototypes. \*=========================================================================*/ @@ -37,7 +39,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int select_open(lua_State *L) { +LUASOCKET_PRIVATE int select_open(lua_State *L) { lua_pushstring(L, "_SETSIZE"); lua_pushinteger(L, FD_SETSIZE); lua_rawset(L, -3); From 898f2df025a3bcc9b1639f64d407fba0ac9acefc Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:00:38 -0700 Subject: [PATCH 14/23] serial.c: include luasocket.h --- src/serial.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/serial.c b/src/serial.c index 7bdb21c..cb46edb 100644 --- a/src/serial.c +++ b/src/serial.c @@ -2,6 +2,8 @@ * Serial stream * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" + #include #include "lua.h" From 525d703e16c1f557b95f742f7d2681ad6815f92f Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:00:51 -0700 Subject: [PATCH 15/23] tcp.c: use LUASOCKET_PRIVATE --- src/tcp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tcp.c b/src/tcp.c index c7384b4..cc5b6a7 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -2,18 +2,21 @@ * TCP object * LuaSocket toolkit \*=========================================================================*/ -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" -#include "compat.h" +#include "compat.h" #include "auxiliar.h" + #include "socket.h" #include "inet.h" #include "options.h" #include "tcp.h" +#include + /*=========================================================================*\ * Internal function prototypes \*=========================================================================*/ @@ -126,7 +129,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int tcp_open(lua_State *L) +LUASOCKET_PRIVATE int tcp_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "tcp{master}", tcp_methods); From 87c2dee13e05d5474e2acde7f5dca29edd589335 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:01:04 -0700 Subject: [PATCH 16/23] timeout.c: use LUASOCKET_PRIVATE --- src/timeout.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/timeout.c b/src/timeout.c index 5a601d5..8fb8f55 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -2,9 +2,7 @@ * Timeout management functions * LuaSocket toolkit \*=========================================================================*/ -#include -#include -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" @@ -13,6 +11,10 @@ #include "auxiliar.h" #include "timeout.h" +#include +#include +#include + #ifdef _WIN32 #include #else @@ -46,7 +48,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * 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->total = total; } @@ -59,7 +61,7 @@ void timeout_init(p_timeout tm, double block, double total) { * Returns * 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) { return -1; } else if (tm->block < 0.0) { @@ -80,7 +82,7 @@ double timeout_get(p_timeout tm) { * Returns * start field of structure \*-------------------------------------------------------------------------*/ -double timeout_getstart(p_timeout tm) { +LUASOCKET_PRIVATE double timeout_getstart(p_timeout tm) { return tm->start; } @@ -92,7 +94,7 @@ double timeout_getstart(p_timeout tm) { * Returns * 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) { return -1; } else if (tm->block < 0.0) { @@ -112,7 +114,7 @@ double timeout_getretry(p_timeout tm) { * Input * tm: timeout control structure \*-------------------------------------------------------------------------*/ -p_timeout timeout_markstart(p_timeout tm) { +LUASOCKET_PRIVATE p_timeout timeout_markstart(p_timeout tm) { tm->start = timeout_gettime(); return tm; } @@ -123,7 +125,7 @@ p_timeout timeout_markstart(p_timeout tm) { * time in s. \*-------------------------------------------------------------------------*/ #ifdef _WIN32 -double timeout_gettime(void) { +LUASOCKET_PRIVATE double timeout_gettime(void) { FILETIME ft; double t; GetSystemTimeAsFileTime(&ft); @@ -133,7 +135,7 @@ double timeout_gettime(void) { return (t - 11644473600.0); } #else -double timeout_gettime(void) { +LUASOCKET_PRIVATE double timeout_gettime(void) { struct timeval v; gettimeofday(&v, (struct timezone *) NULL); /* Unix Epoch time (time since January 1, 1970 (UTC)) */ @@ -144,7 +146,7 @@ double timeout_gettime(void) { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int timeout_open(lua_State *L) { +LUASOCKET_PRIVATE int timeout_open(lua_State *L) { luaL_setfuncs(L, func, 0); return 0; } @@ -155,7 +157,7 @@ int timeout_open(lua_State *L) { * time: time out value in seconds * 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); const char *mode = luaL_optstring(L, 3, "b"); switch (*mode) { @@ -177,7 +179,7 @@ int timeout_meth_settimeout(lua_State *L, p_timeout tm) { * Gets timeout values for IO operations * 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->total); return 2; @@ -199,7 +201,7 @@ static int timeout_lua_gettime(lua_State *L) * Sleep for n seconds. \*-------------------------------------------------------------------------*/ #ifdef _WIN32 -int timeout_lua_sleep(lua_State *L) +LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) { double n = luaL_checknumber(L, 1); if (n < 0.0) n = 0.0; @@ -209,7 +211,7 @@ int timeout_lua_sleep(lua_State *L) return 0; } #else -int timeout_lua_sleep(lua_State *L) +LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) { double n = luaL_checknumber(L, 1); struct timespec t, r; From 30a0a6003b3150af8b317cc8e39ebfa43636e2d0 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:01:21 -0700 Subject: [PATCH 17/23] udp.c: use LUASOCKET_PRIVATE --- src/udp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/udp.c b/src/udp.c index 037f9a4..99a766f 100644 --- a/src/udp.c +++ b/src/udp.c @@ -2,8 +2,7 @@ * UDP object * LuaSocket toolkit \*=========================================================================*/ -#include -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" @@ -15,6 +14,9 @@ #include "options.h" #include "udp.h" +#include +#include + /* min and max macros */ #ifndef MIN #define MIN(x, y) ((x) < (y) ? x : y) @@ -122,7 +124,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int udp_open(lua_State *L) { +LUASOCKET_PRIVATE int udp_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "udp{connected}", udp_methods); auxiliar_newclass(L, "udp{unconnected}", udp_methods); From 678d558c5f5db9af64d33ae78c37056a44848b4c Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:01:33 -0700 Subject: [PATCH 18/23] unixdgram.c: use LUASOCKET_PRIVATE --- src/unixdgram.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/unixdgram.c b/src/unixdgram.c index 0d6f18c..840257a 100644 --- a/src/unixdgram.c +++ b/src/unixdgram.c @@ -2,8 +2,7 @@ * Unix domain socket dgram submodule * LuaSocket toolkit \*=========================================================================*/ -#include -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" @@ -13,6 +12,10 @@ #include "socket.h" #include "options.h" #include "unix.h" + +#include +#include + #include #define UNIXDGRAM_DATAGRAMSIZE 8192 @@ -83,7 +86,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int unixdgram_open(lua_State *L) +LUASOCKET_PRIVATE int unixdgram_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "unixdgram{connected}", unixdgram_methods); From fe437ee844e8e51ef0b7437bb34efd8c18927a75 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:01:44 -0700 Subject: [PATCH 19/23] unixstream.c: use LUASOCKET_PRIVATE --- src/unixstream.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/unixstream.c b/src/unixstream.c index 0b9055c..ce2d3af 100644 --- a/src/unixstream.c +++ b/src/unixstream.c @@ -2,7 +2,7 @@ * Unix domain socket stream sub module * LuaSocket toolkit \*=========================================================================*/ -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" @@ -12,6 +12,8 @@ #include "socket.h" #include "options.h" #include "unixstream.h" + +#include #include /*=========================================================================*\ @@ -80,7 +82,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int unixstream_open(lua_State *L) +LUASOCKET_PRIVATE int unixstream_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "unixstream{master}", unixstream_methods); From d7ffc2f4e69ff24a88f00456cd9a538ecc90d14c Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:04:16 -0700 Subject: [PATCH 20/23] usocket.c use LUASOCKET_PRIVATE --- src/usocket.c | 58 ++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/usocket.c b/src/usocket.c index 6e7f8f6..08a961d 100644 --- a/src/usocket.c +++ b/src/usocket.c @@ -6,12 +6,14 @@ * The penalty of calling select to avoid busy-wait is only paid when * the I/O call fail in the first place. \*=========================================================================*/ -#include -#include +#include "luasocket.h" #include "socket.h" #include "pierror.h" +#include +#include + /*-------------------------------------------------------------------------*\ * Wait for readable/writable/connected socket with timeout \*-------------------------------------------------------------------------*/ @@ -21,7 +23,7 @@ #define WAITFD_R POLLIN #define WAITFD_W 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; struct pollfd pfd; pfd.fd = *ps; @@ -43,7 +45,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) { #define WAITFD_W 2 #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; fd_set rfds, wfds, *rp, *wp; struct timeval tv, *tp; @@ -75,7 +77,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int socket_open(void) { +LUASOCKET_PRIVATE int socket_open(void) { /* installs a handler to ignore sigpipe or it will crash us */ signal(SIGPIPE, SIG_IGN); return 1; @@ -84,14 +86,14 @@ int socket_open(void) { /*-------------------------------------------------------------------------*\ * Close module \*-------------------------------------------------------------------------*/ -int socket_close(void) { +LUASOCKET_PRIVATE int socket_close(void) { return 1; } /*-------------------------------------------------------------------------*\ * Close and inutilize socket \*-------------------------------------------------------------------------*/ -void socket_destroy(p_socket ps) { +LUASOCKET_PRIVATE void socket_destroy(p_socket ps) { if (*ps != SOCKET_INVALID) { close(*ps); *ps = SOCKET_INVALID; @@ -101,7 +103,7 @@ void socket_destroy(p_socket ps) { /*-------------------------------------------------------------------------*\ * 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) { int ret; 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 \*-------------------------------------------------------------------------*/ -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); if (*ps != SOCKET_INVALID) return IO_DONE; else return errno; @@ -127,7 +129,7 @@ int socket_create(p_socket ps, int domain, int type, int protocol) { /*-------------------------------------------------------------------------*\ * 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; socket_setblocking(ps); 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; if (listen(*ps, backlog)) err = errno; 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); } /*-------------------------------------------------------------------------*\ * 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; /* avoid calling on closed sockets */ 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 \*-------------------------------------------------------------------------*/ -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; for ( ;; ) { 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 \*-------------------------------------------------------------------------*/ -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) { int err; @@ -227,7 +229,7 @@ int socket_send(p_socket ps, const char *data, size_t count, /*-------------------------------------------------------------------------*\ * 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) { int err; @@ -252,7 +254,7 @@ int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, /*-------------------------------------------------------------------------*\ * 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; *got = 0; 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 \*-------------------------------------------------------------------------*/ -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) { int err; *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 * 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) { int err; @@ -337,7 +339,7 @@ int socket_write(p_socket ps, const char *data, size_t count, * Read with timeout * 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; *got = 0; 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 \*-------------------------------------------------------------------------*/ -void socket_setblocking(p_socket ps) { +LUASOCKET_PRIVATE void socket_setblocking(p_socket ps) { int flags = fcntl(*ps, F_GETFL, 0); flags &= (~(O_NONBLOCK)); fcntl(*ps, F_SETFL, flags); @@ -368,7 +370,7 @@ void socket_setblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * 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); flags |= O_NONBLOCK; fcntl(*ps, F_SETFL, flags); @@ -377,7 +379,7 @@ void socket_setnonblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * 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); if (*hp) return IO_DONE; 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; } -int socket_gethostbyname(const char *addr, struct hostent **hp) { +LUASOCKET_PRIVATE int socket_gethostbyname(const char *addr, struct hostent **hp) { *hp = gethostbyname(addr); if (*hp) return IO_DONE; else if (h_errno) return h_errno; @@ -397,7 +399,7 @@ int socket_gethostbyname(const char *addr, struct hostent **hp) { * Error translation functions * 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); switch (err) { 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); switch (err) { 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; return socket_strerror(err); } -const char *socket_gaistrerror(int err) { +LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) { if (err == 0) return NULL; switch (err) { case EAI_AGAIN: return PIE_AGAIN; From f8183bab875f541af3932fe4e430fcff8bd8aba0 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:04:29 -0700 Subject: [PATCH 21/23] usocket.c: use LUASOCKET_PRIVATE --- src/wsocket.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/wsocket.c b/src/wsocket.c index ac8411f..c281058 100755 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -5,6 +5,8 @@ * The penalty of calling select to avoid busy-wait is only paid when * the I/O call fail in the first place. \*=========================================================================*/ +#include "luasocket.h" + #include #include "socket.h" @@ -16,7 +18,7 @@ static const char *wstrerror(int err); /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int socket_open(void) { +LUASOCKET_PRIVATE int socket_open(void) { WSADATA wsaData; WORD wVersionRequested = MAKEWORD(2, 0); int err = WSAStartup(wVersionRequested, &wsaData ); @@ -32,7 +34,7 @@ int socket_open(void) { /*-------------------------------------------------------------------------*\ * Close module \*-------------------------------------------------------------------------*/ -int socket_close(void) { +LUASOCKET_PRIVATE int socket_close(void) { WSACleanup(); return 1; } @@ -45,7 +47,7 @@ int socket_close(void) { #define WAITFD_E 4 #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; fd_set rfds, wfds, efds, *rp = NULL, *wp = NULL, *ep = 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 \*-------------------------------------------------------------------------*/ -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) { struct timeval tv; 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 \*-------------------------------------------------------------------------*/ -void socket_destroy(p_socket ps) { +LUASOCKET_PRIVATE void socket_destroy(p_socket ps) { if (*ps != SOCKET_INVALID) { socket_setblocking(ps); /* close can take a long time on WIN32 */ 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); shutdown(*ps, how); socket_setnonblocking(ps); @@ -108,7 +110,7 @@ void socket_shutdown(p_socket ps, int how) { /*-------------------------------------------------------------------------*\ * 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); if (*ps != SOCKET_INVALID) return IO_DONE; else return WSAGetLastError(); @@ -117,7 +119,7 @@ int socket_create(p_socket ps, int domain, int type, int protocol) { /*-------------------------------------------------------------------------*\ * 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; /* don't call on closed socket */ 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 \*-------------------------------------------------------------------------*/ -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; socket_setblocking(ps); 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; socket_setblocking(ps); if (listen(*ps, backlog) < 0) err = WSAGetLastError(); @@ -168,7 +170,7 @@ int socket_listen(p_socket ps, int backlog) { /*-------------------------------------------------------------------------*\ * 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) { if (*ps == SOCKET_INVALID) return IO_CLOSED; 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. * 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) { int err; @@ -218,7 +220,7 @@ int socket_send(p_socket ps, const char *data, size_t count, /*-------------------------------------------------------------------------*\ * 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) { int err; @@ -239,7 +241,7 @@ int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, /*-------------------------------------------------------------------------*\ * 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) { 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 \*-------------------------------------------------------------------------*/ -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) { 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 \*-------------------------------------------------------------------------*/ -void socket_setblocking(p_socket ps) { +LUASOCKET_PRIVATE void socket_setblocking(p_socket ps) { u_long argp = 0; ioctlsocket(*ps, FIONBIO, &argp); } @@ -305,7 +307,7 @@ void socket_setblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * Put socket into non-blocking mode \*-------------------------------------------------------------------------*/ -void socket_setnonblocking(p_socket ps) { +LUASOCKET_PRIVATE void socket_setnonblocking(p_socket ps) { u_long argp = 1; ioctlsocket(*ps, FIONBIO, &argp); } @@ -313,13 +315,13 @@ void socket_setnonblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * 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); if (*hp) return IO_DONE; 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); if (*hp) return IO_DONE; else return WSAGetLastError(); @@ -328,7 +330,7 @@ int socket_gethostbyname(const char *addr, struct hostent **hp) { /*-------------------------------------------------------------------------*\ * Error translation functions \*-------------------------------------------------------------------------*/ -const char *socket_hoststrerror(int err) { +LUASOCKET_PRIVATE const char *socket_hoststrerror(int err) { if (err <= 0) return io_strerror(err); switch (err) { 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); switch (err) { 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; return socket_strerror(err); } -static const char *wstrerror(int err) { +LUASOCKET_PRIVATE static const char *wstrerror(int err) { switch (err) { case WSAEINTR: return "Interrupted function call"; 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; switch (err) { case EAI_AGAIN: return PIE_AGAIN; From 2d8f0d99011b267ed354ab6e8317d93b9627eed4 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:04:49 -0700 Subject: [PATCH 22/23] src/makefile: remove visibility and dllexport defines in favor of in-source labeling --- src/makefile | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/makefile b/src/makefile index cc1ec7e..74bf3d5 100644 --- a/src/makefile +++ b/src/makefile @@ -149,12 +149,8 @@ PLATS= macosx linux win32 mingw solaris SO_macosx=so O_macosx=o CC_macosx=gcc -DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' -CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common \ - -fvisibility=hidden +DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN +CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc SOCKET_macosx=usocket.o @@ -165,12 +161,9 @@ SOCKET_macosx=usocket.o SO_linux=so O_linux=o CC_linux=gcc -DEF_linux=-DLUASOCKET_$(DEBUG) \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' +DEF_linux=-DLUASOCKET_$(DEBUG) CFLAGS_linux=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ - -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden + -Wimplicit -O2 -ggdb3 -fpic LDFLAGS_linux=-O -shared -fpic -o LD_linux=gcc SOCKET_linux=usocket.o @@ -181,12 +174,9 @@ SOCKET_linux=usocket.o SO_freebsd=so O_freebsd=o CC_freebsd=gcc -DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' +DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN CFLAGS_freebsd=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ - -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden + -Wimplicit -O2 -ggdb3 -fpic LDFLAGS_freebsd=-O -shared -fpic -o LD_freebsd=gcc SOCKET_freebsd=usocket.o @@ -197,12 +187,9 @@ SOCKET_freebsd=usocket.o SO_solaris=so O_solaris=o CC_solaris=gcc -DEF_solaris=-DLUASOCKET_$(DEBUG) \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' +DEF_solaris=-DLUASOCKET_$(DEBUG) 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 LD_solaris=gcc SOCKET_solaris=usocket.o @@ -214,10 +201,8 @@ SO_mingw=dll O_mingw=o CC_mingw=gcc DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) \ - -DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \ - -DMIME_API='__declspec(dllexport)' -CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common \ - -fvisibility=hidden + -DWINVER=0x0501 +CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o LD_mingw=gcc SOCKET_mingw=wsocket.o @@ -230,8 +215,8 @@ SO_win32=dll O_win32=obj CC_win32=cl DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \ - //D "LUASOCKET_API=__declspec(dllexport)" //D "_CRT_SECURE_NO_WARNINGS" \ - //D "_WINDLL" //D "MIME_API=__declspec(dllexport)" \ + //D "_CRT_SECURE_NO_WARNINGS" \ + //D "_WINDLL" \ //D "LUASOCKET_$(DEBUG)" CFLAGS_win32=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo LDFLAGS_win32= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \ From e2e43d62fa925e7e22385505ed0c635255c77c0a Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:06:30 -0700 Subject: [PATCH 23/23] rockspecs: remove visibility and dllexport defines in favor of in-source labeling --- luasocket-scm-0.rockspec | 199 ++++++++++++++----------- rockspec/luasocket-3.0rc2-1.rockspec | 209 +++++++++++++++------------ 2 files changed, 231 insertions(+), 177 deletions(-) diff --git a/luasocket-scm-0.rockspec b/luasocket-scm-0.rockspec index c827e46..6cdb0ce 100644 --- a/luasocket-scm-0.rockspec +++ b/luasocket-scm-0.rockspec @@ -1,105 +1,132 @@ package = "LuaSocket" version = "scm-0" source = { - url = "https://github.com/diegonehab/luasocket/archive/master.zip", - dir = "luasocket-master", + url = "git://github.com/diegonehab/luasocket.git" + , branch="master" } description = { - summary = "Network support for the Lua language", - detailed = [[ + summary = "Network support for the Lua language", + detailed = [[ LuaSocket is a Lua extension library that is composed by two parts: a C core that provides support for the TCP and UDP transport layers, and a set of Lua modules that add support for functionality commonly needed by applications that deal with the Internet. ]], - homepage = "http://luaforge.net/projects/luasocket/", - license = "MIT" + homepage = "http://luaforge.net/projects/luasocket/", + license = "MIT" } dependencies = { - "lua >= 5.1" + "lua >= 5.1" } local function make_plat(plat) - local defines = { - unix = { - "LUASOCKET_DEBUG", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - macosx = { - "LUASOCKET_DEBUG", - "UNIX_HAS_SUN_LEN", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - win32 = { - "LUASOCKET_DEBUG", - "NDEBUG", - "LUASOCKET_API=__declspec(dllexport)", - "MIME_API=__declspec(dllexport)" - }, - mingw32 = { - "LUASOCKET_DEBUG", - "LUASOCKET_INET_PTON", - "WINVER=0x0501", - "LUASOCKET_API=__declspec(dllexport)", - "MIME_API=__declspec(dllexport)" - } - } - local modules = { - ["socket.core"] = { - sources = { "src/luasocket.c", "src/timeout.c", "src/buffer.c", "src/io.c", "src/auxiliar.c", "src/options.c", "src/inet.c", "src/except.c", "src/select.c", "src/tcp.c", "src/udp.c", "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["mime.core"] = { - sources = { "src/mime.c", "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["socket.http"] = "src/http.lua", - ["socket.url"] = "src/url.lua", - ["socket.tp"] = "src/tp.lua", - ["socket.ftp"] = "src/ftp.lua", - ["socket.headers"] = "src/headers.lua", - ["socket.smtp"] = "src/smtp.lua", - ltn12 = "src/ltn12.lua", - socket = "src/socket.lua", - mime = "src/mime.lua" - } - if plat == "unix" or plat == "macosx" or plat == "haiku" then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" - if plat == "haiku" then - modules["socket.core"].libraries = {"network"} - end - modules["socket.unix"] = { - sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/unix.c", "src/unixdgram.c", "src/unixstream.c" }, - defines = defines[plat], - incdir = "/src" - } - modules["socket.serial"] = { - sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/serial.c" }, - defines = defines[plat], - incdir = "/src" - } - end - if plat == "win32" or plat == "mingw32" then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" - modules["socket.core"].libraries = { "ws2_32" } - end - return { modules = modules } + local defines = { + unix = { + "LUASOCKET_DEBUG" + }, + macosx = { + "LUASOCKET_DEBUG", + "UNIX_HAS_SUN_LEN" + }, + win32 = { + "LUASOCKET_DEBUG", + "NDEBUG" + }, + mingw32 = { + "LUASOCKET_DEBUG", + "LUASOCKET_INET_PTON", + "WINVER=0x0501" + } + } + local modules = { + ["socket.core"] = { + sources = { + "src/luasocket.c" + , "src/timeout.c" + , "src/buffer.c" + , "src/io.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/inet.c" + , "src/except.c" + , "src/select.c" + , "src/tcp.c" + , "src/udp.c" + , "src/compat.c" }, + defines = defines[plat], + incdir = "/src" + }, + ["mime.core"] = { + sources = { "src/mime.c", "src/compat.c" }, + defines = defines[plat], + incdir = "/src" + }, + ["socket.http"] = "src/http.lua", + ["socket.url"] = "src/url.lua", + ["socket.tp"] = "src/tp.lua", + ["socket.ftp"] = "src/ftp.lua", + ["socket.headers"] = "src/headers.lua", + ["socket.smtp"] = "src/smtp.lua", + ltn12 = "src/ltn12.lua", + socket = "src/socket.lua", + mime = "src/mime.lua" + } + if plat == "unix" + or plat == "macosx" + or plat == "haiku" + then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" + if plat == "haiku" then + modules["socket.core"].libraries = {"network"} + end + modules["socket.unix"] = { + sources = { + "src/buffer.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/timeout.c" + , "src/io.c" + , "src/usocket.c" + , "src/unix.c" + , "src/unixdgram.c" + , "src/unixstream.c" }, + defines = defines[plat], + incdir = "/src" + } + modules["socket.serial"] = { + sources = { + "src/buffer.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/timeout.c" + , "src/io.c" + , "src/usocket.c" + , "src/serial.c" }, + defines = defines[plat], + incdir = "/src" + } + end + if plat == "win32" + or plat == "mingw32" + then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" + modules["socket.core"].libraries = { "ws2_32" } + end + return { modules = modules } end build = { - type = "builtin", - platforms = { - unix = make_plat("unix"), - macosx = make_plat("macosx"), - haiku = make_plat("haiku"), - win32 = make_plat("win32"), - mingw32 = make_plat("mingw32") - }, - copy_directories = { "doc", "samples", "etc", "test" } + type = "builtin", + platforms = { + unix = make_plat("unix"), + macosx = make_plat("macosx"), + haiku = make_plat("haiku"), + win32 = make_plat("win32"), + mingw32 = make_plat("mingw32") + }, + copy_directories = { + "doc" + , "samples" + , "etc" + , "test" } } diff --git a/rockspec/luasocket-3.0rc2-1.rockspec b/rockspec/luasocket-3.0rc2-1.rockspec index 8e37a4a..2b299f3 100644 --- a/rockspec/luasocket-3.0rc2-1.rockspec +++ b/rockspec/luasocket-3.0rc2-1.rockspec @@ -1,105 +1,132 @@ package = "LuaSocket" version = "3.0rc2-1" source = { - url = "git://github.com/diegonehab/luasocket.git", - tag = "v3.0-rc2", + url = "git://github.com/diegonehab/luasocket.git", + tag = "v3.0-rc2", } description = { - summary = "Network support for the Lua language", - detailed = [[ - LuaSocket is a Lua extension library that is composed by two parts: a C core - that provides support for the TCP and UDP transport layers, and a set of Lua - modules that add support for functionality commonly needed by applications - that deal with the Internet. - ]], - homepage = "http://luaforge.net/projects/luasocket/", - license = "MIT" + summary = "Network support for the Lua language", + detailed = [[ + LuaSocket is a Lua extension library that is composed by two parts: a C core + that provides support for the TCP and UDP transport layers, and a set of Lua + modules that add support for functionality commonly needed by applications + that deal with the Internet. + ]], + homepage = "http://luaforge.net/projects/luasocket/", + license = "MIT" } dependencies = { - "lua >= 5.1" + "lua >= 5.1" } local function make_plat(plat) - local defines = { - unix = { - "LUASOCKET_DEBUG", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - macosx = { - "LUASOCKET_DEBUG", - "UNIX_HAS_SUN_LEN", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - win32 = { - "LUASOCKET_DEBUG", - "NDEBUG", - "LUASOCKET_API=__declspec(dllexport)", - "MIME_API=__declspec(dllexport)" - }, - mingw32 = { - "LUASOCKET_DEBUG", - "LUASOCKET_INET_PTON", - "WINVER=0x0501", - "LUASOCKET_API=__declspec(dllexport)", - "MIME_API=__declspec(dllexport)" - } - } - local modules = { - ["socket.core"] = { - sources = { "src/luasocket.c", "src/timeout.c", "src/buffer.c", "src/io.c", "src/auxiliar.c", "src/options.c", "src/inet.c", "src/except.c", "src/select.c", "src/tcp.c", "src/udp.c", "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["mime.core"] = { - sources = { "src/mime.c", "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["socket.http"] = "src/http.lua", - ["socket.url"] = "src/url.lua", - ["socket.tp"] = "src/tp.lua", - ["socket.ftp"] = "src/ftp.lua", - ["socket.headers"] = "src/headers.lua", - ["socket.smtp"] = "src/smtp.lua", - ltn12 = "src/ltn12.lua", - socket = "src/socket.lua", - mime = "src/mime.lua" - } - if plat == "unix" or plat == "macosx" or plat == "haiku" then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" - if plat == "haiku" then - modules["socket.core"].libraries = {"network"} - end - modules["socket.unix"] = { - sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/unix.c" }, - defines = defines[plat], - incdir = "/src" - } - modules["socket.serial"] = { - sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/serial.c" }, - defines = defines[plat], - incdir = "/src" - } - end - if plat == "win32" or plat == "mingw32" then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" - modules["socket.core"].libraries = { "ws2_32" } - end - return { modules = modules } + local defines = { + unix = { + "LUASOCKET_DEBUG" + }, + macosx = { + "LUASOCKET_DEBUG", + "UNIX_HAS_SUN_LEN" + }, + win32 = { + "LUASOCKET_DEBUG", + "NDEBUG" + }, + mingw32 = { + "LUASOCKET_DEBUG", + "LUASOCKET_INET_PTON", + "WINVER=0x0501" + } + } + local modules = { + ["socket.core"] = { + sources = { + "src/luasocket.c" + , "src/timeout.c" + , "src/buffer.c" + , "src/io.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/inet.c" + , "src/except.c" + , "src/select.c" + , "src/tcp.c" + , "src/udp.c" + , "src/compat.c" }, + defines = defines[plat], + incdir = "/src" + }, + ["mime.core"] = { + sources = { "src/mime.c", "src/compat.c" }, + defines = defines[plat], + incdir = "/src" + }, + ["socket.http"] = "src/http.lua", + ["socket.url"] = "src/url.lua", + ["socket.tp"] = "src/tp.lua", + ["socket.ftp"] = "src/ftp.lua", + ["socket.headers"] = "src/headers.lua", + ["socket.smtp"] = "src/smtp.lua", + ltn12 = "src/ltn12.lua", + socket = "src/socket.lua", + mime = "src/mime.lua" + } + if plat == "unix" + or plat == "macosx" + or plat == "haiku" + then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" + if plat == "haiku" then + modules["socket.core"].libraries = {"network"} + end + modules["socket.unix"] = { + sources = { + "src/buffer.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/timeout.c" + , "src/io.c" + , "src/usocket.c" + , "src/unix.c" + , "src/unixdgram.c" + , "src/unixstream.c" }, + defines = defines[plat], + incdir = "/src" + } + modules["socket.serial"] = { + sources = { + "src/buffer.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/timeout.c" + , "src/io.c" + , "src/usocket.c" + , "src/serial.c" }, + defines = defines[plat], + incdir = "/src" + } + end + if plat == "win32" + or plat == "mingw32" + then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" + modules["socket.core"].libraries = { "ws2_32" } + end + return { modules = modules } end build = { - type = "builtin", - platforms = { - unix = make_plat("unix"), - macosx = make_plat("macosx"), - haiku = make_plat("haiku"), - win32 = make_plat("win32"), - mingw32 = make_plat("mingw32") - }, - copy_directories = { "doc", "samples", "etc", "test" } + type = "builtin", + platforms = { + unix = make_plat("unix"), + macosx = make_plat("macosx"), + haiku = make_plat("haiku"), + win32 = make_plat("win32"), + mingw32 = make_plat("mingw32") + }, + copy_directories = { + "doc" + , "samples" + , "etc" + , "test" } }