From 5d52ffedf49ca14af2926eac9ddbf9bfc5e8c56c Mon Sep 17 00:00:00 2001 From: Jonas Kunze Date: Fri, 15 Jan 2016 18:48:57 +0100 Subject: Added solaris platform To compile on solaris some libs had to be linked. So far I was only able to test it on OmniOS r151006 --- src/makefile | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index 3e8c128..adf687f 100644 --- a/src/makefile +++ b/src/makefile @@ -55,7 +55,7 @@ LDIR_linux?=share/lua/$(LUAV) # LUAINC_freebsd: # /usr/local/include/lua$(LUAV) -# where lua headers are found for linux builds +# where lua headers are found for freebsd builds LUAINC_freebsd_base?=/usr/local/include/ LUAINC_freebsd?=$(LUAINC_freebsd_base)/lua$(LUAV) LUAPREFIX_freebsd?=/usr/local/ @@ -86,6 +86,13 @@ LUALIB_win32?=$(LUAPREFIX_win32)/lib/lua/$(LUAV)/$(PLATFORM_win32) LUALIBNAME_win32?=lua$(subst .,,$(LUAV)).lib +# LUAINC_solaris: +LUAINC_solaris_base?=/usr/include +LUAINC_solaris?=$(LUAINC_solaris_base)/lua/$(LUAV) +LUAPREFIX_solaris?=/usr/local +CDIR_solaris?=lib/lua/$(LUAV) +LDIR_solaris?=share/lua/$(LUAV) + # prefix: /usr/local /usr /opt/local /sw # the top of the default install tree prefix?=$(LUAPREFIX_$(PLAT)) @@ -132,7 +139,7 @@ print: #------ # Supported platforms # -PLATS= macosx linux win32 mingw +PLATS= macosx linux win32 mingw solaris #------ # Compiler and linker settings @@ -182,6 +189,22 @@ LDFLAGS_freebsd=-O -shared -fpic -o LD_freebsd=gcc SOCKET_freebsd=usocket.o +#------ +# Compiler and linker settings +# for Solaris +SO_solaris=so +O_solaris=o +CC_solaris=gcc +DEF_solaris=-DLUASOCKET_$(DEBUG) \ + -DLUASOCKET_API='__attribute__((visibility("default")))' \ + -DUNIX_API='__attribute__((visibility("default")))' \ + -DMIME_API='__attribute__((visibility("default")))' +CFLAGS_solaris=-I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \ + -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden +LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o +LD_solaris=gcc +SOCKET_solaris=usocket.o + #------ # Compiler and linker settings # for MingW @@ -332,6 +355,9 @@ linux: mingw: $(MAKE) all PLAT=mingw + +solaris: + $(MAKE) all-unix PLAT=solaris none: @echo "Please run" -- cgit v1.2.3-55-g6feb From 624924a77b5ea905c6bdb7607f0fae50ce58c5f7 Mon Sep 17 00:00:00 2001 From: Jonas Kunze Date: Tue, 12 Apr 2016 13:06:47 +0200 Subject: Enabled overwriting of MYCF/MYLDFlAGS --- src/makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index adf687f..2e00950 100644 --- a/src/makefile +++ b/src/makefile @@ -21,10 +21,10 @@ PLAT?=linux LUAV?=5.1 # MYCFLAGS: to be set by user if needed -MYCFLAGS= +MYCFLAGS?= # MYLDFLAGS: to be set by user if needed -MYLDFLAGS= +MYLDFLAGS?= # DEBUG: NODEBUG DEBUG # debug mode causes luasocket to collect and returns timing information useful @@ -135,6 +135,8 @@ print: @echo LUALIB_$(PLAT)=$(LUALIB_$(PLAT)) @echo INSTALL_TOP_CDIR=$(INSTALL_TOP_CDIR) @echo INSTALL_TOP_LDIR=$(INSTALL_TOP_LDIR) + @echo CFLAGS=$(CFLAGS) + @echo LDFLAGS=$(LDFLAGS) #------ # Supported platforms -- cgit v1.2.3-55-g6feb From aa1b8cc9bc35e56de15eeb153c899e4c51de82a8 Mon Sep 17 00:00:00 2001 From: enginix Date: Fri, 24 Jun 2016 21:23:00 +0800 Subject: support datagram unix domain sockets --- src/makefile | 2 + src/unix.c | 328 ++----------------------------------------- src/unixtcp.c | 338 ++++++++++++++++++++++++++++++++++++++++++++ src/unixtcp.h | 21 +++ src/unixudp.c | 388 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/unixudp.h | 20 +++ test/unixclnt.lua | 8 -- test/unixsrvr.lua | 9 -- test/unixtcpclnt.lua | 8 ++ test/unixtcpsrvr.lua | 9 ++ test/unixudpclnt.lua | 9 ++ test/unixudpsrvr.lua | 9 ++ 12 files changed, 818 insertions(+), 331 deletions(-) create mode 100644 src/unixtcp.c create mode 100644 src/unixtcp.h create mode 100644 src/unixudp.c create mode 100644 src/unixudp.h delete mode 100644 test/unixclnt.lua delete mode 100644 test/unixsrvr.lua create mode 100644 test/unixtcpclnt.lua create mode 100644 test/unixtcpsrvr.lua create mode 100644 test/unixudpclnt.lua create mode 100644 test/unixudpsrvr.lua (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index 2e00950..0e4a544 100644 --- a/src/makefile +++ b/src/makefile @@ -307,6 +307,8 @@ UNIX_OBJS=\ timeout.$(O) \ io.$(O) \ usocket.$(O) \ + unixtcp.$(O) \ + unixudp.$(O) \ unix.$(O) #------ diff --git a/src/unix.c b/src/unix.c index 5bc3148..2009c19 100644 --- a/src/unix.c +++ b/src/unix.c @@ -2,329 +2,29 @@ * Unix domain socket * LuaSocket toolkit \*=========================================================================*/ -#include - #include "lua.h" #include "lauxlib.h" -#include "auxiliar.h" -#include "socket.h" -#include "options.h" -#include "unix.h" -#include - -/*=========================================================================*\ -* Internal function prototypes -\*=========================================================================*/ -static int global_create(lua_State *L); -static int meth_connect(lua_State *L); -static int meth_listen(lua_State *L); -static int meth_bind(lua_State *L); -static int meth_send(lua_State *L); -static int meth_shutdown(lua_State *L); -static int meth_receive(lua_State *L); -static int meth_accept(lua_State *L); -static int meth_close(lua_State *L); -static int meth_setoption(lua_State *L); -static int meth_settimeout(lua_State *L); -static int meth_getfd(lua_State *L); -static int meth_setfd(lua_State *L); -static int meth_dirty(lua_State *L); -static int meth_getstats(lua_State *L); -static int meth_setstats(lua_State *L); - -static const char *unix_tryconnect(p_unix un, const char *path); -static const char *unix_trybind(p_unix un, const char *path); - -/* unix object methods */ -static luaL_Reg unix_methods[] = { - {"__gc", meth_close}, - {"__tostring", auxiliar_tostring}, - {"accept", meth_accept}, - {"bind", meth_bind}, - {"close", meth_close}, - {"connect", meth_connect}, - {"dirty", meth_dirty}, - {"getfd", meth_getfd}, - {"getstats", meth_getstats}, - {"setstats", meth_setstats}, - {"listen", meth_listen}, - {"receive", meth_receive}, - {"send", meth_send}, - {"setfd", meth_setfd}, - {"setoption", meth_setoption}, - {"setpeername", meth_connect}, - {"setsockname", meth_bind}, - {"settimeout", meth_settimeout}, - {"shutdown", meth_shutdown}, - {NULL, NULL} -}; - -/* socket option handlers */ -static t_opt optset[] = { - {"keepalive", opt_set_keepalive}, - {"reuseaddr", opt_set_reuseaddr}, - {"linger", opt_set_linger}, - {NULL, NULL} -}; - -/*-------------------------------------------------------------------------*\ -* Initializes module -\*-------------------------------------------------------------------------*/ -int luaopen_socket_unix(lua_State *L) { - /* create classes */ - auxiliar_newclass(L, "unix{master}", unix_methods); - auxiliar_newclass(L, "unix{client}", unix_methods); - auxiliar_newclass(L, "unix{server}", unix_methods); - /* create class groups */ - auxiliar_add2group(L, "unix{master}", "unix{any}"); - auxiliar_add2group(L, "unix{client}", "unix{any}"); - auxiliar_add2group(L, "unix{server}", "unix{any}"); - /* return the function instead of the 'socket' table */ - lua_pushcfunction(L, global_create); - return 1; -} - -/*=========================================================================*\ -* Lua methods -\*=========================================================================*/ -/*-------------------------------------------------------------------------*\ -* Just call buffered IO methods -\*-------------------------------------------------------------------------*/ -static int meth_send(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unix{client}", 1); - return buffer_meth_send(L, &un->buf); -} - -static int meth_receive(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unix{client}", 1); - return buffer_meth_receive(L, &un->buf); -} - -static int meth_getstats(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unix{client}", 1); - return buffer_meth_getstats(L, &un->buf); -} - -static int meth_setstats(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unix{client}", 1); - return buffer_meth_setstats(L, &un->buf); -} - -/*-------------------------------------------------------------------------*\ -* Just call option handler -\*-------------------------------------------------------------------------*/ -static int meth_setoption(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unix{any}", 1); - return opt_meth_setoption(L, optset, &un->sock); -} - -/*-------------------------------------------------------------------------*\ -* Select support methods -\*-------------------------------------------------------------------------*/ -static int meth_getfd(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unix{any}", 1); - lua_pushnumber(L, (int) un->sock); - return 1; -} - -/* this is very dangerous, but can be handy for those that are brave enough */ -static int meth_setfd(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unix{any}", 1); - un->sock = (t_socket) luaL_checknumber(L, 2); - return 0; -} - -static int meth_dirty(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unix{any}", 1); - lua_pushboolean(L, !buffer_isempty(&un->buf)); - return 1; -} +#include "unixtcp.h" +#include "unixudp.h" /*-------------------------------------------------------------------------*\ -* Waits for and returns a client object attempting connection to the -* server object +* Modules and functions \*-------------------------------------------------------------------------*/ -static int meth_accept(lua_State *L) { - p_unix server = (p_unix) auxiliar_checkclass(L, "unix{server}", 1); - p_timeout tm = timeout_markstart(&server->tm); - t_socket sock; - int err = socket_accept(&server->sock, &sock, NULL, NULL, tm); - /* if successful, push client socket */ - if (err == IO_DONE) { - p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix)); - auxiliar_setclass(L, "unix{client}", -1); - /* initialize structure fields */ - socket_setnonblocking(&sock); - clnt->sock = sock; - io_init(&clnt->io, (p_send)socket_send, (p_recv)socket_recv, - (p_error) socket_ioerror, &clnt->sock); - timeout_init(&clnt->tm, -1, -1); - buffer_init(&clnt->buf, &clnt->io, &clnt->tm); - return 1; - } else { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } -} - -/*-------------------------------------------------------------------------*\ -* Binds an object to an address -\*-------------------------------------------------------------------------*/ -static const char *unix_trybind(p_unix un, const char *path) { - struct sockaddr_un local; - size_t len = strlen(path); - int err; - if (len >= sizeof(local.sun_path)) return "path too long"; - memset(&local, 0, sizeof(local)); - strcpy(local.sun_path, path); - local.sun_family = AF_UNIX; -#ifdef UNIX_HAS_SUN_LEN - local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) - + len + 1; - err = socket_bind(&un->sock, (SA *) &local, local.sun_len); - -#else - err = socket_bind(&un->sock, (SA *) &local, - sizeof(local.sun_family) + len); -#endif - if (err != IO_DONE) socket_destroy(&un->sock); - return socket_strerror(err); -} - -static int meth_bind(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unix{master}", 1); - const char *path = luaL_checkstring(L, 2); - const char *err = unix_trybind(un, path); - if (err) { - lua_pushnil(L); - lua_pushstring(L, err); - return 2; - } - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Turns a master unix object into a client object. -\*-------------------------------------------------------------------------*/ -static const char *unix_tryconnect(p_unix un, const char *path) -{ - struct sockaddr_un remote; - int err; - size_t len = strlen(path); - if (len >= sizeof(remote.sun_path)) return "path too long"; - memset(&remote, 0, sizeof(remote)); - strcpy(remote.sun_path, path); - remote.sun_family = AF_UNIX; - timeout_markstart(&un->tm); -#ifdef UNIX_HAS_SUN_LEN - remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) - + len + 1; - err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); -#else - err = socket_connect(&un->sock, (SA *) &remote, - sizeof(remote.sun_family) + len, &un->tm); -#endif - if (err != IO_DONE) socket_destroy(&un->sock); - return socket_strerror(err); -} - -static int meth_connect(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unix{master}", 1); - const char *path = luaL_checkstring(L, 2); - const char *err = unix_tryconnect(un, path); - if (err) { - lua_pushnil(L); - lua_pushstring(L, err); - return 2; - } - /* turn master object into a client object */ - auxiliar_setclass(L, "unix{client}", 1); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Closes socket used by object -\*-------------------------------------------------------------------------*/ -static int meth_close(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unix{any}", 1); - socket_destroy(&un->sock); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Puts the sockt in listen mode -\*-------------------------------------------------------------------------*/ -static int meth_listen(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unix{master}", 1); - int backlog = (int) luaL_optnumber(L, 2, 32); - int err = socket_listen(&un->sock, backlog); - if (err != IO_DONE) { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } - /* turn master object into a server object */ - auxiliar_setclass(L, "unix{server}", 1); - lua_pushnumber(L, 1); - return 1; -} +static const luaL_Reg mod[] = { + {"tcp", unixtcp_open}, + {"udp", unixudp_open}, + {NULL, NULL} +}; /*-------------------------------------------------------------------------*\ -* Shuts the connection down partially +* Initializes module \*-------------------------------------------------------------------------*/ -static int meth_shutdown(lua_State *L) +int luaopen_socket_unix(lua_State *L) { - /* SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2, so we can use method index directly */ - static const char* methods[] = { "receive", "send", "both", NULL }; - p_unix tcp = (p_unix) auxiliar_checkclass(L, "unix{client}", 1); - int how = luaL_checkoption(L, 2, "both", methods); - socket_shutdown(&tcp->sock, how); - lua_pushnumber(L, 1); - return 1; + int i; + lua_newtable(L); + for (i = 0; mod[i].name; i++) mod[i].func(L); + return 1; } -/*-------------------------------------------------------------------------*\ -* Just call tm methods -\*-------------------------------------------------------------------------*/ -static int meth_settimeout(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unix{any}", 1); - return timeout_meth_settimeout(L, &un->tm); -} - -/*=========================================================================*\ -* Library functions -\*=========================================================================*/ -/*-------------------------------------------------------------------------*\ -* Creates a master unix object -\*-------------------------------------------------------------------------*/ -static int global_create(lua_State *L) { - t_socket sock; - int err = socket_create(&sock, AF_UNIX, SOCK_STREAM, 0); - /* try to allocate a system socket */ - if (err == IO_DONE) { - /* allocate unix object */ - p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); - /* set its type as master object */ - auxiliar_setclass(L, "unix{master}", -1); - /* initialize remaining structure fields */ - socket_setnonblocking(&sock); - un->sock = sock; - io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, - (p_error) socket_ioerror, &un->sock); - timeout_init(&un->tm, -1, -1); - buffer_init(&un->buf, &un->io, &un->tm); - return 1; - } else { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } -} diff --git a/src/unixtcp.c b/src/unixtcp.c new file mode 100644 index 0000000..88baac0 --- /dev/null +++ b/src/unixtcp.c @@ -0,0 +1,338 @@ +/*=========================================================================*\ +* Unix domain socket tcp sub module +* LuaSocket toolkit +\*=========================================================================*/ +#include + +#include "lua.h" +#include "lauxlib.h" + +#include "auxiliar.h" +#include "socket.h" +#include "options.h" +#include "unixtcp.h" +#include + +/*=========================================================================*\ +* Internal function prototypes +\*=========================================================================*/ +static int global_create(lua_State *L); +static int meth_connect(lua_State *L); +static int meth_listen(lua_State *L); +static int meth_bind(lua_State *L); +static int meth_send(lua_State *L); +static int meth_shutdown(lua_State *L); +static int meth_receive(lua_State *L); +static int meth_accept(lua_State *L); +static int meth_close(lua_State *L); +static int meth_setoption(lua_State *L); +static int meth_settimeout(lua_State *L); +static int meth_getfd(lua_State *L); +static int meth_setfd(lua_State *L); +static int meth_dirty(lua_State *L); +static int meth_getstats(lua_State *L); +static int meth_setstats(lua_State *L); + +static const char *unixtcp_tryconnect(p_unix un, const char *path); +static const char *unixtcp_trybind(p_unix un, const char *path); + +/* unixtcp object methods */ +static luaL_Reg unixtcp_methods[] = { + {"__gc", meth_close}, + {"__tostring", auxiliar_tostring}, + {"accept", meth_accept}, + {"bind", meth_bind}, + {"close", meth_close}, + {"connect", meth_connect}, + {"dirty", meth_dirty}, + {"getfd", meth_getfd}, + {"getstats", meth_getstats}, + {"setstats", meth_setstats}, + {"listen", meth_listen}, + {"receive", meth_receive}, + {"send", meth_send}, + {"setfd", meth_setfd}, + {"setoption", meth_setoption}, + {"setpeername", meth_connect}, + {"setsockname", meth_bind}, + {"settimeout", meth_settimeout}, + {"shutdown", meth_shutdown}, + {NULL, NULL} +}; + +/* socket option handlers */ +static t_opt optset[] = { + {"keepalive", opt_set_keepalive}, + {"reuseaddr", opt_set_reuseaddr}, + {"linger", opt_set_linger}, + {NULL, NULL} +}; + +/* functions in library namespace */ +static luaL_Reg func[] = { + {"tcp", global_create}, + {NULL, NULL} +}; + +/*-------------------------------------------------------------------------*\ +* Initializes module +\*-------------------------------------------------------------------------*/ +int unixtcp_open(lua_State *L) +{ + /* create classes */ + auxiliar_newclass(L, "unixtcp{master}", unixtcp_methods); + auxiliar_newclass(L, "unixtcp{client}", unixtcp_methods); + auxiliar_newclass(L, "unixtcp{server}", unixtcp_methods); + + /* create class groups */ + auxiliar_add2group(L, "unixtcp{master}", "unixtcp{any}"); + auxiliar_add2group(L, "unixtcp{client}", "unixtcp{any}"); + auxiliar_add2group(L, "unixtcp{server}", "unixtcp{any}"); + + luaL_setfuncs(L, func, 0); + return 1; +} + +/*=========================================================================*\ +* Lua methods +\*=========================================================================*/ +/*-------------------------------------------------------------------------*\ +* Just call buffered IO methods +\*-------------------------------------------------------------------------*/ +static int meth_send(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); + return buffer_meth_send(L, &un->buf); +} + +static int meth_receive(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); + return buffer_meth_receive(L, &un->buf); +} + +static int meth_getstats(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); + return buffer_meth_getstats(L, &un->buf); +} + +static int meth_setstats(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); + return buffer_meth_setstats(L, &un->buf); +} + +/*-------------------------------------------------------------------------*\ +* Just call option handler +\*-------------------------------------------------------------------------*/ +static int meth_setoption(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); + return opt_meth_setoption(L, optset, &un->sock); +} + +/*-------------------------------------------------------------------------*\ +* Select support methods +\*-------------------------------------------------------------------------*/ +static int meth_getfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); + lua_pushnumber(L, (int) un->sock); + return 1; +} + +/* this is very dangerous, but can be handy for those that are brave enough */ +static int meth_setfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); + un->sock = (t_socket) luaL_checknumber(L, 2); + return 0; +} + +static int meth_dirty(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); + lua_pushboolean(L, !buffer_isempty(&un->buf)); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Waits for and returns a client object attempting connection to the +* server object +\*-------------------------------------------------------------------------*/ +static int meth_accept(lua_State *L) { + p_unix server = (p_unix) auxiliar_checkclass(L, "unixtcp{server}", 1); + p_timeout tm = timeout_markstart(&server->tm); + t_socket sock; + int err = socket_accept(&server->sock, &sock, NULL, NULL, tm); + /* if successful, push client socket */ + if (err == IO_DONE) { + p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix)); + auxiliar_setclass(L, "unixtcp{client}", -1); + /* initialize structure fields */ + socket_setnonblocking(&sock); + clnt->sock = sock; + io_init(&clnt->io, (p_send)socket_send, (p_recv)socket_recv, + (p_error) socket_ioerror, &clnt->sock); + timeout_init(&clnt->tm, -1, -1); + buffer_init(&clnt->buf, &clnt->io, &clnt->tm); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } +} + +/*-------------------------------------------------------------------------*\ +* Binds an object to an address +\*-------------------------------------------------------------------------*/ +static const char *unixtcp_trybind(p_unix un, const char *path) { + struct sockaddr_un local; + size_t len = strlen(path); + int err; + if (len >= sizeof(local.sun_path)) return "path too long"; + memset(&local, 0, sizeof(local)); + strcpy(local.sun_path, path); + local.sun_family = AF_UNIX; +#ifdef UNIX_HAS_SUN_LEN + local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) + + len + 1; + err = socket_bind(&un->sock, (SA *) &local, local.sun_len); + +#else + err = socket_bind(&un->sock, (SA *) &local, + sizeof(local.sun_family) + len); +#endif + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_bind(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixtcp_trybind(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Turns a master unixtcp object into a client object. +\*-------------------------------------------------------------------------*/ +static const char *unixtcp_tryconnect(p_unix un, const char *path) +{ + struct sockaddr_un remote; + int err; + size_t len = strlen(path); + if (len >= sizeof(remote.sun_path)) return "path too long"; + memset(&remote, 0, sizeof(remote)); + strcpy(remote.sun_path, path); + remote.sun_family = AF_UNIX; + timeout_markstart(&un->tm); +#ifdef UNIX_HAS_SUN_LEN + remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) + + len + 1; + err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); +#else + err = socket_connect(&un->sock, (SA *) &remote, + sizeof(remote.sun_family) + len, &un->tm); +#endif + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_connect(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixtcp_tryconnect(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + /* turn master object into a client object */ + auxiliar_setclass(L, "unixtcp{client}", 1); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Closes socket used by object +\*-------------------------------------------------------------------------*/ +static int meth_close(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); + socket_destroy(&un->sock); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Puts the sockt in listen mode +\*-------------------------------------------------------------------------*/ +static int meth_listen(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); + int backlog = (int) luaL_optnumber(L, 2, 32); + int err = socket_listen(&un->sock, backlog); + if (err != IO_DONE) { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } + /* turn master object into a server object */ + auxiliar_setclass(L, "unixtcp{server}", 1); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Shuts the connection down partially +\*-------------------------------------------------------------------------*/ +static int meth_shutdown(lua_State *L) +{ + /* SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2, so we can use method index directly */ + static const char* methods[] = { "receive", "send", "both", NULL }; + p_unix tcp = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); + int how = luaL_checkoption(L, 2, "both", methods); + socket_shutdown(&tcp->sock, how); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Just call tm methods +\*-------------------------------------------------------------------------*/ +static int meth_settimeout(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); + return timeout_meth_settimeout(L, &un->tm); +} + +/*=========================================================================*\ +* Library functions +\*=========================================================================*/ +/*-------------------------------------------------------------------------*\ +* Creates a master unixtcp object +\*-------------------------------------------------------------------------*/ +static int global_create(lua_State *L) { + t_socket sock; + int err = socket_create(&sock, AF_UNIX, SOCK_STREAM, 0); + /* try to allocate a system socket */ + if (err == IO_DONE) { + /* allocate unixtcp object */ + p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); + /* set its type as master object */ + auxiliar_setclass(L, "unixtcp{master}", -1); + /* initialize remaining structure fields */ + socket_setnonblocking(&sock); + un->sock = sock; + io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, + (p_error) socket_ioerror, &un->sock); + timeout_init(&un->tm, -1, -1); + buffer_init(&un->buf, &un->io, &un->tm); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } +} diff --git a/src/unixtcp.h b/src/unixtcp.h new file mode 100644 index 0000000..0eababc --- /dev/null +++ b/src/unixtcp.h @@ -0,0 +1,21 @@ +#ifndef UNIXTCP_H +#define UNIXTCP_H +/*=========================================================================*\ +* UNIX TCP object +* LuaSocket toolkit +* +* The unixtcp.h module is basicly a glue that puts together modules buffer.h, +* timeout.h socket.h and inet.h to provide the LuaSocket UNIX TCP (AF_UNIX, +* SOCK_STREAM) support. +* +* Three classes are defined: master, client and server. The master class is +* a newly created unixtcp object, that has not been bound or connected. Server +* objects are unixtcp objects bound to some local address. Client objects are +* unixtcp objects either connected to some address or returned by the accept +* method of a server object. +\*=========================================================================*/ +#include "unix.h" + +int unixtcp_open(lua_State *L); + +#endif /* UNIXTCP_H */ diff --git a/src/unixudp.c b/src/unixudp.c new file mode 100644 index 0000000..ec348cf --- /dev/null +++ b/src/unixudp.c @@ -0,0 +1,388 @@ +/*=========================================================================*\ +* Unix domain socket udp submodule +* LuaSocket toolkit +\*=========================================================================*/ +#include +#include + +#include "lua.h" +#include "lauxlib.h" + +#include "auxiliar.h" +#include "socket.h" +#include "options.h" +#include "unix.h" +#include + +#define UNIXUDP_DATAGRAMSIZE 8192 + +/*=========================================================================*\ +* Internal function prototypes +\*=========================================================================*/ +static int global_create(lua_State *L); +static int meth_connect(lua_State *L); +static int meth_bind(lua_State *L); +static int meth_send(lua_State *L); +static int meth_receive(lua_State *L); +static int meth_close(lua_State *L); +static int meth_setoption(lua_State *L); +static int meth_settimeout(lua_State *L); +static int meth_gettimeout(lua_State *L); +static int meth_getfd(lua_State *L); +static int meth_setfd(lua_State *L); +static int meth_dirty(lua_State *L); +static int meth_receivefrom(lua_State *L); +static int meth_sendto(lua_State *L); + +static const char *unixudp_tryconnect(p_unix un, const char *path); +static const char *unixudp_trybind(p_unix un, const char *path); + +/* unixudp object methods */ +static luaL_Reg unixudp_methods[] = { + {"__gc", meth_close}, + {"__tostring", auxiliar_tostring}, + {"bind", meth_bind}, + {"close", meth_close}, + {"connect", meth_connect}, + {"dirty", meth_dirty}, + {"getfd", meth_getfd}, + {"send", meth_send}, + {"sendto", meth_sendto}, + {"receive", meth_receive}, + {"receivefrom", meth_receivefrom}, + {"setfd", meth_setfd}, + {"setoption", meth_setoption}, + {"setpeername", meth_connect}, + {"setsockname", meth_bind}, + {"settimeout", meth_settimeout}, + {"gettimeout", meth_gettimeout}, + {NULL, NULL} +}; + +/* socket option handlers */ +static t_opt optset[] = { + {"reuseaddr", opt_set_reuseaddr}, + {NULL, NULL} +}; + +/* functions in library namespace */ +static luaL_Reg func[] = { + {"udp", global_create}, + {NULL, NULL} +}; + +/*-------------------------------------------------------------------------*\ +* Initializes module +\*-------------------------------------------------------------------------*/ +int unixudp_open(lua_State *L) +{ + /* create classes */ + auxiliar_newclass(L, "unixudp{connected}", unixudp_methods); + auxiliar_newclass(L, "unixudp{unconnected}", unixudp_methods); + /* create class groups */ + auxiliar_add2group(L, "unixudp{connected}", "unixudp{any}"); + auxiliar_add2group(L, "unixudp{unconnected}", "unixudp{any}"); + auxiliar_add2group(L, "unixudp{connected}", "select{able}"); + auxiliar_add2group(L, "unixudp{unconnected}", "select{able}"); + + luaL_setfuncs(L, func, 0); + return 1; +} + +/*=========================================================================*\ +* Lua methods +\*=========================================================================*/ +static const char *unixudp_strerror(int err) +{ + /* a 'closed' error on an unconnected means the target address was not + * accepted by the transport layer */ + if (err == IO_CLOSED) return "refused"; + else return socket_strerror(err); +} + +static int meth_send(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{connected}", 1); + p_timeout tm = &un->tm; + size_t count, sent = 0; + int err; + const char *data = luaL_checklstring(L, 2, &count); + timeout_markstart(tm); + err = socket_send(&un->sock, data, count, &sent, tm); + if (err != IO_DONE) { + lua_pushnil(L); + lua_pushstring(L, unixudp_strerror(err)); + return 2; + } + lua_pushnumber(L, (lua_Number) sent); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Send data through unconnected unixudp socket +\*-------------------------------------------------------------------------*/ +static int meth_sendto(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); + size_t count, sent = 0; + const char *data = luaL_checklstring(L, 2, &count); + const char *path = luaL_checkstring(L, 3); + p_timeout tm = &un->tm; + int err; + struct sockaddr_un remote; + size_t len = strlen(path); + + if (len >= sizeof(remote.sun_path)) { + lua_pushnil(L); + lua_pushstring(L, "path too long"); + return 2; + } + + memset(&remote, 0, sizeof(remote)); + strcpy(remote.sun_path, path); + remote.sun_family = AF_UNIX; + timeout_markstart(tm); +#ifdef UNIX_HAS_SUN_LEN + remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) + + len + 1; + err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, remote.sun_len, tm); +#else + err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, + sizeof(remote.sun_family) + len, tm); +#endif + if (err != IO_DONE) { + lua_pushnil(L); + lua_pushstring(L, unixudp_strerror(err)); + return 2; + } + lua_pushnumber(L, (lua_Number) sent); + return 1; +} + +static int meth_receive(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{any}", 1); + char buf[UNIXUDP_DATAGRAMSIZE]; + size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); + char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; + int err; + p_timeout tm = &un->tm; + timeout_markstart(tm); + if (!dgram) { + lua_pushnil(L); + lua_pushliteral(L, "out of memory"); + return 2; + } + err = socket_recv(&un->sock, dgram, wanted, &got, tm); + /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ + if (err != IO_DONE && err != IO_CLOSED) { + lua_pushnil(L); + lua_pushstring(L, unixudp_strerror(err)); + if (wanted > sizeof(buf)) free(dgram); + return 2; + } + lua_pushlstring(L, dgram, got); + if (wanted > sizeof(buf)) free(dgram); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Receives data and sender from a UDP socket +\*-------------------------------------------------------------------------*/ +static int meth_receivefrom(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); + char buf[UNIXUDP_DATAGRAMSIZE]; + size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); + char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; + struct sockaddr_un addr; + socklen_t addr_len = sizeof(addr); + int err; + p_timeout tm = &un->tm; + timeout_markstart(tm); + if (!dgram) { + lua_pushnil(L); + lua_pushliteral(L, "out of memory"); + return 2; + } + err = socket_recvfrom(&un->sock, dgram, wanted, &got, (SA *) &addr, + &addr_len, tm); + /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ + if (err != IO_DONE && err != IO_CLOSED) { + lua_pushnil(L); + lua_pushstring(L, unixudp_strerror(err)); + if (wanted > sizeof(buf)) free(dgram); + return 2; + } + + lua_pushlstring(L, dgram, got); + /* the path may be empty, when client send without bind */ + lua_pushstring(L, addr.sun_path); + if (wanted > sizeof(buf)) free(dgram); + return 2; +} + +/*-------------------------------------------------------------------------*\ +* Just call option handler +\*-------------------------------------------------------------------------*/ +static int meth_setoption(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); + return opt_meth_setoption(L, optset, &un->sock); +} + +/*-------------------------------------------------------------------------*\ +* Select support methods +\*-------------------------------------------------------------------------*/ +static int meth_getfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); + lua_pushnumber(L, (int) un->sock); + return 1; +} + +/* this is very dangerous, but can be handy for those that are brave enough */ +static int meth_setfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); + un->sock = (t_socket) luaL_checknumber(L, 2); + return 0; +} + +static int meth_dirty(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); + (void) un; + lua_pushboolean(L, 0); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Binds an object to an address +\*-------------------------------------------------------------------------*/ +static const char *unixudp_trybind(p_unix un, const char *path) { + struct sockaddr_un local; + size_t len = strlen(path); + int err; + if (len >= sizeof(local.sun_path)) return "path too long"; + memset(&local, 0, sizeof(local)); + strcpy(local.sun_path, path); + local.sun_family = AF_UNIX; +#ifdef UNIX_HAS_SUN_LEN + local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) + + len + 1; + err = socket_bind(&un->sock, (SA *) &local, local.sun_len); + +#else + err = socket_bind(&un->sock, (SA *) &local, + sizeof(local.sun_family) + len); +#endif + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_bind(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixudp_trybind(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Turns a master unixudp object into a client object. +\*-------------------------------------------------------------------------*/ +static const char *unixudp_tryconnect(p_unix un, const char *path) +{ + struct sockaddr_un remote; + int err; + size_t len = strlen(path); + if (len >= sizeof(remote.sun_path)) return "path too long"; + memset(&remote, 0, sizeof(remote)); + strcpy(remote.sun_path, path); + remote.sun_family = AF_UNIX; + timeout_markstart(&un->tm); +#ifdef UNIX_HAS_SUN_LEN + remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) + + len + 1; + err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); +#else + err = socket_connect(&un->sock, (SA *) &remote, + sizeof(remote.sun_family) + len, &un->tm); +#endif + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_connect(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{any}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixudp_tryconnect(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + /* turn unconnected object into a connected object */ + auxiliar_setclass(L, "unixudp{connected}", 1); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Closes socket used by object +\*-------------------------------------------------------------------------*/ +static int meth_close(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); + socket_destroy(&un->sock); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Just call tm methods +\*-------------------------------------------------------------------------*/ +static int meth_settimeout(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); + return timeout_meth_settimeout(L, &un->tm); +} + +static int meth_gettimeout(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); + return timeout_meth_gettimeout(L, &un->tm); +} + +/*=========================================================================*\ +* Library functions +\*=========================================================================*/ +/*-------------------------------------------------------------------------*\ +* Creates a master unixudp object +\*-------------------------------------------------------------------------*/ +static int global_create(lua_State *L) +{ + t_socket sock; + int err = socket_create(&sock, AF_UNIX, SOCK_DGRAM, 0); + /* try to allocate a system socket */ + if (err == IO_DONE) { + /* allocate unixudp object */ + p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); + /* set its type as master object */ + auxiliar_setclass(L, "unixudp{unconnected}", -1); + /* initialize remaining structure fields */ + socket_setnonblocking(&sock); + un->sock = sock; + io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, + (p_error) socket_ioerror, &un->sock); + timeout_init(&un->tm, -1, -1); + buffer_init(&un->buf, &un->io, &un->tm); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } +} diff --git a/src/unixudp.h b/src/unixudp.h new file mode 100644 index 0000000..ccfdc07 --- /dev/null +++ b/src/unixudp.h @@ -0,0 +1,20 @@ +#ifndef UNIXUDP_H +#define UNIXUDP_H +/*=========================================================================*\ +* UDP object +* LuaSocket toolkit +* +* The udp.h module provides LuaSocket with support for UDP protocol +* (AF_INET, SOCK_DGRAM). +* +* Two classes are defined: connected and unconnected. UDP objects are +* originally unconnected. They can be "connected" to a given address +* with a call to the setpeername function. The same function can be used to +* break the connection. +\*=========================================================================*/ + +#include "unix.h" + +int unixudp_open(lua_State *L); + +#endif /* UNIXUDP_H */ diff --git a/test/unixclnt.lua b/test/unixclnt.lua deleted file mode 100644 index 5171535..0000000 --- a/test/unixclnt.lua +++ /dev/null @@ -1,8 +0,0 @@ -socket = require"socket" -socket.unix = require"socket.unix" -c = assert(socket.unix()) -assert(c:connect("/tmp/foo")) -while 1 do - local l = io.read() - assert(c:send(l .. "\n")) -end diff --git a/test/unixsrvr.lua b/test/unixsrvr.lua deleted file mode 100644 index 81b9c99..0000000 --- a/test/unixsrvr.lua +++ /dev/null @@ -1,9 +0,0 @@ - socket = require"socket" - socket.unix = require"socket.unix" - u = assert(socket.unix()) - assert(u:bind("/tmp/foo")) - assert(u:listen()) - c = assert(u:accept()) - while 1 do - print(assert(c:receive())) - end diff --git a/test/unixtcpclnt.lua b/test/unixtcpclnt.lua new file mode 100644 index 0000000..652a680 --- /dev/null +++ b/test/unixtcpclnt.lua @@ -0,0 +1,8 @@ +socket = require"socket" +socket.unix = require"socket.unix" +c = assert(socket.unix.tcp()) +assert(c:connect("/tmp/foo")) +while 1 do + local l = io.read() + assert(c:send(l .. "\n")) +end diff --git a/test/unixtcpsrvr.lua b/test/unixtcpsrvr.lua new file mode 100644 index 0000000..2a2b065 --- /dev/null +++ b/test/unixtcpsrvr.lua @@ -0,0 +1,9 @@ + socket = require"socket" + socket.unix = require"socket.unix" + u = assert(socket.unix.tcp()) + assert(u:bind("/tmp/foo")) + assert(u:listen()) + c = assert(u:accept()) + while 1 do + print(assert(c:receive())) + end diff --git a/test/unixudpclnt.lua b/test/unixudpclnt.lua new file mode 100644 index 0000000..bbbff7f --- /dev/null +++ b/test/unixudpclnt.lua @@ -0,0 +1,9 @@ +socket = require"socket" +socket.unix = require"socket.unix" +c = assert(socket.unix.udp()) +c:bind("/tmp/bar") +while 1 do + local l = io.read("*l") + assert(c:sendto(l, "/tmp/foo")) + print(assert(c:receivefrom())) +end diff --git a/test/unixudpsrvr.lua b/test/unixudpsrvr.lua new file mode 100644 index 0000000..5ed71dc --- /dev/null +++ b/test/unixudpsrvr.lua @@ -0,0 +1,9 @@ + socket = require"socket" + socket.unix = require"socket.unix" + u = assert(socket.unix.udp()) + assert(u:bind("/tmp/foo")) + while 1 do + x, r = assert(u:receivefrom()) + print(x, r) + assert(u:sendto(">" .. x, r)) + end -- cgit v1.2.3-55-g6feb From 9f77f8b24f7fcce66678b5c73ca82ceb23576536 Mon Sep 17 00:00:00 2001 From: enginix Date: Thu, 30 Jun 2016 15:40:51 +0800 Subject: unix socket: compat lua 5.1 --- src/makefile | 1 + src/unixtcp.c | 3 ++- src/unixudp.c | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index 0e4a544..2ffd7d9 100644 --- a/src/makefile +++ b/src/makefile @@ -309,6 +309,7 @@ UNIX_OBJS=\ usocket.$(O) \ unixtcp.$(O) \ unixudp.$(O) \ + compat.$(O) \ unix.$(O) #------ diff --git a/src/unixtcp.c b/src/unixtcp.c index 88baac0..a9c4962 100644 --- a/src/unixtcp.c +++ b/src/unixtcp.c @@ -6,6 +6,7 @@ #include "lua.h" #include "lauxlib.h" +#include "compat.h" #include "auxiliar.h" #include "socket.h" @@ -90,7 +91,7 @@ int unixtcp_open(lua_State *L) auxiliar_add2group(L, "unixtcp{server}", "unixtcp{any}"); luaL_setfuncs(L, func, 0); - return 1; + return 0; } /*=========================================================================*\ diff --git a/src/unixudp.c b/src/unixudp.c index ec348cf..75f5b08 100644 --- a/src/unixudp.c +++ b/src/unixudp.c @@ -7,6 +7,7 @@ #include "lua.h" #include "lauxlib.h" +#include "compat.h" #include "auxiliar.h" #include "socket.h" @@ -86,7 +87,7 @@ int unixudp_open(lua_State *L) auxiliar_add2group(L, "unixudp{unconnected}", "select{able}"); luaL_setfuncs(L, func, 0); - return 1; + return 0; } /*=========================================================================*\ -- cgit v1.2.3-55-g6feb From cd1e52eb7ad050c083703662dfbb870e57c3a1f0 Mon Sep 17 00:00:00 2001 From: Mike Usenko Date: Tue, 8 Nov 2016 22:07:20 +0300 Subject: allow DESTDIR to be set from the environment --- src/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index 2ffd7d9..2dfe549 100644 --- a/src/makefile +++ b/src/makefile @@ -102,7 +102,7 @@ LDIR?=$(LDIR_$(PLAT)) # DESTDIR: (no default) # used by package managers to install into a temporary destination -DESTDIR= +DESTDIR?= #------ # Definitions below can be overridden on the make command line, but -- cgit v1.2.3-55-g6feb From 3a33c37b9ce852d0b3531e82c6ffdb47bb937f0a Mon Sep 17 00:00:00 2001 From: enginix Date: Sun, 25 Dec 2016 23:15:12 +0800 Subject: rename unix.tcp to unix.stream, unix.udp to unix.dgram --- src/makefile | 4 +- src/unix.c | 8 +- src/unixdgram.c | 407 ++++++++++++++++++++++++++++++++++++++++++++++++ src/unixdgram.h | 20 +++ src/unixstream.c | 357 ++++++++++++++++++++++++++++++++++++++++++ src/unixstream.h | 21 +++ src/unixtcp.c | 357 ------------------------------------------ src/unixtcp.h | 21 --- src/unixudp.c | 407 ------------------------------------------------ src/unixudp.h | 20 --- test/unixdgramclnt.lua | 9 ++ test/unixdgramsrvr.lua | 9 ++ test/unixstreamclnt.lua | 8 + test/unixstreamsrvr.lua | 9 ++ test/unixtcpclnt.lua | 8 - test/unixtcpsrvr.lua | 9 -- test/unixudpclnt.lua | 9 -- test/unixudpsrvr.lua | 9 -- 18 files changed, 846 insertions(+), 846 deletions(-) create mode 100644 src/unixdgram.c create mode 100644 src/unixdgram.h create mode 100644 src/unixstream.c create mode 100644 src/unixstream.h delete mode 100644 src/unixtcp.c delete mode 100644 src/unixtcp.h delete mode 100644 src/unixudp.c delete mode 100644 src/unixudp.h create mode 100644 test/unixdgramclnt.lua create mode 100644 test/unixdgramsrvr.lua create mode 100644 test/unixstreamclnt.lua create mode 100644 test/unixstreamsrvr.lua delete mode 100644 test/unixtcpclnt.lua delete mode 100644 test/unixtcpsrvr.lua delete mode 100644 test/unixudpclnt.lua delete mode 100644 test/unixudpsrvr.lua (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index 2dfe549..494baab 100644 --- a/src/makefile +++ b/src/makefile @@ -307,8 +307,8 @@ UNIX_OBJS=\ timeout.$(O) \ io.$(O) \ usocket.$(O) \ - unixtcp.$(O) \ - unixudp.$(O) \ + unixstream.$(O) \ + unixdgram.$(O) \ compat.$(O) \ unix.$(O) diff --git a/src/unix.c b/src/unix.c index 2009c19..e604733 100644 --- a/src/unix.c +++ b/src/unix.c @@ -5,15 +5,15 @@ #include "lua.h" #include "lauxlib.h" -#include "unixtcp.h" -#include "unixudp.h" +#include "unixstream.h" +#include "unixdgram.h" /*-------------------------------------------------------------------------*\ * Modules and functions \*-------------------------------------------------------------------------*/ static const luaL_Reg mod[] = { - {"tcp", unixtcp_open}, - {"udp", unixudp_open}, + {"stream", unixstream_open}, + {"dgram", unixdgram_open}, {NULL, NULL} }; diff --git a/src/unixdgram.c b/src/unixdgram.c new file mode 100644 index 0000000..c07cbd5 --- /dev/null +++ b/src/unixdgram.c @@ -0,0 +1,407 @@ +/*=========================================================================*\ +* Unix domain socket dgram submodule +* LuaSocket toolkit +\*=========================================================================*/ +#include +#include + +#include "lua.h" +#include "lauxlib.h" +#include "compat.h" + +#include "auxiliar.h" +#include "socket.h" +#include "options.h" +#include "unix.h" +#include + +#define UNIXDGRAM_DATAGRAMSIZE 8192 + +/*=========================================================================*\ +* Internal function prototypes +\*=========================================================================*/ +static int global_create(lua_State *L); +static int meth_connect(lua_State *L); +static int meth_bind(lua_State *L); +static int meth_send(lua_State *L); +static int meth_receive(lua_State *L); +static int meth_close(lua_State *L); +static int meth_setoption(lua_State *L); +static int meth_settimeout(lua_State *L); +static int meth_gettimeout(lua_State *L); +static int meth_getfd(lua_State *L); +static int meth_setfd(lua_State *L); +static int meth_dirty(lua_State *L); +static int meth_receivefrom(lua_State *L); +static int meth_sendto(lua_State *L); +static int meth_getsockname(lua_State *L); + +static const char *unixdgram_tryconnect(p_unix un, const char *path); +static const char *unixdgram_trybind(p_unix un, const char *path); + +/* unixdgram object methods */ +static luaL_Reg unixdgram_methods[] = { + {"__gc", meth_close}, + {"__tostring", auxiliar_tostring}, + {"bind", meth_bind}, + {"close", meth_close}, + {"connect", meth_connect}, + {"dirty", meth_dirty}, + {"getfd", meth_getfd}, + {"send", meth_send}, + {"sendto", meth_sendto}, + {"receive", meth_receive}, + {"receivefrom", meth_receivefrom}, + {"setfd", meth_setfd}, + {"setoption", meth_setoption}, + {"setpeername", meth_connect}, + {"setsockname", meth_bind}, + {"getsockname", meth_getsockname}, + {"settimeout", meth_settimeout}, + {"gettimeout", meth_gettimeout}, + {NULL, NULL} +}; + +/* socket option handlers */ +static t_opt optset[] = { + {"reuseaddr", opt_set_reuseaddr}, + {NULL, NULL} +}; + +/* functions in library namespace */ +static luaL_Reg func[] = { + {"dgram", global_create}, + {NULL, NULL} +}; + +/*-------------------------------------------------------------------------*\ +* Initializes module +\*-------------------------------------------------------------------------*/ +int unixdgram_open(lua_State *L) +{ + /* create classes */ + auxiliar_newclass(L, "unixdgram{connected}", unixdgram_methods); + auxiliar_newclass(L, "unixdgram{unconnected}", unixdgram_methods); + /* create class groups */ + auxiliar_add2group(L, "unixdgram{connected}", "unixdgram{any}"); + auxiliar_add2group(L, "unixdgram{unconnected}", "unixdgram{any}"); + auxiliar_add2group(L, "unixdgram{connected}", "select{able}"); + auxiliar_add2group(L, "unixdgram{unconnected}", "select{able}"); + + luaL_setfuncs(L, func, 0); + return 0; +} + +/*=========================================================================*\ +* Lua methods +\*=========================================================================*/ +static const char *unixdgram_strerror(int err) +{ + /* a 'closed' error on an unconnected means the target address was not + * accepted by the transport layer */ + if (err == IO_CLOSED) return "refused"; + else return socket_strerror(err); +} + +static int meth_send(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{connected}", 1); + p_timeout tm = &un->tm; + size_t count, sent = 0; + int err; + const char *data = luaL_checklstring(L, 2, &count); + timeout_markstart(tm); + err = socket_send(&un->sock, data, count, &sent, tm); + if (err != IO_DONE) { + lua_pushnil(L); + lua_pushstring(L, unixdgram_strerror(err)); + return 2; + } + lua_pushnumber(L, (lua_Number) sent); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Send data through unconnected unixdgram socket +\*-------------------------------------------------------------------------*/ +static int meth_sendto(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); + size_t count, sent = 0; + const char *data = luaL_checklstring(L, 2, &count); + const char *path = luaL_checkstring(L, 3); + p_timeout tm = &un->tm; + int err; + struct sockaddr_un remote; + size_t len = strlen(path); + + if (len >= sizeof(remote.sun_path)) { + lua_pushnil(L); + lua_pushstring(L, "path too long"); + return 2; + } + + memset(&remote, 0, sizeof(remote)); + strcpy(remote.sun_path, path); + remote.sun_family = AF_UNIX; + timeout_markstart(tm); +#ifdef UNIX_HAS_SUN_LEN + remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) + + len + 1; + err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, remote.sun_len, tm); +#else + err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, + sizeof(remote.sun_family) + len, tm); +#endif + if (err != IO_DONE) { + lua_pushnil(L); + lua_pushstring(L, unixdgram_strerror(err)); + return 2; + } + lua_pushnumber(L, (lua_Number) sent); + return 1; +} + +static int meth_receive(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + char buf[UNIXDGRAM_DATAGRAMSIZE]; + size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); + char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; + int err; + p_timeout tm = &un->tm; + timeout_markstart(tm); + if (!dgram) { + lua_pushnil(L); + lua_pushliteral(L, "out of memory"); + return 2; + } + err = socket_recv(&un->sock, dgram, wanted, &got, tm); + /* Unlike STREAM, recv() of zero is not closed, but a zero-length packet. */ + if (err != IO_DONE && err != IO_CLOSED) { + lua_pushnil(L); + lua_pushstring(L, unixdgram_strerror(err)); + if (wanted > sizeof(buf)) free(dgram); + return 2; + } + lua_pushlstring(L, dgram, got); + if (wanted > sizeof(buf)) free(dgram); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Receives data and sender from a DGRAM socket +\*-------------------------------------------------------------------------*/ +static int meth_receivefrom(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); + char buf[UNIXDGRAM_DATAGRAMSIZE]; + size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); + char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; + struct sockaddr_un addr; + socklen_t addr_len = sizeof(addr); + int err; + p_timeout tm = &un->tm; + timeout_markstart(tm); + if (!dgram) { + lua_pushnil(L); + lua_pushliteral(L, "out of memory"); + return 2; + } + err = socket_recvfrom(&un->sock, dgram, wanted, &got, (SA *) &addr, + &addr_len, tm); + /* Unlike STREAM, recv() of zero is not closed, but a zero-length packet. */ + if (err != IO_DONE && err != IO_CLOSED) { + lua_pushnil(L); + lua_pushstring(L, unixdgram_strerror(err)); + if (wanted > sizeof(buf)) free(dgram); + return 2; + } + + lua_pushlstring(L, dgram, got); + /* the path may be empty, when client send without bind */ + lua_pushstring(L, addr.sun_path); + if (wanted > sizeof(buf)) free(dgram); + return 2; +} + +/*-------------------------------------------------------------------------*\ +* Just call option handler +\*-------------------------------------------------------------------------*/ +static int meth_setoption(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + return opt_meth_setoption(L, optset, &un->sock); +} + +/*-------------------------------------------------------------------------*\ +* Select support methods +\*-------------------------------------------------------------------------*/ +static int meth_getfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + lua_pushnumber(L, (int) un->sock); + return 1; +} + +/* this is very dangerous, but can be handy for those that are brave enough */ +static int meth_setfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + un->sock = (t_socket) luaL_checknumber(L, 2); + return 0; +} + +static int meth_dirty(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + (void) un; + lua_pushboolean(L, 0); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Binds an object to an address +\*-------------------------------------------------------------------------*/ +static const char *unixdgram_trybind(p_unix un, const char *path) { + struct sockaddr_un local; + size_t len = strlen(path); + int err; + if (len >= sizeof(local.sun_path)) return "path too long"; + memset(&local, 0, sizeof(local)); + strcpy(local.sun_path, path); + local.sun_family = AF_UNIX; +#ifdef UNIX_HAS_SUN_LEN + local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) + + len + 1; + err = socket_bind(&un->sock, (SA *) &local, local.sun_len); + +#else + err = socket_bind(&un->sock, (SA *) &local, + sizeof(local.sun_family) + len); +#endif + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_bind(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixdgram_trybind(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + lua_pushnumber(L, 1); + return 1; +} + +static int meth_getsockname(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + struct sockaddr_un peer = {0}; + socklen_t peer_len = sizeof(peer); + + if (getsockname(un->sock, (SA *) &peer, &peer_len) < 0) { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(errno)); + return 2; + } + + lua_pushstring(L, peer.sun_path); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Turns a master unixdgram object into a client object. +\*-------------------------------------------------------------------------*/ +static const char *unixdgram_tryconnect(p_unix un, const char *path) +{ + struct sockaddr_un remote; + int err; + size_t len = strlen(path); + if (len >= sizeof(remote.sun_path)) return "path too long"; + memset(&remote, 0, sizeof(remote)); + strcpy(remote.sun_path, path); + remote.sun_family = AF_UNIX; + timeout_markstart(&un->tm); +#ifdef UNIX_HAS_SUN_LEN + remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) + + len + 1; + err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); +#else + err = socket_connect(&un->sock, (SA *) &remote, + sizeof(remote.sun_family) + len, &un->tm); +#endif + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_connect(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixdgram_tryconnect(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + /* turn unconnected object into a connected object */ + auxiliar_setclass(L, "unixdgram{connected}", 1); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Closes socket used by object +\*-------------------------------------------------------------------------*/ +static int meth_close(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + socket_destroy(&un->sock); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Just call tm methods +\*-------------------------------------------------------------------------*/ +static int meth_settimeout(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + return timeout_meth_settimeout(L, &un->tm); +} + +static int meth_gettimeout(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + return timeout_meth_gettimeout(L, &un->tm); +} + +/*=========================================================================*\ +* Library functions +\*=========================================================================*/ +/*-------------------------------------------------------------------------*\ +* Creates a master unixdgram object +\*-------------------------------------------------------------------------*/ +static int global_create(lua_State *L) +{ + t_socket sock; + int err = socket_create(&sock, AF_UNIX, SOCK_DGRAM, 0); + /* try to allocate a system socket */ + if (err == IO_DONE) { + /* allocate unixdgram object */ + p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); + /* set its type as master object */ + auxiliar_setclass(L, "unixdgram{unconnected}", -1); + /* initialize remaining structure fields */ + socket_setnonblocking(&sock); + un->sock = sock; + io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, + (p_error) socket_ioerror, &un->sock); + timeout_init(&un->tm, -1, -1); + buffer_init(&un->buf, &un->io, &un->tm); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } +} diff --git a/src/unixdgram.h b/src/unixdgram.h new file mode 100644 index 0000000..7187966 --- /dev/null +++ b/src/unixdgram.h @@ -0,0 +1,20 @@ +#ifndef UNIXDGRAM_H +#define UNIXDGRAM_H +/*=========================================================================*\ +* DGRAM object +* LuaSocket toolkit +* +* The dgram.h module provides LuaSocket with support for DGRAM protocol +* (AF_INET, SOCK_DGRAM). +* +* Two classes are defined: connected and unconnected. DGRAM objects are +* originally unconnected. They can be "connected" to a given address +* with a call to the setpeername function. The same function can be used to +* break the connection. +\*=========================================================================*/ + +#include "unix.h" + +int unixdgram_open(lua_State *L); + +#endif /* UNIXDGRAM_H */ diff --git a/src/unixstream.c b/src/unixstream.c new file mode 100644 index 0000000..0b9055c --- /dev/null +++ b/src/unixstream.c @@ -0,0 +1,357 @@ +/*=========================================================================*\ +* Unix domain socket stream sub module +* LuaSocket toolkit +\*=========================================================================*/ +#include + +#include "lua.h" +#include "lauxlib.h" +#include "compat.h" + +#include "auxiliar.h" +#include "socket.h" +#include "options.h" +#include "unixstream.h" +#include + +/*=========================================================================*\ +* Internal function prototypes +\*=========================================================================*/ +static int global_create(lua_State *L); +static int meth_connect(lua_State *L); +static int meth_listen(lua_State *L); +static int meth_bind(lua_State *L); +static int meth_send(lua_State *L); +static int meth_shutdown(lua_State *L); +static int meth_receive(lua_State *L); +static int meth_accept(lua_State *L); +static int meth_close(lua_State *L); +static int meth_setoption(lua_State *L); +static int meth_settimeout(lua_State *L); +static int meth_getfd(lua_State *L); +static int meth_setfd(lua_State *L); +static int meth_dirty(lua_State *L); +static int meth_getstats(lua_State *L); +static int meth_setstats(lua_State *L); +static int meth_getsockname(lua_State *L); + +static const char *unixstream_tryconnect(p_unix un, const char *path); +static const char *unixstream_trybind(p_unix un, const char *path); + +/* unixstream object methods */ +static luaL_Reg unixstream_methods[] = { + {"__gc", meth_close}, + {"__tostring", auxiliar_tostring}, + {"accept", meth_accept}, + {"bind", meth_bind}, + {"close", meth_close}, + {"connect", meth_connect}, + {"dirty", meth_dirty}, + {"getfd", meth_getfd}, + {"getstats", meth_getstats}, + {"setstats", meth_setstats}, + {"listen", meth_listen}, + {"receive", meth_receive}, + {"send", meth_send}, + {"setfd", meth_setfd}, + {"setoption", meth_setoption}, + {"setpeername", meth_connect}, + {"setsockname", meth_bind}, + {"getsockname", meth_getsockname}, + {"settimeout", meth_settimeout}, + {"shutdown", meth_shutdown}, + {NULL, NULL} +}; + +/* socket option handlers */ +static t_opt optset[] = { + {"keepalive", opt_set_keepalive}, + {"reuseaddr", opt_set_reuseaddr}, + {"linger", opt_set_linger}, + {NULL, NULL} +}; + +/* functions in library namespace */ +static luaL_Reg func[] = { + {"stream", global_create}, + {NULL, NULL} +}; + +/*-------------------------------------------------------------------------*\ +* Initializes module +\*-------------------------------------------------------------------------*/ +int unixstream_open(lua_State *L) +{ + /* create classes */ + auxiliar_newclass(L, "unixstream{master}", unixstream_methods); + auxiliar_newclass(L, "unixstream{client}", unixstream_methods); + auxiliar_newclass(L, "unixstream{server}", unixstream_methods); + + /* create class groups */ + auxiliar_add2group(L, "unixstream{master}", "unixstream{any}"); + auxiliar_add2group(L, "unixstream{client}", "unixstream{any}"); + auxiliar_add2group(L, "unixstream{server}", "unixstream{any}"); + + luaL_setfuncs(L, func, 0); + return 0; +} + +/*=========================================================================*\ +* Lua methods +\*=========================================================================*/ +/*-------------------------------------------------------------------------*\ +* Just call buffered IO methods +\*-------------------------------------------------------------------------*/ +static int meth_send(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); + return buffer_meth_send(L, &un->buf); +} + +static int meth_receive(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); + return buffer_meth_receive(L, &un->buf); +} + +static int meth_getstats(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); + return buffer_meth_getstats(L, &un->buf); +} + +static int meth_setstats(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); + return buffer_meth_setstats(L, &un->buf); +} + +/*-------------------------------------------------------------------------*\ +* Just call option handler +\*-------------------------------------------------------------------------*/ +static int meth_setoption(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + return opt_meth_setoption(L, optset, &un->sock); +} + +/*-------------------------------------------------------------------------*\ +* Select support methods +\*-------------------------------------------------------------------------*/ +static int meth_getfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + lua_pushnumber(L, (int) un->sock); + return 1; +} + +/* this is very dangerous, but can be handy for those that are brave enough */ +static int meth_setfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + un->sock = (t_socket) luaL_checknumber(L, 2); + return 0; +} + +static int meth_dirty(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + lua_pushboolean(L, !buffer_isempty(&un->buf)); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Waits for and returns a client object attempting connection to the +* server object +\*-------------------------------------------------------------------------*/ +static int meth_accept(lua_State *L) { + p_unix server = (p_unix) auxiliar_checkclass(L, "unixstream{server}", 1); + p_timeout tm = timeout_markstart(&server->tm); + t_socket sock; + int err = socket_accept(&server->sock, &sock, NULL, NULL, tm); + /* if successful, push client socket */ + if (err == IO_DONE) { + p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix)); + auxiliar_setclass(L, "unixstream{client}", -1); + /* initialize structure fields */ + socket_setnonblocking(&sock); + clnt->sock = sock; + io_init(&clnt->io, (p_send)socket_send, (p_recv)socket_recv, + (p_error) socket_ioerror, &clnt->sock); + timeout_init(&clnt->tm, -1, -1); + buffer_init(&clnt->buf, &clnt->io, &clnt->tm); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } +} + +/*-------------------------------------------------------------------------*\ +* Binds an object to an address +\*-------------------------------------------------------------------------*/ +static const char *unixstream_trybind(p_unix un, const char *path) { + struct sockaddr_un local; + size_t len = strlen(path); + int err; + if (len >= sizeof(local.sun_path)) return "path too long"; + memset(&local, 0, sizeof(local)); + strcpy(local.sun_path, path); + local.sun_family = AF_UNIX; +#ifdef UNIX_HAS_SUN_LEN + local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) + + len + 1; + err = socket_bind(&un->sock, (SA *) &local, local.sun_len); + +#else + err = socket_bind(&un->sock, (SA *) &local, + sizeof(local.sun_family) + len); +#endif + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_bind(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixstream_trybind(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + lua_pushnumber(L, 1); + return 1; +} + +static int meth_getsockname(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + struct sockaddr_un peer = {0}; + socklen_t peer_len = sizeof(peer); + + if (getsockname(un->sock, (SA *) &peer, &peer_len) < 0) { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(errno)); + return 2; + } + + lua_pushstring(L, peer.sun_path); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Turns a master unixstream object into a client object. +\*-------------------------------------------------------------------------*/ +static const char *unixstream_tryconnect(p_unix un, const char *path) +{ + struct sockaddr_un remote; + int err; + size_t len = strlen(path); + if (len >= sizeof(remote.sun_path)) return "path too long"; + memset(&remote, 0, sizeof(remote)); + strcpy(remote.sun_path, path); + remote.sun_family = AF_UNIX; + timeout_markstart(&un->tm); +#ifdef UNIX_HAS_SUN_LEN + remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) + + len + 1; + err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); +#else + err = socket_connect(&un->sock, (SA *) &remote, + sizeof(remote.sun_family) + len, &un->tm); +#endif + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_connect(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixstream_tryconnect(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + /* turn master object into a client object */ + auxiliar_setclass(L, "unixstream{client}", 1); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Closes socket used by object +\*-------------------------------------------------------------------------*/ +static int meth_close(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + socket_destroy(&un->sock); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Puts the sockt in listen mode +\*-------------------------------------------------------------------------*/ +static int meth_listen(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); + int backlog = (int) luaL_optnumber(L, 2, 32); + int err = socket_listen(&un->sock, backlog); + if (err != IO_DONE) { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } + /* turn master object into a server object */ + auxiliar_setclass(L, "unixstream{server}", 1); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Shuts the connection down partially +\*-------------------------------------------------------------------------*/ +static int meth_shutdown(lua_State *L) +{ + /* SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2, so we can use method index directly */ + static const char* methods[] = { "receive", "send", "both", NULL }; + p_unix stream = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); + int how = luaL_checkoption(L, 2, "both", methods); + socket_shutdown(&stream->sock, how); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Just call tm methods +\*-------------------------------------------------------------------------*/ +static int meth_settimeout(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + return timeout_meth_settimeout(L, &un->tm); +} + +/*=========================================================================*\ +* Library functions +\*=========================================================================*/ +/*-------------------------------------------------------------------------*\ +* Creates a master unixstream object +\*-------------------------------------------------------------------------*/ +static int global_create(lua_State *L) { + t_socket sock; + int err = socket_create(&sock, AF_UNIX, SOCK_STREAM, 0); + /* try to allocate a system socket */ + if (err == IO_DONE) { + /* allocate unixstream object */ + p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); + /* set its type as master object */ + auxiliar_setclass(L, "unixstream{master}", -1); + /* initialize remaining structure fields */ + socket_setnonblocking(&sock); + un->sock = sock; + io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, + (p_error) socket_ioerror, &un->sock); + timeout_init(&un->tm, -1, -1); + buffer_init(&un->buf, &un->io, &un->tm); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } +} diff --git a/src/unixstream.h b/src/unixstream.h new file mode 100644 index 0000000..ef1d071 --- /dev/null +++ b/src/unixstream.h @@ -0,0 +1,21 @@ +#ifndef UNIXSTREAM_H +#define UNIXSTREAM_H +/*=========================================================================*\ +* UNIX STREAM object +* LuaSocket toolkit +* +* The unixstream.h module is basicly a glue that puts together modules buffer.h, +* timeout.h socket.h and inet.h to provide the LuaSocket UNIX STREAM (AF_UNIX, +* SOCK_STREAM) support. +* +* Three classes are defined: master, client and server. The master class is +* a newly created unixstream object, that has not been bound or connected. Server +* objects are unixstream objects bound to some local address. Client objects are +* unixstream objects either connected to some address or returned by the accept +* method of a server object. +\*=========================================================================*/ +#include "unix.h" + +int unixstream_open(lua_State *L); + +#endif /* UNIXSTREAM_H */ diff --git a/src/unixtcp.c b/src/unixtcp.c deleted file mode 100644 index 747ef5f..0000000 --- a/src/unixtcp.c +++ /dev/null @@ -1,357 +0,0 @@ -/*=========================================================================*\ -* Unix domain socket tcp sub module -* LuaSocket toolkit -\*=========================================================================*/ -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - -#include "auxiliar.h" -#include "socket.h" -#include "options.h" -#include "unixtcp.h" -#include - -/*=========================================================================*\ -* Internal function prototypes -\*=========================================================================*/ -static int global_create(lua_State *L); -static int meth_connect(lua_State *L); -static int meth_listen(lua_State *L); -static int meth_bind(lua_State *L); -static int meth_send(lua_State *L); -static int meth_shutdown(lua_State *L); -static int meth_receive(lua_State *L); -static int meth_accept(lua_State *L); -static int meth_close(lua_State *L); -static int meth_setoption(lua_State *L); -static int meth_settimeout(lua_State *L); -static int meth_getfd(lua_State *L); -static int meth_setfd(lua_State *L); -static int meth_dirty(lua_State *L); -static int meth_getstats(lua_State *L); -static int meth_setstats(lua_State *L); -static int meth_getsockname(lua_State *L); - -static const char *unixtcp_tryconnect(p_unix un, const char *path); -static const char *unixtcp_trybind(p_unix un, const char *path); - -/* unixtcp object methods */ -static luaL_Reg unixtcp_methods[] = { - {"__gc", meth_close}, - {"__tostring", auxiliar_tostring}, - {"accept", meth_accept}, - {"bind", meth_bind}, - {"close", meth_close}, - {"connect", meth_connect}, - {"dirty", meth_dirty}, - {"getfd", meth_getfd}, - {"getstats", meth_getstats}, - {"setstats", meth_setstats}, - {"listen", meth_listen}, - {"receive", meth_receive}, - {"send", meth_send}, - {"setfd", meth_setfd}, - {"setoption", meth_setoption}, - {"setpeername", meth_connect}, - {"setsockname", meth_bind}, - {"getsockname", meth_getsockname}, - {"settimeout", meth_settimeout}, - {"shutdown", meth_shutdown}, - {NULL, NULL} -}; - -/* socket option handlers */ -static t_opt optset[] = { - {"keepalive", opt_set_keepalive}, - {"reuseaddr", opt_set_reuseaddr}, - {"linger", opt_set_linger}, - {NULL, NULL} -}; - -/* functions in library namespace */ -static luaL_Reg func[] = { - {"tcp", global_create}, - {NULL, NULL} -}; - -/*-------------------------------------------------------------------------*\ -* Initializes module -\*-------------------------------------------------------------------------*/ -int unixtcp_open(lua_State *L) -{ - /* create classes */ - auxiliar_newclass(L, "unixtcp{master}", unixtcp_methods); - auxiliar_newclass(L, "unixtcp{client}", unixtcp_methods); - auxiliar_newclass(L, "unixtcp{server}", unixtcp_methods); - - /* create class groups */ - auxiliar_add2group(L, "unixtcp{master}", "unixtcp{any}"); - auxiliar_add2group(L, "unixtcp{client}", "unixtcp{any}"); - auxiliar_add2group(L, "unixtcp{server}", "unixtcp{any}"); - - luaL_setfuncs(L, func, 0); - return 0; -} - -/*=========================================================================*\ -* Lua methods -\*=========================================================================*/ -/*-------------------------------------------------------------------------*\ -* Just call buffered IO methods -\*-------------------------------------------------------------------------*/ -static int meth_send(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); - return buffer_meth_send(L, &un->buf); -} - -static int meth_receive(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); - return buffer_meth_receive(L, &un->buf); -} - -static int meth_getstats(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); - return buffer_meth_getstats(L, &un->buf); -} - -static int meth_setstats(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); - return buffer_meth_setstats(L, &un->buf); -} - -/*-------------------------------------------------------------------------*\ -* Just call option handler -\*-------------------------------------------------------------------------*/ -static int meth_setoption(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - return opt_meth_setoption(L, optset, &un->sock); -} - -/*-------------------------------------------------------------------------*\ -* Select support methods -\*-------------------------------------------------------------------------*/ -static int meth_getfd(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - lua_pushnumber(L, (int) un->sock); - return 1; -} - -/* this is very dangerous, but can be handy for those that are brave enough */ -static int meth_setfd(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - un->sock = (t_socket) luaL_checknumber(L, 2); - return 0; -} - -static int meth_dirty(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - lua_pushboolean(L, !buffer_isempty(&un->buf)); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Waits for and returns a client object attempting connection to the -* server object -\*-------------------------------------------------------------------------*/ -static int meth_accept(lua_State *L) { - p_unix server = (p_unix) auxiliar_checkclass(L, "unixtcp{server}", 1); - p_timeout tm = timeout_markstart(&server->tm); - t_socket sock; - int err = socket_accept(&server->sock, &sock, NULL, NULL, tm); - /* if successful, push client socket */ - if (err == IO_DONE) { - p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix)); - auxiliar_setclass(L, "unixtcp{client}", -1); - /* initialize structure fields */ - socket_setnonblocking(&sock); - clnt->sock = sock; - io_init(&clnt->io, (p_send)socket_send, (p_recv)socket_recv, - (p_error) socket_ioerror, &clnt->sock); - timeout_init(&clnt->tm, -1, -1); - buffer_init(&clnt->buf, &clnt->io, &clnt->tm); - return 1; - } else { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } -} - -/*-------------------------------------------------------------------------*\ -* Binds an object to an address -\*-------------------------------------------------------------------------*/ -static const char *unixtcp_trybind(p_unix un, const char *path) { - struct sockaddr_un local; - size_t len = strlen(path); - int err; - if (len >= sizeof(local.sun_path)) return "path too long"; - memset(&local, 0, sizeof(local)); - strcpy(local.sun_path, path); - local.sun_family = AF_UNIX; -#ifdef UNIX_HAS_SUN_LEN - local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) - + len + 1; - err = socket_bind(&un->sock, (SA *) &local, local.sun_len); - -#else - err = socket_bind(&un->sock, (SA *) &local, - sizeof(local.sun_family) + len); -#endif - if (err != IO_DONE) socket_destroy(&un->sock); - return socket_strerror(err); -} - -static int meth_bind(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); - const char *path = luaL_checkstring(L, 2); - const char *err = unixtcp_trybind(un, path); - if (err) { - lua_pushnil(L); - lua_pushstring(L, err); - return 2; - } - lua_pushnumber(L, 1); - return 1; -} - -static int meth_getsockname(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - struct sockaddr_un peer = {0}; - socklen_t peer_len = sizeof(peer); - - if (getsockname(un->sock, (SA *) &peer, &peer_len) < 0) { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(errno)); - return 2; - } - - lua_pushstring(L, peer.sun_path); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Turns a master unixtcp object into a client object. -\*-------------------------------------------------------------------------*/ -static const char *unixtcp_tryconnect(p_unix un, const char *path) -{ - struct sockaddr_un remote; - int err; - size_t len = strlen(path); - if (len >= sizeof(remote.sun_path)) return "path too long"; - memset(&remote, 0, sizeof(remote)); - strcpy(remote.sun_path, path); - remote.sun_family = AF_UNIX; - timeout_markstart(&un->tm); -#ifdef UNIX_HAS_SUN_LEN - remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) - + len + 1; - err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); -#else - err = socket_connect(&un->sock, (SA *) &remote, - sizeof(remote.sun_family) + len, &un->tm); -#endif - if (err != IO_DONE) socket_destroy(&un->sock); - return socket_strerror(err); -} - -static int meth_connect(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); - const char *path = luaL_checkstring(L, 2); - const char *err = unixtcp_tryconnect(un, path); - if (err) { - lua_pushnil(L); - lua_pushstring(L, err); - return 2; - } - /* turn master object into a client object */ - auxiliar_setclass(L, "unixtcp{client}", 1); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Closes socket used by object -\*-------------------------------------------------------------------------*/ -static int meth_close(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - socket_destroy(&un->sock); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Puts the sockt in listen mode -\*-------------------------------------------------------------------------*/ -static int meth_listen(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); - int backlog = (int) luaL_optnumber(L, 2, 32); - int err = socket_listen(&un->sock, backlog); - if (err != IO_DONE) { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } - /* turn master object into a server object */ - auxiliar_setclass(L, "unixtcp{server}", 1); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Shuts the connection down partially -\*-------------------------------------------------------------------------*/ -static int meth_shutdown(lua_State *L) -{ - /* SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2, so we can use method index directly */ - static const char* methods[] = { "receive", "send", "both", NULL }; - p_unix tcp = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); - int how = luaL_checkoption(L, 2, "both", methods); - socket_shutdown(&tcp->sock, how); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Just call tm methods -\*-------------------------------------------------------------------------*/ -static int meth_settimeout(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - return timeout_meth_settimeout(L, &un->tm); -} - -/*=========================================================================*\ -* Library functions -\*=========================================================================*/ -/*-------------------------------------------------------------------------*\ -* Creates a master unixtcp object -\*-------------------------------------------------------------------------*/ -static int global_create(lua_State *L) { - t_socket sock; - int err = socket_create(&sock, AF_UNIX, SOCK_STREAM, 0); - /* try to allocate a system socket */ - if (err == IO_DONE) { - /* allocate unixtcp object */ - p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); - /* set its type as master object */ - auxiliar_setclass(L, "unixtcp{master}", -1); - /* initialize remaining structure fields */ - socket_setnonblocking(&sock); - un->sock = sock; - io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, - (p_error) socket_ioerror, &un->sock); - timeout_init(&un->tm, -1, -1); - buffer_init(&un->buf, &un->io, &un->tm); - return 1; - } else { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } -} diff --git a/src/unixtcp.h b/src/unixtcp.h deleted file mode 100644 index 0eababc..0000000 --- a/src/unixtcp.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef UNIXTCP_H -#define UNIXTCP_H -/*=========================================================================*\ -* UNIX TCP object -* LuaSocket toolkit -* -* The unixtcp.h module is basicly a glue that puts together modules buffer.h, -* timeout.h socket.h and inet.h to provide the LuaSocket UNIX TCP (AF_UNIX, -* SOCK_STREAM) support. -* -* Three classes are defined: master, client and server. The master class is -* a newly created unixtcp object, that has not been bound or connected. Server -* objects are unixtcp objects bound to some local address. Client objects are -* unixtcp objects either connected to some address or returned by the accept -* method of a server object. -\*=========================================================================*/ -#include "unix.h" - -int unixtcp_open(lua_State *L); - -#endif /* UNIXTCP_H */ diff --git a/src/unixudp.c b/src/unixudp.c deleted file mode 100644 index 0e0a19a..0000000 --- a/src/unixudp.c +++ /dev/null @@ -1,407 +0,0 @@ -/*=========================================================================*\ -* Unix domain socket udp submodule -* LuaSocket toolkit -\*=========================================================================*/ -#include -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - -#include "auxiliar.h" -#include "socket.h" -#include "options.h" -#include "unix.h" -#include - -#define UNIXUDP_DATAGRAMSIZE 8192 - -/*=========================================================================*\ -* Internal function prototypes -\*=========================================================================*/ -static int global_create(lua_State *L); -static int meth_connect(lua_State *L); -static int meth_bind(lua_State *L); -static int meth_send(lua_State *L); -static int meth_receive(lua_State *L); -static int meth_close(lua_State *L); -static int meth_setoption(lua_State *L); -static int meth_settimeout(lua_State *L); -static int meth_gettimeout(lua_State *L); -static int meth_getfd(lua_State *L); -static int meth_setfd(lua_State *L); -static int meth_dirty(lua_State *L); -static int meth_receivefrom(lua_State *L); -static int meth_sendto(lua_State *L); -static int meth_getsockname(lua_State *L); - -static const char *unixudp_tryconnect(p_unix un, const char *path); -static const char *unixudp_trybind(p_unix un, const char *path); - -/* unixudp object methods */ -static luaL_Reg unixudp_methods[] = { - {"__gc", meth_close}, - {"__tostring", auxiliar_tostring}, - {"bind", meth_bind}, - {"close", meth_close}, - {"connect", meth_connect}, - {"dirty", meth_dirty}, - {"getfd", meth_getfd}, - {"send", meth_send}, - {"sendto", meth_sendto}, - {"receive", meth_receive}, - {"receivefrom", meth_receivefrom}, - {"setfd", meth_setfd}, - {"setoption", meth_setoption}, - {"setpeername", meth_connect}, - {"setsockname", meth_bind}, - {"getsockname", meth_getsockname}, - {"settimeout", meth_settimeout}, - {"gettimeout", meth_gettimeout}, - {NULL, NULL} -}; - -/* socket option handlers */ -static t_opt optset[] = { - {"reuseaddr", opt_set_reuseaddr}, - {NULL, NULL} -}; - -/* functions in library namespace */ -static luaL_Reg func[] = { - {"udp", global_create}, - {NULL, NULL} -}; - -/*-------------------------------------------------------------------------*\ -* Initializes module -\*-------------------------------------------------------------------------*/ -int unixudp_open(lua_State *L) -{ - /* create classes */ - auxiliar_newclass(L, "unixudp{connected}", unixudp_methods); - auxiliar_newclass(L, "unixudp{unconnected}", unixudp_methods); - /* create class groups */ - auxiliar_add2group(L, "unixudp{connected}", "unixudp{any}"); - auxiliar_add2group(L, "unixudp{unconnected}", "unixudp{any}"); - auxiliar_add2group(L, "unixudp{connected}", "select{able}"); - auxiliar_add2group(L, "unixudp{unconnected}", "select{able}"); - - luaL_setfuncs(L, func, 0); - return 0; -} - -/*=========================================================================*\ -* Lua methods -\*=========================================================================*/ -static const char *unixudp_strerror(int err) -{ - /* a 'closed' error on an unconnected means the target address was not - * accepted by the transport layer */ - if (err == IO_CLOSED) return "refused"; - else return socket_strerror(err); -} - -static int meth_send(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{connected}", 1); - p_timeout tm = &un->tm; - size_t count, sent = 0; - int err; - const char *data = luaL_checklstring(L, 2, &count); - timeout_markstart(tm); - err = socket_send(&un->sock, data, count, &sent, tm); - if (err != IO_DONE) { - lua_pushnil(L); - lua_pushstring(L, unixudp_strerror(err)); - return 2; - } - lua_pushnumber(L, (lua_Number) sent); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Send data through unconnected unixudp socket -\*-------------------------------------------------------------------------*/ -static int meth_sendto(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); - size_t count, sent = 0; - const char *data = luaL_checklstring(L, 2, &count); - const char *path = luaL_checkstring(L, 3); - p_timeout tm = &un->tm; - int err; - struct sockaddr_un remote; - size_t len = strlen(path); - - if (len >= sizeof(remote.sun_path)) { - lua_pushnil(L); - lua_pushstring(L, "path too long"); - return 2; - } - - memset(&remote, 0, sizeof(remote)); - strcpy(remote.sun_path, path); - remote.sun_family = AF_UNIX; - timeout_markstart(tm); -#ifdef UNIX_HAS_SUN_LEN - remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) - + len + 1; - err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, remote.sun_len, tm); -#else - err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, - sizeof(remote.sun_family) + len, tm); -#endif - if (err != IO_DONE) { - lua_pushnil(L); - lua_pushstring(L, unixudp_strerror(err)); - return 2; - } - lua_pushnumber(L, (lua_Number) sent); - return 1; -} - -static int meth_receive(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - char buf[UNIXUDP_DATAGRAMSIZE]; - size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); - char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; - int err; - p_timeout tm = &un->tm; - timeout_markstart(tm); - if (!dgram) { - lua_pushnil(L); - lua_pushliteral(L, "out of memory"); - return 2; - } - err = socket_recv(&un->sock, dgram, wanted, &got, tm); - /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ - if (err != IO_DONE && err != IO_CLOSED) { - lua_pushnil(L); - lua_pushstring(L, unixudp_strerror(err)); - if (wanted > sizeof(buf)) free(dgram); - return 2; - } - lua_pushlstring(L, dgram, got); - if (wanted > sizeof(buf)) free(dgram); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Receives data and sender from a UDP socket -\*-------------------------------------------------------------------------*/ -static int meth_receivefrom(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); - char buf[UNIXUDP_DATAGRAMSIZE]; - size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); - char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; - struct sockaddr_un addr; - socklen_t addr_len = sizeof(addr); - int err; - p_timeout tm = &un->tm; - timeout_markstart(tm); - if (!dgram) { - lua_pushnil(L); - lua_pushliteral(L, "out of memory"); - return 2; - } - err = socket_recvfrom(&un->sock, dgram, wanted, &got, (SA *) &addr, - &addr_len, tm); - /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ - if (err != IO_DONE && err != IO_CLOSED) { - lua_pushnil(L); - lua_pushstring(L, unixudp_strerror(err)); - if (wanted > sizeof(buf)) free(dgram); - return 2; - } - - lua_pushlstring(L, dgram, got); - /* the path may be empty, when client send without bind */ - lua_pushstring(L, addr.sun_path); - if (wanted > sizeof(buf)) free(dgram); - return 2; -} - -/*-------------------------------------------------------------------------*\ -* Just call option handler -\*-------------------------------------------------------------------------*/ -static int meth_setoption(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - return opt_meth_setoption(L, optset, &un->sock); -} - -/*-------------------------------------------------------------------------*\ -* Select support methods -\*-------------------------------------------------------------------------*/ -static int meth_getfd(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - lua_pushnumber(L, (int) un->sock); - return 1; -} - -/* this is very dangerous, but can be handy for those that are brave enough */ -static int meth_setfd(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - un->sock = (t_socket) luaL_checknumber(L, 2); - return 0; -} - -static int meth_dirty(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - (void) un; - lua_pushboolean(L, 0); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Binds an object to an address -\*-------------------------------------------------------------------------*/ -static const char *unixudp_trybind(p_unix un, const char *path) { - struct sockaddr_un local; - size_t len = strlen(path); - int err; - if (len >= sizeof(local.sun_path)) return "path too long"; - memset(&local, 0, sizeof(local)); - strcpy(local.sun_path, path); - local.sun_family = AF_UNIX; -#ifdef UNIX_HAS_SUN_LEN - local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) - + len + 1; - err = socket_bind(&un->sock, (SA *) &local, local.sun_len); - -#else - err = socket_bind(&un->sock, (SA *) &local, - sizeof(local.sun_family) + len); -#endif - if (err != IO_DONE) socket_destroy(&un->sock); - return socket_strerror(err); -} - -static int meth_bind(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); - const char *path = luaL_checkstring(L, 2); - const char *err = unixudp_trybind(un, path); - if (err) { - lua_pushnil(L); - lua_pushstring(L, err); - return 2; - } - lua_pushnumber(L, 1); - return 1; -} - -static int meth_getsockname(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - struct sockaddr_un peer = {0}; - socklen_t peer_len = sizeof(peer); - - if (getsockname(un->sock, (SA *) &peer, &peer_len) < 0) { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(errno)); - return 2; - } - - lua_pushstring(L, peer.sun_path); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Turns a master unixudp object into a client object. -\*-------------------------------------------------------------------------*/ -static const char *unixudp_tryconnect(p_unix un, const char *path) -{ - struct sockaddr_un remote; - int err; - size_t len = strlen(path); - if (len >= sizeof(remote.sun_path)) return "path too long"; - memset(&remote, 0, sizeof(remote)); - strcpy(remote.sun_path, path); - remote.sun_family = AF_UNIX; - timeout_markstart(&un->tm); -#ifdef UNIX_HAS_SUN_LEN - remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) - + len + 1; - err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); -#else - err = socket_connect(&un->sock, (SA *) &remote, - sizeof(remote.sun_family) + len, &un->tm); -#endif - if (err != IO_DONE) socket_destroy(&un->sock); - return socket_strerror(err); -} - -static int meth_connect(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - const char *path = luaL_checkstring(L, 2); - const char *err = unixudp_tryconnect(un, path); - if (err) { - lua_pushnil(L); - lua_pushstring(L, err); - return 2; - } - /* turn unconnected object into a connected object */ - auxiliar_setclass(L, "unixudp{connected}", 1); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Closes socket used by object -\*-------------------------------------------------------------------------*/ -static int meth_close(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - socket_destroy(&un->sock); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Just call tm methods -\*-------------------------------------------------------------------------*/ -static int meth_settimeout(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - return timeout_meth_settimeout(L, &un->tm); -} - -static int meth_gettimeout(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - return timeout_meth_gettimeout(L, &un->tm); -} - -/*=========================================================================*\ -* Library functions -\*=========================================================================*/ -/*-------------------------------------------------------------------------*\ -* Creates a master unixudp object -\*-------------------------------------------------------------------------*/ -static int global_create(lua_State *L) -{ - t_socket sock; - int err = socket_create(&sock, AF_UNIX, SOCK_DGRAM, 0); - /* try to allocate a system socket */ - if (err == IO_DONE) { - /* allocate unixudp object */ - p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); - /* set its type as master object */ - auxiliar_setclass(L, "unixudp{unconnected}", -1); - /* initialize remaining structure fields */ - socket_setnonblocking(&sock); - un->sock = sock; - io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, - (p_error) socket_ioerror, &un->sock); - timeout_init(&un->tm, -1, -1); - buffer_init(&un->buf, &un->io, &un->tm); - return 1; - } else { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } -} diff --git a/src/unixudp.h b/src/unixudp.h deleted file mode 100644 index ccfdc07..0000000 --- a/src/unixudp.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef UNIXUDP_H -#define UNIXUDP_H -/*=========================================================================*\ -* UDP object -* LuaSocket toolkit -* -* The udp.h module provides LuaSocket with support for UDP protocol -* (AF_INET, SOCK_DGRAM). -* -* Two classes are defined: connected and unconnected. UDP objects are -* originally unconnected. They can be "connected" to a given address -* with a call to the setpeername function. The same function can be used to -* break the connection. -\*=========================================================================*/ - -#include "unix.h" - -int unixudp_open(lua_State *L); - -#endif /* UNIXUDP_H */ diff --git a/test/unixdgramclnt.lua b/test/unixdgramclnt.lua new file mode 100644 index 0000000..9bd60f7 --- /dev/null +++ b/test/unixdgramclnt.lua @@ -0,0 +1,9 @@ +socket = require"socket" +socket.unix = require"socket.unix" +c = assert(socket.unix.dgram()) +print(c:bind("/tmp/bar")) +while 1 do + local l = io.read("*l") + assert(c:sendto(l, "/tmp/foo")) + print(assert(c:receivefrom())) +end diff --git a/test/unixdgramsrvr.lua b/test/unixdgramsrvr.lua new file mode 100644 index 0000000..4c11f55 --- /dev/null +++ b/test/unixdgramsrvr.lua @@ -0,0 +1,9 @@ + socket = require"socket" + socket.unix = require"socket.unix" + u = assert(socket.unix.dgram()) + assert(u:bind("/tmp/foo")) + while 1 do + x, r = assert(u:receivefrom()) + print(x, r) + assert(u:sendto(">" .. x, r)) + end diff --git a/test/unixstreamclnt.lua b/test/unixstreamclnt.lua new file mode 100644 index 0000000..4f2e1e3 --- /dev/null +++ b/test/unixstreamclnt.lua @@ -0,0 +1,8 @@ +socket = require"socket" +socket.unix = require"socket.unix" +c = assert(socket.unix.stream()) +assert(c:connect("/tmp/foo")) +while 1 do + local l = io.read() + assert(c:send(l .. "\n")) +end diff --git a/test/unixstreamsrvr.lua b/test/unixstreamsrvr.lua new file mode 100644 index 0000000..0a5c644 --- /dev/null +++ b/test/unixstreamsrvr.lua @@ -0,0 +1,9 @@ + socket = require"socket" + socket.unix = require"socket.unix" + u = assert(socket.unix.stream()) + assert(u:bind("/tmp/foo")) + assert(u:listen()) + c = assert(u:accept()) + while 1 do + print(assert(c:receive())) + end diff --git a/test/unixtcpclnt.lua b/test/unixtcpclnt.lua deleted file mode 100644 index 652a680..0000000 --- a/test/unixtcpclnt.lua +++ /dev/null @@ -1,8 +0,0 @@ -socket = require"socket" -socket.unix = require"socket.unix" -c = assert(socket.unix.tcp()) -assert(c:connect("/tmp/foo")) -while 1 do - local l = io.read() - assert(c:send(l .. "\n")) -end diff --git a/test/unixtcpsrvr.lua b/test/unixtcpsrvr.lua deleted file mode 100644 index 2a2b065..0000000 --- a/test/unixtcpsrvr.lua +++ /dev/null @@ -1,9 +0,0 @@ - socket = require"socket" - socket.unix = require"socket.unix" - u = assert(socket.unix.tcp()) - assert(u:bind("/tmp/foo")) - assert(u:listen()) - c = assert(u:accept()) - while 1 do - print(assert(c:receive())) - end diff --git a/test/unixudpclnt.lua b/test/unixudpclnt.lua deleted file mode 100644 index bbbff7f..0000000 --- a/test/unixudpclnt.lua +++ /dev/null @@ -1,9 +0,0 @@ -socket = require"socket" -socket.unix = require"socket.unix" -c = assert(socket.unix.udp()) -c:bind("/tmp/bar") -while 1 do - local l = io.read("*l") - assert(c:sendto(l, "/tmp/foo")) - print(assert(c:receivefrom())) -end diff --git a/test/unixudpsrvr.lua b/test/unixudpsrvr.lua deleted file mode 100644 index 5ed71dc..0000000 --- a/test/unixudpsrvr.lua +++ /dev/null @@ -1,9 +0,0 @@ - socket = require"socket" - socket.unix = require"socket.unix" - u = assert(socket.unix.udp()) - assert(u:bind("/tmp/foo")) - while 1 do - x, r = assert(u:receivefrom()) - print(x, r) - assert(u:sendto(">" .. x, r)) - end -- cgit v1.2.3-55-g6feb From 288219fd6b53ce2e709745c9918aa4c4b7f715c9 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Wed, 22 Aug 2018 17:37:32 -0300 Subject: Update to Visual Studio 2017. --- .gitignore | 1 - Lua.props | 28 +++++++++ Lua51.props | 28 --------- Lua52.props | 28 --------- mime.vcxproj | 61 ++++++++++---------- socket.vcxproj | 173 ++++++++++++++++++++++++++++---------------------------- src/luasocket.c | 2 +- src/makefile | 2 +- src/mime.c | 2 +- src/wsocket.c | 4 +- 10 files changed, 151 insertions(+), 178 deletions(-) create mode 100755 Lua.props delete mode 100644 Lua51.props delete mode 100644 Lua52.props mode change 100644 => 100755 src/luasocket.c mode change 100644 => 100755 src/mime.c mode change 100644 => 100755 src/wsocket.c (limited to 'src/makefile') diff --git a/.gitignore b/.gitignore index 8307483..9ed661c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ *.dll* *.user *.sdf -Lua.props Debug Release *.manifest diff --git a/Lua.props b/Lua.props new file mode 100755 index 0000000..bdfca40 --- /dev/null +++ b/Lua.props @@ -0,0 +1,28 @@ + + + + + z:\data\build\vc14\ + $(BUILD)\bin\lua\5.3\ + $(BUILD)\lib\lua\5.3\ + $(BUILD)\include\lua\5.3\ + + + <_PropertySheetDisplayName>Lua53 + + + + + $(LUALIB) + + + $(LUAINC) + + + $(LUABIN) + + + $(BUILD) + + + diff --git a/Lua51.props b/Lua51.props deleted file mode 100644 index 1bd6256..0000000 --- a/Lua51.props +++ /dev/null @@ -1,28 +0,0 @@ - - - - - ..\build\vc12\bin\lua\5.1\ - ..\build\vc12\bin\lua\5.1\ - ..\build\vc12\include\lua\5.1\ - lua51.lib - - - <_PropertySheetDisplayName>Lua51 - - - - - $(LUALIB_PATH) - - - $(LUABIN_PATH) - - - $(LUAINC_PATH) - - - $(LUALIB) - - - diff --git a/Lua52.props b/Lua52.props deleted file mode 100644 index 01afcfa..0000000 --- a/Lua52.props +++ /dev/null @@ -1,28 +0,0 @@ - - - - - ..\build\vc12\bin\lua\5.2\ - ..\build\vc12\bin\lua\5.2\ - ..\build\vc12\include\lua\5.2\ - lua52.lib - - - <_PropertySheetDisplayName>Lua52 - - - - - $(LUALIB_PATH) - - - $(LUABIN_PATH) - - - $(LUAINC_PATH) - - - $(LUALIB) - - - diff --git a/mime.vcxproj b/mime.vcxproj index c77d611..74bba0c 100755 --- a/mime.vcxproj +++ b/mime.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -24,39 +24,40 @@ Document - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - copy %(FullPath) $(LUALIB_PATH)$(Platform)\$(Configuration) - copy %(FullPath) $(LUALIB_PATH)$(Platform)\$(Configuration) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) {128E8BD0-174A-48F0-8771-92B1E8D18713} Win32Proj + 10.0.15063.0 DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte @@ -87,7 +88,7 @@ <_ProjectFileVersion>11.0.50727.1 - $(LUABIN_PATH)$(Configuration)\mime\ + $(LUABIN)$(Configuration)\mime\ $(Configuration)\ true core @@ -95,23 +96,23 @@ true core - $(LUABIN_PATH)$(Platform)\$(Configuration)\mime\ + $(LUABIN)$(Platform)\$(Configuration)\mime\ - $(LUABIN_PATH)$(Configuration)\mime\ + $(LUABIN)$(Configuration)\mime\ $(Configuration)\ false core false - $(LUABIN_PATH)$(Platform)\$(Configuration)\mime\ + $(LUABIN)$(Platform)\$(Configuration)\mime\ core Disabled - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -122,9 +123,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);%(AdditionalDependencies) + lualib.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB)$(Configuration);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -138,7 +139,7 @@ Disabled - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -149,9 +150,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);%(AdditionalDependencies) + lualib.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -163,7 +164,7 @@ - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL @@ -172,9 +173,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);%(AdditionalDependencies) + lualib.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB)$(Configuration);%(AdditionalLibraryDirectories) true Windows true @@ -187,7 +188,7 @@ - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL @@ -198,9 +199,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);%(AdditionalDependencies) + lualib.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) true Windows true @@ -214,4 +215,4 @@ - \ No newline at end of file + diff --git a/socket.vcxproj b/socket.vcxproj index 16daeef..cfa32b3 100755 --- a/socket.vcxproj +++ b/socket.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -35,118 +35,119 @@ Document - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) Document - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A} Win32Proj + 10.0.15063.0 DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte @@ -177,7 +178,7 @@ <_ProjectFileVersion>11.0.50727.1 - $(LUALIB_PATH)$(Configuration)\socket\ + $(LUABIN)$(Configuration)\socket\ $(Configuration)\ true core @@ -185,23 +186,23 @@ true core - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\ + $(LUABIN)$(Platform)\$(Configuration)\socket\ - $(LUALIB_PATH)$(Configuration)\socket\ + $(LUABIN)$(Configuration)\socket\ $(Configuration)\ false core false - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\ + $(LUABIN)$(Platform)\$(Configuration)\socket\ core Disabled - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUASOCKET_DEBUG;%(PreprocessorDefinitions) true EnableFastChecks @@ -212,9 +213,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);ws2_32.lib;%(AdditionalDependencies) + lualib.lib;ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB)$(Configuration);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -228,7 +229,7 @@ Disabled - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUASOCKET_DEBUG;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -239,9 +240,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);ws2_32.lib;%(AdditionalDependencies) + lualib.lib;ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -253,7 +254,7 @@ - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL @@ -262,9 +263,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);ws2_32.lib;%(AdditionalDependencies) + lualib.lib;ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB)$(Configuration);%(AdditionalLibraryDirectories) true Windows true @@ -277,7 +278,7 @@ - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL @@ -288,9 +289,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);ws2_32.lib;%(AdditionalDependencies) + lualib.lib;ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) true Windows true @@ -304,4 +305,4 @@ - \ No newline at end of file + diff --git a/src/luasocket.c b/src/luasocket.c old mode 100644 new mode 100755 index 7d9c802..d2752a7 --- a/src/luasocket.c +++ b/src/luasocket.c @@ -64,7 +64,7 @@ static luaL_Reg func[] = { * Skip a few arguments \*-------------------------------------------------------------------------*/ static int global_skip(lua_State *L) { - int amount = luaL_checkinteger(L, 1); + int amount = (int) luaL_checkinteger(L, 1); int ret = lua_gettop(L) - amount - 1; return ret >= 0 ? ret : 0; } diff --git a/src/makefile b/src/makefile index 494baab..1ed3f4f 100644 --- a/src/makefile +++ b/src/makefile @@ -386,7 +386,7 @@ $(UNIX_SO): $(UNIX_OBJS) $(SERIAL_SO): $(SERIAL_OBJS) $(LD) $(SERIAL_OBJS) $(LDFLAGS)$@ -install: +install: $(INSTALL_DIR) $(INSTALL_TOP_LDIR) $(INSTALL_DATA) $(TO_TOP_LDIR) $(INSTALL_TOP_LDIR) $(INSTALL_DIR) $(INSTALL_SOCKET_LDIR) diff --git a/src/mime.c b/src/mime.c old mode 100644 new mode 100755 index db356fc..338ecd4 --- a/src/mime.c +++ b/src/mime.c @@ -654,7 +654,7 @@ static int eolprocess(int c, int last, const char *marker, \*-------------------------------------------------------------------------*/ static int mime_global_eol(lua_State *L) { - int ctx = luaL_checkinteger(L, 1); + int ctx = (int) luaL_checkinteger(L, 1); size_t isize = 0; const char *input = luaL_optlstring(L, 2, NULL, &isize); const char *last = input + isize; diff --git a/src/wsocket.c b/src/wsocket.c old mode 100644 new mode 100755 index 8ecb0fc..ac8411f --- a/src/wsocket.c +++ b/src/wsocket.c @@ -131,11 +131,11 @@ int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { /* we wait until something happens */ err = socket_waitfd(ps, WAITFD_C, tm); if (err == IO_CLOSED) { - int len = sizeof(err); + int elen = sizeof(err); /* give windows time to set the error (yes, disgusting) */ Sleep(10); /* find out why we failed */ - getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &len); + getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &elen); /* we KNOW there was an error. if 'why' is 0, we will return * "unknown error", but it's not really our fault */ return err > 0? err: IO_UNKNOWN; -- cgit v1.2.3-55-g6feb From d1e35c9573c0a6055a22072aed23c478151be133 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Tue, 19 Feb 2019 04:02:37 -0700 Subject: src/makefile: define UNIX_HAS_SUN_LEN for FreeBSD builds --- src/makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index 1ed3f4f..0f4b359 100644 --- a/src/makefile +++ b/src/makefile @@ -181,7 +181,7 @@ SOCKET_linux=usocket.o SO_freebsd=so O_freebsd=o CC_freebsd=gcc -DEF_freebsd=-DLUASOCKET_$(DEBUG) \ +DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN \ -DLUASOCKET_API='__attribute__((visibility("default")))' \ -DUNIX_API='__attribute__((visibility("default")))' \ -DMIME_API='__attribute__((visibility("default")))' @@ -360,7 +360,7 @@ linux: mingw: $(MAKE) all PLAT=mingw - + solaris: $(MAKE) all-unix PLAT=solaris -- cgit v1.2.3-55-g6feb From 5858c8e7769b2855a9492b244b8bfa9254ce1c42 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Fri, 22 Feb 2019 16:16:03 -0700 Subject: src/makefile: support both lua/$(LUAV) and lua$(LUAV) include paths --- src/makefile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index 0f4b359..cc1ec7e 100644 --- a/src/makefile +++ b/src/makefile @@ -35,7 +35,7 @@ DEBUG?=NODEBUG # LUAINC_macosx: # /opt/local/include LUAINC_macosx_base?=/opt/local/include -LUAINC_macosx?=$(LUAINC_macosx_base)/lua/$(LUAV) +LUAINC_macosx?=$(LUAINC_macosx_base)/lua/$(LUAV) $(LUAINC_macosx_base)/lua$(LUAV) # FIXME default should this default to fink or to macports? # What happens when more than one Lua version is installed? LUAPREFIX_macosx?=/opt/local @@ -48,7 +48,7 @@ LDIR_macosx?=share/lua/$(LUAV) # /usr/local/include/lua$(LUAV) # where lua headers are found for linux builds LUAINC_linux_base?=/usr/include -LUAINC_linux?=$(LUAINC_linux_base)/lua/$(LUAV) +LUAINC_linux?=$(LUAINC_linux_base)/lua/$(LUAV) $(LUAINC_linux_base)/lua$(LUAV) LUAPREFIX_linux?=/usr/local CDIR_linux?=lib/lua/$(LUAV) LDIR_linux?=share/lua/$(LUAV) @@ -57,7 +57,7 @@ LDIR_linux?=share/lua/$(LUAV) # /usr/local/include/lua$(LUAV) # where lua headers are found for freebsd builds LUAINC_freebsd_base?=/usr/local/include/ -LUAINC_freebsd?=$(LUAINC_freebsd_base)/lua$(LUAV) +LUAINC_freebsd?=$(LUAINC_freebsd_base)/lua/$(LUAV) $(LUAINC_freebsd_base)/lua$(LUAV) LUAPREFIX_freebsd?=/usr/local/ CDIR_freebsd?=lib/lua/$(LUAV) LDIR_freebsd?=share/lua/$(LUAV) @@ -66,7 +66,7 @@ LDIR_freebsd?=share/lua/$(LUAV) # LUAINC_mingw: # /opt/local/include LUAINC_mingw_base?=/usr/include -LUAINC_mingw?=$(LUAINC_mingw_base)/lua/$(LUAV) +LUAINC_mingw?=$(LUAINC_mingw_base)/lua/$(LUAV) $(LUAINC_mingw_base)/lua$(LUAV) LUALIB_mingw_base?=/usr/bin LUALIB_mingw?=$(LUALIB_mingw_base)/lua/$(LUAV)/lua$(subst .,,$(LUAV)).dll LUAPREFIX_mingw?=/usr @@ -78,7 +78,7 @@ LDIR_mingw?=lua/$(LUAV)/lua # LUALIB_win32: # where lua headers and libraries are found for win32 builds LUAPREFIX_win32?= -LUAINC_win32?=$(LUAPREFIX_win32)/include/lua/$(LUAV) +LUAINC_win32?=$(LUAPREFIX_win32)/include/lua/$(LUAV) $(LUAPREFIX_win32)/include/lua$(LUAV) PLATFORM_win32?=Release CDIR_win32?=bin/lua/$(LUAV)/$(PLATFORM_win32) LDIR_win32?=bin/lua/$(LUAV)/$(PLATFORM_win32)/lua @@ -88,7 +88,7 @@ LUALIBNAME_win32?=lua$(subst .,,$(LUAV)).lib # LUAINC_solaris: LUAINC_solaris_base?=/usr/include -LUAINC_solaris?=$(LUAINC_solaris_base)/lua/$(LUAV) +LUAINC_solaris?=$(LUAINC_solaris_base)/lua/$(LUAV) $(LUAINC_solaris_base)/lua$(LUAV) LUAPREFIX_solaris?=/usr/local CDIR_solaris?=lib/lua/$(LUAV) LDIR_solaris?=share/lua/$(LUAV) @@ -153,7 +153,7 @@ DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN \ -DLUASOCKET_API='__attribute__((visibility("default")))' \ -DUNIX_API='__attribute__((visibility("default")))' \ -DMIME_API='__attribute__((visibility("default")))' -CFLAGS_macosx= -I$(LUAINC) $(DEF) -Wall -O2 -fno-common \ +CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common \ -fvisibility=hidden LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc @@ -169,7 +169,7 @@ DEF_linux=-DLUASOCKET_$(DEBUG) \ -DLUASOCKET_API='__attribute__((visibility("default")))' \ -DUNIX_API='__attribute__((visibility("default")))' \ -DMIME_API='__attribute__((visibility("default")))' -CFLAGS_linux= -I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \ +CFLAGS_linux=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden LDFLAGS_linux=-O -shared -fpic -o LD_linux=gcc @@ -185,7 +185,7 @@ 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= -I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \ +CFLAGS_freebsd=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden LDFLAGS_freebsd=-O -shared -fpic -o LD_freebsd=gcc @@ -201,7 +201,7 @@ DEF_solaris=-DLUASOCKET_$(DEBUG) \ -DLUASOCKET_API='__attribute__((visibility("default")))' \ -DUNIX_API='__attribute__((visibility("default")))' \ -DMIME_API='__attribute__((visibility("default")))' -CFLAGS_solaris=-I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \ +CFLAGS_solaris=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o LD_solaris=gcc @@ -216,7 +216,7 @@ CC_mingw=gcc DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) \ -DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \ -DMIME_API='__declspec(dllexport)' -CFLAGS_mingw= -I$(LUAINC) $(DEF) -Wall -O2 -fno-common \ +CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common \ -fvisibility=hidden LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o LD_mingw=gcc @@ -233,7 +233,7 @@ DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \ //D "LUASOCKET_API=__declspec(dllexport)" //D "_CRT_SECURE_NO_WARNINGS" \ //D "_WINDLL" //D "MIME_API=__declspec(dllexport)" \ //D "LUASOCKET_$(DEBUG)" -CFLAGS_win32=//I "$(LUAINC)" $(DEF) //O2 //Ot //MD //W3 //nologo +CFLAGS_win32=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo LDFLAGS_win32= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \ //MANIFEST //MANIFESTFILE:"intermediate.manifest" \ //MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ -- cgit v1.2.3-55-g6feb From 2d8f0d99011b267ed354ab6e8317d93b9627eed4 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:04:49 -0700 Subject: src/makefile: remove visibility and dllexport defines in favor of in-source labeling --- src/makefile | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'src/makefile') 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 \ -- cgit v1.2.3-55-g6feb From 1e4255e2a937d46dd46695eea56b570090427001 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 1 Mar 2019 20:46:37 -0300 Subject: Update Windows projects vor Visual Studio 2017 --- Lua.props | 39 ++++++++++++++----- makefile | 2 +- mime.vcxproj | 37 ++++++------------ socket.vcxproj | 116 ++++++--------------------------------------------------- src/makefile | 50 +++++++++++++++++++++---- vc32.bat | 3 ++ vc64.bat | 3 ++ win32.cmd | 2 +- win64.cmd | 1 + 9 files changed, 106 insertions(+), 147 deletions(-) mode change 100644 => 100755 makefile mode change 100644 => 100755 src/makefile create mode 100755 vc32.bat create mode 100755 vc64.bat mode change 100644 => 100755 win32.cmd create mode 100755 win64.cmd (limited to 'src/makefile') diff --git a/Lua.props b/Lua.props index bdfca40..d748448 100755 --- a/Lua.props +++ b/Lua.props @@ -1,28 +1,49 @@  + + $(Platform)/$(Configuration) + + + $(Configuration) + - z:\data\build\vc14\ - $(BUILD)\bin\lua\5.3\ - $(BUILD)\lib\lua\5.3\ - $(BUILD)\include\lua\5.3\ + 5.3 + z:\data\build\vc14\ + $(LUAPREFIX)\lib\lua\$(LUAV)\$(LUAPLAT) + $(LUAPREFIX)\bin\lua\$(LUAV)\$(LUAPLAT) + $(LUAPREFIX)\bin\lua\$(LUAV)\$(LUAPLAT)\lua + $(LUAPREFIX)\include\lua\$(LUAV);$(LUAPREFIX)\include\lua$(LUAV) + lua$(LUAV.Replace('.', '')).lib - <_PropertySheetDisplayName>Lua53 + <_PropertySheetDisplayName>Lua + + $(LUAPLAT) + + + $(LUAPREFIX) + + + $(LUAV) + $(LUALIB) $(LUAINC) - - $(LUABIN) + + $(LUACDIR) + + + $(LUALDIR) - - $(BUILD) + + $(LUALIBNAME) diff --git a/makefile b/makefile old mode 100644 new mode 100755 index cc15b4e..f766a25 --- a/makefile +++ b/makefile @@ -10,7 +10,7 @@ # print print the build settings PLAT?= linux -PLATS= macosx linux win32 mingw freebsd solaris +PLATS= macosx linux win32 win64 mingw freebsd solaris all: $(PLAT) diff --git a/mime.vcxproj b/mime.vcxproj index 74bba0c..6a7b35a 100755 --- a/mime.vcxproj +++ b/mime.vcxproj @@ -21,19 +21,6 @@ - - - Document - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - {128E8BD0-174A-48F0-8771-92B1E8D18713} Win32Proj @@ -88,7 +75,7 @@ <_ProjectFileVersion>11.0.50727.1 - $(LUABIN)$(Configuration)\mime\ + $(Configuration)\mime\ $(Configuration)\ true core @@ -96,17 +83,17 @@ true core - $(LUABIN)$(Platform)\$(Configuration)\mime\ + $(Platform)\$(Configuration)\mime\ - $(LUABIN)$(Configuration)\mime\ + $(Configuration)\mime\ $(Configuration)\ false core false - $(LUABIN)$(Platform)\$(Configuration)\mime\ + $(Platform)\$(Configuration)\mime\ core @@ -123,9 +110,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;%(AdditionalDependencies) + $(LUALIBNAME);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -150,9 +137,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;%(AdditionalDependencies) + $(LUALIBNAME);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -173,9 +160,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;%(AdditionalDependencies) + $(LUALIBNAME);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true Windows true @@ -199,9 +186,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;%(AdditionalDependencies) + $(LUALIBNAME);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true Windows true diff --git a/socket.vcxproj b/socket.vcxproj index cfa32b3..e639216 100755 --- a/socket.vcxproj +++ b/socket.vcxproj @@ -32,98 +32,6 @@ - - - Document - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - - Document - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - - - - Document - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - - Document - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - - Document - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - - Document - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - - Document - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - - Document - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN)$(Platform)\$(Configuration) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A} Win32Proj @@ -178,7 +86,7 @@ <_ProjectFileVersion>11.0.50727.1 - $(LUABIN)$(Configuration)\socket\ + $(Configuration)\socket\ $(Configuration)\ true core @@ -186,17 +94,17 @@ true core - $(LUABIN)$(Platform)\$(Configuration)\socket\ + $(Platform)\$(Configuration)\socket\ - $(LUABIN)$(Configuration)\socket\ + $(Configuration)\socket\ $(Configuration)\ false core false - $(LUABIN)$(Platform)\$(Configuration)\socket\ + $(Platform)\$(Configuration)\socket\ core @@ -213,9 +121,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;ws2_32.lib;%(AdditionalDependencies) + $(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -240,9 +148,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;ws2_32.lib;%(AdditionalDependencies) + $(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -263,9 +171,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;ws2_32.lib;%(AdditionalDependencies) + $(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true Windows true @@ -289,9 +197,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;ws2_32.lib;%(AdditionalDependencies) + $(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true Windows true diff --git a/src/makefile b/src/makefile old mode 100644 new mode 100755 index 74bf3d5..e6baf78 --- a/src/makefile +++ b/src/makefile @@ -12,7 +12,7 @@ # # make PLAT=linux DEBUG=DEBUG LUAV=5.2 prefix=/sw -# PLAT: linux macosx win32 mingw +# PLAT: linux macosx win32 win64 mingw # platform to build for PLAT?=linux @@ -83,7 +83,18 @@ PLATFORM_win32?=Release CDIR_win32?=bin/lua/$(LUAV)/$(PLATFORM_win32) LDIR_win32?=bin/lua/$(LUAV)/$(PLATFORM_win32)/lua LUALIB_win32?=$(LUAPREFIX_win32)/lib/lua/$(LUAV)/$(PLATFORM_win32) -LUALIBNAME_win32?=lua$(subst .,,$(LUAV)).lib +LUALIBNAME_win32?=lua$(subst .,,$(LUAV)).lib + +# LUAINC_win64: +# LUALIB_win64: +# where lua headers and libraries are found for win64 builds +LUAPREFIX_win64?= +LUAINC_win64?=$(LUAPREFIX_win64)/include/lua/$(LUAV) $(LUAPREFIX_win64)/include/lua$(LUAV) +PLATFORM_win64?=x64/Release +CDIR_win64?=bin/lua/$(LUAV)/$(PLATFORM_win64) +LDIR_win64?=bin/lua/$(LUAV)/$(PLATFORM_win64)/lua +LUALIB_win64?=$(LUAPREFIX_win64)/lib/lua/$(LUAV)/$(PLATFORM_win64) +LUALIBNAME_win64?=lua$(subst .,,$(LUAV)).lib # LUAINC_solaris: @@ -141,7 +152,7 @@ print: #------ # Supported platforms # -PLATS= macosx linux win32 mingw solaris +PLATS= macosx linux win32 win64 mingw solaris #------ # Compiler and linker settings @@ -152,7 +163,7 @@ CC_macosx=gcc DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o -LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc +LD_macosx=gcc SOCKET_macosx=usocket.o #------ @@ -217,17 +228,39 @@ CC_win32=cl DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \ //D "_CRT_SECURE_NO_WARNINGS" \ //D "_WINDLL" \ - //D "LUASOCKET_$(DEBUG)" + //D "LUASOCKET_$(DEBUG)" CFLAGS_win32=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo LDFLAGS_win32= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \ //MANIFEST //MANIFESTFILE:"intermediate.manifest" \ - //MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ + /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ //SUBSYSTEM:WINDOWS //OPT:REF //OPT:ICF //DYNAMICBASE:NO \ - //MACHINE:X86 /LIBPATH:"$(shell cmd //c echo $(LUALIB))" \ + //MACHINE:X86 /LIBPATH:"$(LUALIB)" \ $(LUALIBNAME_win32) ws2_32.lib //OUT: + LD_win32=cl SOCKET_win32=wsocket.obj +#------ +# Compiler and linker settings +# for Win64 +SO_win64=dll +O_win64=obj +CC_win64=cl +DEF_win64= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \ + //D "_CRT_SECURE_NO_WARNINGS" \ + //D "_WINDLL" \ + //D "LUASOCKET_$(DEBUG)" +CFLAGS_win64=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo +LDFLAGS_win64= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \ + //MANIFEST //MANIFESTFILE:"intermediate.manifest" \ + /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ + //SUBSYSTEM:WINDOWS //OPT:REF //OPT:ICF //DYNAMICBASE:NO \ + /LIBPATH:"$(LUALIB)" \ + $(LUALIBNAME_win64) ws2_32.lib //OUT: + +LD_win64=cl +SOCKET_win64=wsocket.obj + .SUFFIXES: .obj .c.obj: @@ -340,6 +373,9 @@ macosx: win32: $(MAKE) all PLAT=win32 +win64: + $(MAKE) all PLAT=win64 + linux: $(MAKE) all-unix PLAT=linux diff --git a/vc32.bat b/vc32.bat new file mode 100755 index 0000000..7ff8c0e --- /dev/null +++ b/vc32.bat @@ -0,0 +1,3 @@ +call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" +cls +"c:\Program Files\Git\git-bash.exe" --cd-to-home diff --git a/vc64.bat b/vc64.bat new file mode 100755 index 0000000..ed5cb3a --- /dev/null +++ b/vc64.bat @@ -0,0 +1,3 @@ +call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat" +cls +"c:\Program Files\Git\git-bash.exe" --cd-to-home diff --git a/win32.cmd b/win32.cmd old mode 100644 new mode 100755 index 3045721..5eda3b1 --- a/win32.cmd +++ b/win32.cmd @@ -1 +1 @@ -make LUAPREFIX_win32='c:\cygwin\home\diego\vc12' LUAV=5.1 PLAT=win32 LUALIBNAME_win32=lualib.lib PLATFORM_win32=Debug install-both +LUAV=5.3 PLAT=win32 LUAPREFIX_win32=/z/data/build/vc14 make diff --git a/win64.cmd b/win64.cmd new file mode 100755 index 0000000..b1f9ac0 --- /dev/null +++ b/win64.cmd @@ -0,0 +1 @@ +LUAV=5.3 PLAT=win64 LUAPREFIX_win64=/z/data/build/vc14 make -- cgit v1.2.3-55-g6feb From 03b72d8f7ee5e35f76f97da299ce676946023725 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sat, 9 Mar 2019 23:23:48 -0300 Subject: Use static initialization This helps with multi-threaded apps. --- src/makefile | 3 +- src/mime.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 145 insertions(+), 10 deletions(-) (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index e6baf78..b9e2f93 100755 --- a/src/makefile +++ b/src/makefile @@ -35,7 +35,8 @@ DEBUG?=NODEBUG # LUAINC_macosx: # /opt/local/include LUAINC_macosx_base?=/opt/local/include -LUAINC_macosx?=$(LUAINC_macosx_base)/lua/$(LUAV) $(LUAINC_macosx_base)/lua$(LUAV) +LUAINC_macosx?=$(LUAINC_macosx_base)/lua/$(LUAV) $(LUAINC_macosx_base)/lua$(LUAV) $(LUAINC_macosx_base)/lua-$(LUAV) + # FIXME default should this default to fink or to macports? # What happens when more than one Lua version is installed? LUAPREFIX_macosx?=/opt/local diff --git a/src/mime.c b/src/mime.c index 6e359af..ce28826 100755 --- a/src/mime.c +++ b/src/mime.c @@ -3,6 +3,7 @@ * LuaSocket toolkit \*=========================================================================*/ #include +#include #include "lua.h" #include "lauxlib.h" @@ -30,12 +31,12 @@ static int mime_global_eol(lua_State *L); static int mime_global_dot(lua_State *L); static size_t dot(int c, size_t state, luaL_Buffer *buffer); -static void b64setup(UC *base); +//static void b64setup(UC *base); static size_t b64encode(UC c, UC *input, size_t size, luaL_Buffer *buffer); static size_t b64pad(const UC *input, size_t size, luaL_Buffer *buffer); static size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer); -static void qpsetup(UC *class, UC *unbase); +//static void qpsetup(UC *class, UC *unbase); static void qpquote(UC c, luaL_Buffer *buffer); static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer); static size_t qpencode(UC c, UC *input, size_t size, @@ -58,17 +59,111 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Quoted-printable globals \*-------------------------------------------------------------------------*/ -static UC qpclass[256]; -static UC qpbase[] = "0123456789ABCDEF"; -static UC qpunbase[256]; enum {QP_PLAIN, QP_QUOTED, QP_CR, QP_IF_LAST}; +static UC qpclass[] = { + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_IF_LAST, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_CR, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_IF_LAST, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_QUOTED, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED +}; + +static const UC qpbase[] = "0123456789ABCDEF"; + +static const UC qpunbase[] = { + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, + 255, 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255 +}; + /*-------------------------------------------------------------------------*\ * Base64 globals \*-------------------------------------------------------------------------*/ static const UC b64base[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static UC b64unbase[256]; + +static const UC b64unbase[] = { + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 0, + 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, + 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255 +}; /*=========================================================================*\ * Exported functions @@ -85,8 +180,8 @@ LUASOCKET_API int luaopen_mime_core(lua_State *L) lua_pushstring(L, MIME_VERSION); lua_rawset(L, -3); /* initialize lookup tables */ - qpsetup(qpclass, qpunbase); - b64setup(b64unbase); + // qpsetup(qpclass, qpunbase); + // b64setup(b64unbase); return 1; } @@ -145,13 +240,21 @@ static int mime_global_wrp(lua_State *L) /*-------------------------------------------------------------------------*\ * Fill base64 decode map. \*-------------------------------------------------------------------------*/ +#if 0 static void b64setup(UC *unbase) { int i; for (i = 0; i <= 255; i++) unbase[i] = (UC) 255; for (i = 0; i < 64; i++) unbase[b64base[i]] = (UC) i; unbase['='] = 0; + + printf("static const UC b64unbase[] = {\n"); + for (int i = 0; i < 256; i++) { + printf("%d, ", unbase[i]); + } + printf("\n}\n;"); } +#endif /*-------------------------------------------------------------------------*\ * Acumulates bytes in input buffer until 3 bytes are available. @@ -349,8 +452,10 @@ static int mime_global_unb64(lua_State *L) * Split quoted-printable characters into classes * Precompute reverse map for encoding \*-------------------------------------------------------------------------*/ +#if 0 static void qpsetup(UC *cl, UC *unbase) { + int i; for (i = 0; i < 256; i++) cl[i] = QP_QUOTED; for (i = 33; i <= 60; i++) cl[i] = QP_PLAIN; @@ -367,7 +472,37 @@ static void qpsetup(UC *cl, UC *unbase) unbase['c'] = 12; unbase['D'] = 13; unbase['d'] = 13; unbase['E'] = 14; unbase['e'] = 14; unbase['F'] = 15; unbase['f'] = 15; + +printf("static UC qpclass[] = {"); + for (int i = 0; i < 256; i++) { + if (i % 6 == 0) { + printf("\n "); + } + switch(cl[i]) { + case QP_QUOTED: + printf("QP_QUOTED, "); + break; + case QP_PLAIN: + printf("QP_PLAIN, "); + break; + case QP_CR: + printf("QP_CR, "); + break; + case QP_IF_LAST: + printf("QP_IF_LAST, "); + break; + } + } +printf("\n};\n"); + +printf("static const UC qpunbase[] = {"); + for (int i = 0; i < 256; i++) { + int c = qpunbase[i]; + printf("%d, ", c); + } +printf("\";\n"); } +#endif /*-------------------------------------------------------------------------*\ * Output one character in form =XX @@ -447,7 +582,6 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer) \*-------------------------------------------------------------------------*/ static int mime_global_qp(lua_State *L) { - size_t asize = 0, isize = 0; UC atom[3]; const UC *input = (const UC *) luaL_optlstring(L, 1, NULL, &isize); -- cgit v1.2.3-55-g6feb From c8d0fdda544b32ee0b7bcd38b26933ecc2c8a95b Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:05:38 -0700 Subject: src/makefile: serial += compat --- src/makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index b9e2f93..5a9ba97 100755 --- a/src/makefile +++ b/src/makefile @@ -336,6 +336,7 @@ UNIX_OBJS=\ # SERIAL_OBJS=\ buffer.$(O) \ + compat.$(O) \ auxiliar.$(O) \ options.$(O) \ timeout.$(O) \ -- cgit v1.2.3-55-g6feb From 78a1657c7db5510ba66f8d4491f1e8e7370c5943 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Fri, 27 Mar 2020 18:41:57 -0600 Subject: src/makefile: remove -DLUASOCKET_INET_PTON as current mingw builds don't want it --- src/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/makefile') diff --git a/src/makefile b/src/makefile index 5a9ba97..522d378 100755 --- a/src/makefile +++ b/src/makefile @@ -212,7 +212,7 @@ SOCKET_solaris=usocket.o SO_mingw=dll O_mingw=o CC_mingw=gcc -DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) \ +DEF_mingw= -DLUASOCKET_$(DEBUG) \ -DWINVER=0x0501 CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o -- cgit v1.2.3-55-g6feb From d9c08114da2ec8950498f71939f92a6dc0d237c1 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Wed, 23 Mar 2022 17:11:43 +0100 Subject: chore; add Lua 5.4 to make files --- makefile | 6 ++++++ src/makefile | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/makefile') diff --git a/makefile b/makefile index f766a25..63d9985 100755 --- a/makefile +++ b/makefile @@ -33,6 +33,9 @@ install-both: $(MAKE) clean @cd src; $(MAKE) $(PLAT) LUAV=5.3 @cd src; $(MAKE) install LUAV=5.3 + $(MAKE) clean + @cd src; $(MAKE) $(PLAT) LUAV=5.4 + @cd src; $(MAKE) install LUAV=5.4 install-both-unix: $(MAKE) clean @@ -44,6 +47,9 @@ install-both-unix: $(MAKE) clean @cd src; $(MAKE) $(PLAT) LUAV=5.3 @cd src; $(MAKE) install-unix LUAV=5.3 + $(MAKE) clean + @cd src; $(MAKE) $(PLAT) LUAV=5.4 + @cd src; $(MAKE) install-unix LUAV=5.4 .PHONY: test diff --git a/src/makefile b/src/makefile index 522d378..f95498a 100755 --- a/src/makefile +++ b/src/makefile @@ -16,7 +16,7 @@ # platform to build for PLAT?=linux -# LUAV: 5.1 5.2 +# LUAV: 5.1 5.2 5.3 5.4 # lua version to build against LUAV?=5.1 @@ -163,7 +163,7 @@ O_macosx=o CC_macosx=gcc DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common -LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o +LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o LD_macosx=gcc SOCKET_macosx=usocket.o @@ -176,7 +176,7 @@ CC_linux=gcc DEF_linux=-DLUASOCKET_$(DEBUG) CFLAGS_linux=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ -Wimplicit -O2 -ggdb3 -fpic -LDFLAGS_linux=-O -shared -fpic -o +LDFLAGS_linux=-O -shared -fpic -o LD_linux=gcc SOCKET_linux=usocket.o @@ -189,7 +189,7 @@ CC_freebsd=gcc DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN CFLAGS_freebsd=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ -Wimplicit -O2 -ggdb3 -fpic -LDFLAGS_freebsd=-O -shared -fpic -o +LDFLAGS_freebsd=-O -shared -fpic -o LD_freebsd=gcc SOCKET_freebsd=usocket.o @@ -202,7 +202,7 @@ CC_solaris=gcc DEF_solaris=-DLUASOCKET_$(DEBUG) CFLAGS_solaris=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ -Wimplicit -O2 -ggdb3 -fpic -LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o +LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o LD_solaris=gcc SOCKET_solaris=usocket.o @@ -215,7 +215,7 @@ CC_mingw=gcc DEF_mingw= -DLUASOCKET_$(DEBUG) \ -DWINVER=0x0501 CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common -LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o +LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o LD_mingw=gcc SOCKET_mingw=wsocket.o -- cgit v1.2.3-55-g6feb From 1d61853ab84f0724502205f45849c2347d6a49ac Mon Sep 17 00:00:00 2001 From: Robert Scheck Date: Mon, 28 Mar 2022 13:53:32 +0200 Subject: chore: Update internal version references to match release (#370) --- docs/installation.html | 2 +- makefile.dist | 2 +- src/luasocket.h | 2 +- src/makefile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/makefile') diff --git a/docs/installation.html b/docs/installation.html index 28a9fbb..dcf9d36 100644 --- a/docs/installation.html +++ b/docs/installation.html @@ -89,7 +89,7 @@ it should be easy to use LuaSocket. Just fire the interpreter and use the Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio > socket = require("socket") > print(socket._VERSION) ---> LuaSocket 3.0-rc1 +--> LuaSocket 3.0.0

Each module loads their dependencies automatically, so you only need to diff --git a/makefile.dist b/makefile.dist index 3a2e100..a27ba57 100644 --- a/makefile.dist +++ b/makefile.dist @@ -1,7 +1,7 @@ #-------------------------------------------------------------------------- # Distribution makefile #-------------------------------------------------------------------------- -DIST = luasocket-3.0-rc1 +DIST = luasocket-3.0.0 TEST = \ test/README \ diff --git a/src/luasocket.h b/src/luasocket.h index d22b1be..1017fba 100644 --- a/src/luasocket.h +++ b/src/luasocket.h @@ -10,7 +10,7 @@ /*-------------------------------------------------------------------------* \ * Current socket library version \*-------------------------------------------------------------------------*/ -#define LUASOCKET_VERSION "LuaSocket 3.0-rc1" +#define LUASOCKET_VERSION "LuaSocket 3.0.0" #define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab" /*-------------------------------------------------------------------------*\ diff --git a/src/makefile b/src/makefile index f95498a..06f4d19 100755 --- a/src/makefile +++ b/src/makefile @@ -272,7 +272,7 @@ SOCKET_win64=wsocket.obj # SO=$(SO_$(PLAT)) O=$(O_$(PLAT)) -SOCKET_V=3.0-rc1 +SOCKET_V=3.0.0 MIME_V=1.0.3 SOCKET_SO=socket-$(SOCKET_V).$(SO) MIME_SO=mime-$(MIME_V).$(SO) -- cgit v1.2.3-55-g6feb