From 833333e1311b531ffbf3f7051da1ec5287a682b5 Mon Sep 17 00:00:00 2001 From: kobra Date: Thu, 12 Sep 2013 00:46:32 +0100 Subject: [PATCH 001/194] Added ability to set the option `reuseport` of a tcp socket. --- src/options.h | 2 +- src/tcp.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/options.h b/src/options.h index 5657a06..f7048b1 100644 --- a/src/options.h +++ b/src/options.h @@ -44,7 +44,7 @@ int opt_get_reuseaddr(lua_State *L, p_socket ps); int opt_get_tcp_nodelay(lua_State *L, p_socket ps); int opt_get_keepalive(lua_State *L, p_socket ps); int opt_get_linger(lua_State *L, p_socket ps); -int opt_get_reuseaddr(lua_State *L, p_socket ps); +int opt_get_reuseport(lua_State *L, p_socket ps); int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); int opt_get_ip_multicast_if(lua_State *L, p_socket ps); int opt_get_error(lua_State *L, p_socket ps); diff --git a/src/tcp.c b/src/tcp.c index 6594bda..d0658a3 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -71,6 +71,7 @@ static luaL_Reg tcp_methods[] = { static t_opt optget[] = { {"keepalive", opt_get_keepalive}, {"reuseaddr", opt_get_reuseaddr}, + {"reuseport", opt_get_reuseport}, {"tcp-nodelay", opt_get_tcp_nodelay}, {"linger", opt_get_linger}, {"error", opt_get_error}, @@ -80,6 +81,7 @@ static t_opt optget[] = { static t_opt optset[] = { {"keepalive", opt_set_keepalive}, {"reuseaddr", opt_set_reuseaddr}, + {"reuseport", opt_set_reuseport}, {"tcp-nodelay", opt_set_tcp_nodelay}, {"ipv6-v6only", opt_set_ip6_v6only}, {"linger", opt_set_linger}, From 2906d6a5227df25f14305c373fdde057f388d363 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Fri, 5 Dec 2014 13:17:50 +0100 Subject: [PATCH 002/194] Add "tcp-keepidle", "tcp-keepcnt" and "tcp-keepintvl" options --- doc/tcp.html | 6 ++++++ src/options.c | 36 ++++++++++++++++++++++++++++++++++++ src/options.h | 18 ++++++++++++++++++ src/tcp.c | 18 ++++++++++++++++++ test/tcp-getoptions | 4 +++- 5 files changed, 81 insertions(+), 1 deletion(-) diff --git a/doc/tcp.html b/doc/tcp.html index 4226d78..4307234 100644 --- a/doc/tcp.html +++ b/doc/tcp.html @@ -433,6 +433,12 @@ used in validating addresses supplied in a call to
  • 'tcp-nodelay': Setting this option to true disables the Nagle's algorithm for the connection; +
  • 'tcp-keepidle': value in seconds for TCP_KEEPIDLE Linux only!! + +
  • 'tcp-keepcnt': value for TCP_KEEPCNT Linux only!! + +
  • 'tcp-keepintvl': value for TCP_KEEPINTVL Linux only!! +
  • 'ipv6-v6only': Setting this option to true restricts an inet6 socket to sending and receiving only IPv6 packets. diff --git a/src/options.c b/src/options.c index 8ac2a14..28fc08a 100644 --- a/src/options.c +++ b/src/options.c @@ -90,6 +90,42 @@ int opt_get_tcp_nodelay(lua_State *L, p_socket ps) return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); } +#ifdef TCP_KEEPIDLE +int opt_get_tcp_keepidle(lua_State *L, p_socket ps) +{ + return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE); +} + +int opt_set_tcp_keepidle(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE); +} +#endif + +#ifdef TCP_KEEPCNT +int opt_get_tcp_keepcnt(lua_State *L, p_socket ps) +{ + return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPCNT); +} + +int opt_set_tcp_keepcnt(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPCNT); +} +#endif + +#ifdef TCP_KEEPINTVL +int opt_get_tcp_keepintvl(lua_State *L, p_socket ps) +{ + return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL); +} + +int opt_set_tcp_keepintvl(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL); +} +#endif + int opt_set_keepalive(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); diff --git a/src/options.h b/src/options.h index 5657a06..2b6697b 100644 --- a/src/options.h +++ b/src/options.h @@ -23,6 +23,15 @@ int opt_set_dontroute(lua_State *L, p_socket ps); int opt_set_broadcast(lua_State *L, p_socket ps); int opt_set_reuseaddr(lua_State *L, p_socket ps); int opt_set_tcp_nodelay(lua_State *L, p_socket ps); +#ifdef TCP_KEEPIDLE +int opt_set_tcp_keepidle(lua_State *L, p_socket ps); +#endif +#ifdef TCP_KEEPCNT +int opt_set_tcp_keepcnt(lua_State *L, p_socket ps); +#endif +#ifdef TCP_KEEPINTVL +int opt_set_tcp_keepintvl(lua_State *L, p_socket ps); +#endif int opt_set_keepalive(lua_State *L, p_socket ps); int opt_set_linger(lua_State *L, p_socket ps); int opt_set_reuseaddr(lua_State *L, p_socket ps); @@ -42,6 +51,15 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps); /* supported options for getoption */ int opt_get_reuseaddr(lua_State *L, p_socket ps); int opt_get_tcp_nodelay(lua_State *L, p_socket ps); +#ifdef TCP_KEEPIDLE +int opt_get_tcp_keepidle(lua_State *L, p_socket ps); +#endif +#ifdef TCP_KEEPCNT +int opt_get_tcp_keepcnt(lua_State *L, p_socket ps); +#endif +#ifdef TCP_KEEPINTVL +int opt_get_tcp_keepintvl(lua_State *L, p_socket ps); +#endif int opt_get_keepalive(lua_State *L, p_socket ps); int opt_get_linger(lua_State *L, p_socket ps); int opt_get_reuseaddr(lua_State *L, p_socket ps); diff --git a/src/tcp.c b/src/tcp.c index 6594bda..3af9a39 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -72,6 +72,15 @@ static t_opt optget[] = { {"keepalive", opt_get_keepalive}, {"reuseaddr", opt_get_reuseaddr}, {"tcp-nodelay", opt_get_tcp_nodelay}, +#ifdef TCP_KEEPIDLE + {"tcp-keepidle", opt_get_tcp_keepidle}, +#endif +#ifdef TCP_KEEPCNT + {"tcp-keepcnt", opt_get_tcp_keepcnt}, +#endif +#ifdef TCP_KEEPINTVL + {"tcp-keepintvl", opt_get_tcp_keepintvl}, +#endif {"linger", opt_get_linger}, {"error", opt_get_error}, {NULL, NULL} @@ -81,6 +90,15 @@ static t_opt optset[] = { {"keepalive", opt_set_keepalive}, {"reuseaddr", opt_set_reuseaddr}, {"tcp-nodelay", opt_set_tcp_nodelay}, +#ifdef TCP_KEEPIDLE + {"tcp-keepidle", opt_set_tcp_keepidle}, +#endif +#ifdef TCP_KEEPCNT + {"tcp-keepcnt", opt_set_tcp_keepcnt}, +#endif +#ifdef TCP_KEEPINTVL + {"tcp-keepintvl", opt_set_tcp_keepintvl}, +#endif {"ipv6-v6only", opt_set_ip6_v6only}, {"linger", opt_set_linger}, {NULL, NULL} diff --git a/test/tcp-getoptions b/test/tcp-getoptions index f9b3d1b..777ccc3 100755 --- a/test/tcp-getoptions +++ b/test/tcp-getoptions @@ -7,7 +7,9 @@ port = 8765 function options(o) print("options for", o) - for _, opt in ipairs{"keepalive", "reuseaddr", "tcp-nodelay"} do + for _, opt in ipairs{ + "keepalive", "reuseaddr", + "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do print("getoption", opt, o:getoption(opt)) end From fd729b32a8966291f007567f72f3dc0158bdab35 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Mon, 5 Oct 2015 11:47:51 +0800 Subject: [PATCH 003/194] Added support for arbitrary datagram sizes. The maximum size is still constant per UDP object, but the size can be speficied at creation time. --- doc/udp.html | 34 ++++++++++++++++++++++++------ src/udp.c | 58 +++++++++++++++++++++++++++++++++------------------- src/udp.h | 5 +++-- 3 files changed, 68 insertions(+), 29 deletions(-) diff --git a/doc/udp.html b/doc/udp.html index a300f2f..22d7c72 100644 --- a/doc/udp.html +++ b/doc/udp.html @@ -42,7 +42,7 @@

    -socket.udp() +socket.udp([buffersize])

    @@ -62,6 +62,13 @@ The setpeername is used to connect the object.

    +

    +The optional buffersize parameter +specifies the size of the largest datagram that will +ever be received by the UDP object. The default value is +8192. +

    +

    In case of success, a new unconnected UDP object returned. In case of error, nil is returned, followed by @@ -85,7 +92,7 @@ href=#setoption>setoption will fail.

    -socket.udp4() +socket.udp4([buffersize])

    @@ -105,6 +112,13 @@ The setpeername is used to connect the object.

    +

    +The optional buffersize parameter +specifies the size of the largest datagram that will +ever be received by the UDP object. The default value is +8192. +

    +

    In case of success, a new unconnected UDP object returned. In case of error, nil is returned, followed by @@ -114,7 +128,7 @@ an error message.

    -socket.udp6() +socket.udp6([buffersize])

    @@ -134,6 +148,13 @@ The setpeername is used to connect the object.

    +

    +The optional buffersize parameter +specifies the size of the largest datagram that will +ever be received by the UDP object. The default value is +8192. +

    +

    In case of success, a new unconnected UDP object returned. In case of error, nil is returned, followed by @@ -238,9 +259,10 @@ specifies the maximum size of the datagram to be retrieved. If there are more than size bytes available in the datagram, the excess bytes are discarded. If there are less then size bytes available in the current datagram, the -available bytes are returned. If size is omitted, the -maximum datagram size is used (which is currently limited by the -implementation to 8192 bytes). +available bytes are returned. +If size is omitted, the +buffersize argument at creation time is used +(which defaults to 8192 bytes).

    diff --git a/src/udp.c b/src/udp.c index 17d932a..9c27b60 100644 --- a/src/udp.c +++ b/src/udp.c @@ -41,6 +41,7 @@ static int meth_setpeername(lua_State *L); static int meth_close(lua_State *L); static int meth_setoption(lua_State *L); static int meth_getoption(lua_State *L); +static int meth_getbufferlength(lua_State *L); static int meth_settimeout(lua_State *L); static int meth_getfd(lua_State *L); static int meth_setfd(lua_State *L); @@ -63,6 +64,7 @@ static luaL_Reg udp_methods[] = { {"setfd", meth_setfd}, {"setoption", meth_setoption}, {"getoption", meth_getoption}, + {"getoption", meth_getbufferlength}, {"setpeername", meth_setpeername}, {"setsockname", meth_setsockname}, {"settimeout", meth_settimeout}, @@ -202,47 +204,55 @@ static int meth_sendto(lua_State *L) { \*-------------------------------------------------------------------------*/ static int meth_receive(lua_State *L) { p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1); - char buffer[UDP_DATAGRAMSIZE]; - size_t got, count = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); + char buf[UDP_DATAGRAMSIZE]; + size_t len = MAX(udp->len, UDP_DATAGRAMSIZE); + char *dgram = len > sizeof(buf)? udp->buf: buf; + size_t got, wanted = (size_t) luaL_optnumber(L, 2, len); int err; p_timeout tm = &udp->tm; - count = MIN(count, sizeof(buffer)); timeout_markstart(tm); - err = socket_recv(&udp->sock, buffer, count, &got, tm); + wanted = MIN(wanted, len); + err = socket_recv(&udp->sock, dgram, wanted, &got, tm); /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ - if (err == IO_CLOSED) - err = IO_DONE; - if (err != IO_DONE) { + if (err != IO_DONE && err != IO_CLOSED ) { lua_pushnil(L); lua_pushstring(L, udp_strerror(err)); return 2; } - lua_pushlstring(L, buffer, got); + lua_pushlstring(L, dgram, got); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Receives data from a UDP socket +\*-------------------------------------------------------------------------*/ +static int meth_getbufferlength(lua_State *L) { + p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1); + lua_pushinteger(L, MAX(UDP_DATAGRAMSIZE, udp->len)); return 1; } /*-------------------------------------------------------------------------*\ * Receives data and sender from a UDP socket \*-------------------------------------------------------------------------*/ -static int meth_receivefrom(lua_State *L) -{ +static int meth_receivefrom(lua_State *L) { p_udp udp = (p_udp) auxiliar_checkclass(L, "udp{unconnected}", 1); - char buffer[UDP_DATAGRAMSIZE]; - size_t got, count = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); - int err; - p_timeout tm = &udp->tm; + char buf[UDP_DATAGRAMSIZE]; + size_t len = MAX(udp->len, UDP_DATAGRAMSIZE); + char *dgram = len > sizeof(buf)? udp->buf: buf; + size_t got, wanted = (size_t) luaL_optnumber(L, 2, len); struct sockaddr_storage addr; socklen_t addr_len = sizeof(addr); char addrstr[INET6_ADDRSTRLEN]; char portstr[6]; + int err; + p_timeout tm = &udp->tm; timeout_markstart(tm); - count = MIN(count, sizeof(buffer)); - err = socket_recvfrom(&udp->sock, buffer, count, &got, (SA *) &addr, + wanted = MIN(wanted, len); + err = socket_recvfrom(&udp->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_CLOSED) - err = IO_DONE; - if (err != IO_DONE) { + if (err != IO_DONE && err != IO_CLOSED) { lua_pushnil(L); lua_pushstring(L, udp_strerror(err)); return 2; @@ -254,7 +264,7 @@ static int meth_receivefrom(lua_State *L) lua_pushstring(L, gai_strerror(err)); return 2; } - lua_pushlstring(L, buffer, got); + lua_pushlstring(L, dgram, got); lua_pushstring(L, addrstr); lua_pushinteger(L, (int) strtol(portstr, (char **) NULL, 10)); return 3; @@ -409,13 +419,19 @@ static int meth_setsockname(lua_State *L) { * Creates a master udp object \*-------------------------------------------------------------------------*/ static int udp_create(lua_State *L, int family) { + p_udp udp = NULL; + /* optional length for private datagram buffer. this is useful when + * you need larger datagrams than UDP_DATAGRAMSIZE */ + size_t len = (size_t) luaL_optinteger(L, 1, 0); + if (len <= UDP_DATAGRAMSIZE) len = 0; /* allocate udp object */ - p_udp udp = (p_udp) lua_newuserdata(L, sizeof(t_udp)); + udp = (p_udp) lua_newuserdata(L, sizeof(t_udp) + len - 1); auxiliar_setclass(L, "udp{unconnected}", -1); /* if family is AF_UNSPEC, we leave the socket invalid and * store AF_UNSPEC into family. This will allow it to later be * replaced with an AF_INET6 or AF_INET socket upon first use. */ udp->sock = SOCKET_INVALID; + udp->len = len; timeout_init(&udp->tm, -1, -1); udp->family = family; if (family != AF_UNSPEC) { diff --git a/src/udp.h b/src/udp.h index 2b831a5..da27a7a 100644 --- a/src/udp.h +++ b/src/udp.h @@ -8,7 +8,7 @@ * (AF_INET, SOCK_DGRAM). * * Two classes are defined: connected and unconnected. UDP objects are -* originally unconnected. They can be "connected" to a given address +* 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. \*=========================================================================*/ @@ -17,13 +17,14 @@ #include "timeout.h" #include "socket.h" -/* can't be larger than wsocket.c MAXCHUNK!!! */ #define UDP_DATAGRAMSIZE 8192 typedef struct t_udp_ { t_socket sock; t_timeout tm; int family; + size_t len; /* length of datagram buffer below */ + char buf[1]; /* allocate larger structure to hold actual buffer */ } t_udp; typedef t_udp *p_udp; From be67f63f4e11e53690bf1431a236f86b484c9bf0 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Tue, 6 Oct 2015 11:33:50 +0800 Subject: [PATCH 004/194] Changed buffer-per-socket to buffer-per-operation. This is a difficult tradeoff to measure. I think large datagrams won't be used very frequently. So it is better to not lock a large buffer to each socket object and instead allocate and deallocate for each operation receiving a datagram larger than UDP_DATAGRAMSIZE. --- doc/reference.html | 2 ++ doc/socket.html | 25 +++++++++++++++++++- doc/udp.html | 33 ++++++-------------------- src/select.c | 5 +++- src/udp.c | 58 +++++++++++++++++++++------------------------- src/udp.h | 2 -- test/testclnt.lua | 1 - 7 files changed, 64 insertions(+), 62 deletions(-) diff --git a/doc/reference.html b/doc/reference.html index 6067ba6..878e7d2 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -147,6 +147,7 @@ Support, Manual"> connect, connect4, connect6, +_DATAGRAMSIZE, _DEBUG, dns, gettime, @@ -158,6 +159,7 @@ Support, Manual"> skip, sleep, _SETSIZE, +_SOCKETINVALID, source, tcp, tcp4, diff --git a/doc/socket.html b/doc/socket.html index e6a9bf8..8a81414 100644 --- a/doc/socket.html +++ b/doc/socket.html @@ -90,7 +90,7 @@ of connect are defined as simple helper functions that restrict the -

    +

    socket._DEBUG

    @@ -99,6 +99,19 @@ This constant is set to true if the library was compiled with debug support.

    + + +

    +socket._DATAGRAMSIZE +

    + +

    +Default datagram size used by calls to +receive and +receivefrom. +(Unless changed in compile time, the value is 8192.) +

    +

    @@ -393,6 +406,16 @@ The maximum number of sockets that the select function can handle.

    + + +

    +socket._SOCKETINVALID +

    + +

    +The OS value for an invalid socket. +

    +

    diff --git a/doc/udp.html b/doc/udp.html index 22d7c72..9437c51 100644 --- a/doc/udp.html +++ b/doc/udp.html @@ -42,7 +42,7 @@

    -socket.udp([buffersize]) +socket.udp()

    @@ -62,13 +62,6 @@ The setpeername is used to connect the object.

    -

    -The optional buffersize parameter -specifies the size of the largest datagram that will -ever be received by the UDP object. The default value is -8192. -

    -

    In case of success, a new unconnected UDP object returned. In case of error, nil is returned, followed by @@ -92,7 +85,7 @@ href=#setoption>setoption will fail.

    -socket.udp4([buffersize]) +socket.udp4()

    @@ -112,13 +105,6 @@ The setpeername is used to connect the object.

    -

    -The optional buffersize parameter -specifies the size of the largest datagram that will -ever be received by the UDP object. The default value is -8192. -

    -

    In case of success, a new unconnected UDP object returned. In case of error, nil is returned, followed by @@ -128,7 +114,7 @@ an error message.

    -socket.udp6([buffersize]) +socket.udp6()

    @@ -148,13 +134,6 @@ The setpeername is used to connect the object.

    -

    -The optional buffersize parameter -specifies the size of the largest datagram that will -ever be received by the UDP object. The default value is -8192. -

    -

    In case of success, a new unconnected UDP object returned. In case of error, nil is returned, followed by @@ -261,8 +240,10 @@ the excess bytes are discarded. If there are less then size bytes available in the current datagram, the available bytes are returned. If size is omitted, the -buffersize argument at creation time is used -(which defaults to 8192 bytes). +compile-time constant socket._DATAGRAMSIZE is used +(it defaults to 8192 bytes). Larger sizes will cause a +temporary buffer to be allocated for the operation.

    diff --git a/src/select.c b/src/select.c index d14c40a..9d133b7 100644 --- a/src/select.c +++ b/src/select.c @@ -39,7 +39,10 @@ static luaL_Reg func[] = { \*-------------------------------------------------------------------------*/ int select_open(lua_State *L) { lua_pushstring(L, "_SETSIZE"); - lua_pushnumber(L, FD_SETSIZE); + lua_pushinteger(L, FD_SETSIZE); + lua_rawset(L, -3); + lua_pushstring(L, "_SOCKETINVALID"); + lua_pushinteger(L, SOCKET_INVALID); lua_rawset(L, -3); luaL_setfuncs(L, func, 0); return 0; diff --git a/src/udp.c b/src/udp.c index 9c27b60..968dca8 100644 --- a/src/udp.c +++ b/src/udp.c @@ -41,7 +41,6 @@ static int meth_setpeername(lua_State *L); static int meth_close(lua_State *L); static int meth_setoption(lua_State *L); static int meth_getoption(lua_State *L); -static int meth_getbufferlength(lua_State *L); static int meth_settimeout(lua_State *L); static int meth_getfd(lua_State *L); static int meth_setfd(lua_State *L); @@ -64,7 +63,6 @@ static luaL_Reg udp_methods[] = { {"setfd", meth_setfd}, {"setoption", meth_setoption}, {"getoption", meth_getoption}, - {"getoption", meth_getbufferlength}, {"setpeername", meth_setpeername}, {"setsockname", meth_setsockname}, {"settimeout", meth_settimeout}, @@ -118,8 +116,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int udp_open(lua_State *L) -{ +int udp_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "udp{connected}", udp_methods); auxiliar_newclass(L, "udp{unconnected}", udp_methods); @@ -130,6 +127,10 @@ int udp_open(lua_State *L) auxiliar_add2group(L, "udp{unconnected}", "select{able}"); /* define library functions */ luaL_setfuncs(L, func, 0); + /* export default UDP size */ + lua_pushliteral(L, "_DATAGRAMSIZE"); + lua_pushinteger(L, UDP_DATAGRAMSIZE); + lua_rawset(L, -3); return 0; } @@ -205,30 +206,26 @@ static int meth_sendto(lua_State *L) { static int meth_receive(lua_State *L) { p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1); char buf[UDP_DATAGRAMSIZE]; - size_t len = MAX(udp->len, UDP_DATAGRAMSIZE); - char *dgram = len > sizeof(buf)? udp->buf: buf; - size_t got, wanted = (size_t) luaL_optnumber(L, 2, len); + 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 = &udp->tm; timeout_markstart(tm); - wanted = MIN(wanted, len); + if (!dgram) { + lua_pushnil(L); + lua_pushliteral(L, "out of memory"); + return 2; + } err = socket_recv(&udp->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 ) { + if (err != IO_DONE && err != IO_CLOSED) { lua_pushnil(L); lua_pushstring(L, udp_strerror(err)); + if (wanted > sizeof(buf)) free(dgram); return 2; } lua_pushlstring(L, dgram, got); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Receives data from a UDP socket -\*-------------------------------------------------------------------------*/ -static int meth_getbufferlength(lua_State *L) { - p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1); - lua_pushinteger(L, MAX(UDP_DATAGRAMSIZE, udp->len)); + if (wanted > sizeof(buf)) free(dgram); return 1; } @@ -238,9 +235,8 @@ static int meth_getbufferlength(lua_State *L) { static int meth_receivefrom(lua_State *L) { p_udp udp = (p_udp) auxiliar_checkclass(L, "udp{unconnected}", 1); char buf[UDP_DATAGRAMSIZE]; - size_t len = MAX(udp->len, UDP_DATAGRAMSIZE); - char *dgram = len > sizeof(buf)? udp->buf: buf; - size_t got, wanted = (size_t) luaL_optnumber(L, 2, len); + size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); + char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; struct sockaddr_storage addr; socklen_t addr_len = sizeof(addr); char addrstr[INET6_ADDRSTRLEN]; @@ -248,13 +244,18 @@ static int meth_receivefrom(lua_State *L) { int err; p_timeout tm = &udp->tm; timeout_markstart(tm); - wanted = MIN(wanted, len); + if (!dgram) { + lua_pushnil(L); + lua_pushliteral(L, "out of memory"); + return 2; + } err = socket_recvfrom(&udp->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, udp_strerror(err)); + if (wanted > sizeof(buf)) free(dgram); return 2; } err = getnameinfo((struct sockaddr *)&addr, addr_len, addrstr, @@ -262,19 +263,20 @@ static int meth_receivefrom(lua_State *L) { if (err) { lua_pushnil(L); lua_pushstring(L, gai_strerror(err)); + if (wanted > sizeof(buf)) free(dgram); return 2; } lua_pushlstring(L, dgram, got); lua_pushstring(L, addrstr); lua_pushinteger(L, (int) strtol(portstr, (char **) NULL, 10)); + if (wanted > sizeof(buf)) free(dgram); return 3; } /*-------------------------------------------------------------------------*\ * Returns family as string \*-------------------------------------------------------------------------*/ -static int meth_getfamily(lua_State *L) -{ +static int meth_getfamily(lua_State *L) { p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1); if (udp->family == AF_INET6) { lua_pushliteral(L, "inet6"); @@ -419,19 +421,13 @@ static int meth_setsockname(lua_State *L) { * Creates a master udp object \*-------------------------------------------------------------------------*/ static int udp_create(lua_State *L, int family) { - p_udp udp = NULL; - /* optional length for private datagram buffer. this is useful when - * you need larger datagrams than UDP_DATAGRAMSIZE */ - size_t len = (size_t) luaL_optinteger(L, 1, 0); - if (len <= UDP_DATAGRAMSIZE) len = 0; /* allocate udp object */ - udp = (p_udp) lua_newuserdata(L, sizeof(t_udp) + len - 1); + p_udp udp = (p_udp) lua_newuserdata(L, sizeof(t_udp)); auxiliar_setclass(L, "udp{unconnected}", -1); /* if family is AF_UNSPEC, we leave the socket invalid and * store AF_UNSPEC into family. This will allow it to later be * replaced with an AF_INET6 or AF_INET socket upon first use. */ udp->sock = SOCKET_INVALID; - udp->len = len; timeout_init(&udp->tm, -1, -1); udp->family = family; if (family != AF_UNSPEC) { diff --git a/src/udp.h b/src/udp.h index da27a7a..be9b6a5 100644 --- a/src/udp.h +++ b/src/udp.h @@ -23,8 +23,6 @@ typedef struct t_udp_ { t_socket sock; t_timeout tm; int family; - size_t len; /* length of datagram buffer below */ - char buf[1]; /* allocate larger structure to hold actual buffer */ } t_udp; typedef t_udp *p_udp; diff --git a/test/testclnt.lua b/test/testclnt.lua index ee1201f..170e187 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua @@ -669,7 +669,6 @@ local udp_methods = { "settimeout" } - ------------------------------------------------------------------------ test_methods(socket.udp(), udp_methods) do local sock = socket.tcp6() From 83880dbed77f9a0a3627bce2e7bfbe1b862e091d Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Thu, 3 Dec 2015 12:56:18 -0200 Subject: [PATCH 005/194] When zero-timeout, only try first address in connect. --- doc/tcp.html | 13 ++++++++----- src/inet.c | 4 ++-- src/tcp.c | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/doc/tcp.html b/doc/tcp.html index fb627a1..c86853d 100644 --- a/doc/tcp.html +++ b/doc/tcp.html @@ -242,11 +242,14 @@ established.

    Note: Starting with LuaSocket 3.0, the host name resolution -depends on whether the socket was created by socket.tcp or socket.tcp6. Addresses from -the appropriate family are tried in succession until the -first success or until the last failure. +depends on whether the socket was created by +socket.tcp, +socket.tcp4 or +socket.tcp6. Addresses from +the appropriate family (or both) are tried in the order +returned by the resolver until the +first success or until the last failure. If the timeout was +set to zero, only the first address is tried.

    diff --git a/src/inet.c b/src/inet.c index 331b800..f4c8404 100644 --- a/src/inet.c +++ b/src/inet.c @@ -423,8 +423,8 @@ const char *inet_tryconnect(p_socket ps, int *family, const char *address, /* try connecting to remote address */ err = socket_strerror(socket_connect(ps, (SA *) iterator->ai_addr, (socklen_t) iterator->ai_addrlen, tm)); - /* if success, break out of loop */ - if (err == NULL) { + /* if success or timeout is zero, break out of loop */ + if (err == NULL || timeout_iszero(tm)) { *family = current_family; break; } diff --git a/src/tcp.c b/src/tcp.c index cef9d16..e4f1a4b 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -417,7 +417,7 @@ static int global_connect(lua_State *L) { bindhints.ai_family = family; bindhints.ai_flags = AI_PASSIVE; if (localaddr) { - err = inet_trybind(&tcp->sock, &tcp->family, localaddr, + err = inet_trybind(&tcp->sock, &tcp->family, localaddr, localserv, &bindhints); if (err) { lua_pushnil(L); @@ -429,7 +429,7 @@ static int global_connect(lua_State *L) { memset(&connecthints, 0, sizeof(connecthints)); connecthints.ai_socktype = SOCK_STREAM; /* make sure we try to connect only to the same family */ - connecthints.ai_family = tcp->family; + connecthints.ai_family = tcp->family; err = inet_tryconnect(&tcp->sock, &tcp->family, remoteaddr, remoteserv, &tcp->tm, &connecthints); if (err) { From 5d52ffedf49ca14af2926eac9ddbf9bfc5e8c56c Mon Sep 17 00:00:00 2001 From: Jonas Kunze Date: Fri, 15 Jan 2016 18:48:57 +0100 Subject: [PATCH 006/194] 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 --- makefile | 2 +- src/makefile | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/makefile b/makefile index e34f5a9..cc15b4e 100644 --- a/makefile +++ b/makefile @@ -10,7 +10,7 @@ # print print the build settings PLAT?= linux -PLATS= macosx linux win32 mingw freebsd +PLATS= macosx linux win32 mingw freebsd solaris all: $(PLAT) 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" From a7f21e8ec44586fafd5a6a2ffaaf721b69d86f6e Mon Sep 17 00:00:00 2001 From: mpeterv Date: Mon, 25 Jan 2016 13:52:41 +0300 Subject: [PATCH 007/194] Fix error in ltn12 under Lua 5.3 --- src/ltn12.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ltn12.lua b/src/ltn12.lua index 1014de2..f75cd07 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua @@ -9,6 +9,7 @@ ----------------------------------------------------------------------------- local string = require("string") local table = require("table") +local unpack = unpack or table.unpack local base = _G local _M = {} if module then -- heuristic for exporting a global package table From 3c3a5d001138f7c4630aea595da0e93ed247ec34 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 11 Feb 2016 15:53:53 +0300 Subject: [PATCH 008/194] Use base.select instead of just select --- src/ltn12.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ltn12.lua b/src/ltn12.lua index f75cd07..dede0fa 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua @@ -43,7 +43,7 @@ end -- (thanks to Wim Couwenberg) function filter.chain(...) local arg = {...} - local n = select('#',...) + local n = base.select('#',...) local top, index = 1, 1 local retry = "" return function(chunk) From 700ece0721b4b1b70da413f15c5df7dcbae0fe3b Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 11 Feb 2016 15:54:59 +0300 Subject: [PATCH 009/194] Fix base_parsed global in url module --- src/url.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/src/url.lua b/src/url.lua index 7809535..fbd93d1 100644 --- a/src/url.lua +++ b/src/url.lua @@ -219,6 +219,7 @@ end -- corresponding absolute url ----------------------------------------------------------------------------- function _M.absolute(base_url, relative_url) + local base_parsed if base.type(base_url) == "table" then base_parsed = base_url base_url = _M.build(base_parsed) From 52bb99af35159700814d78687e9d95142feb1a9c Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 11 Feb 2016 15:56:57 +0300 Subject: [PATCH 010/194] Fix sink method in tp module --- src/tp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tp.lua b/src/tp.lua index cbeff56..328cbab 100644 --- a/src/tp.lua +++ b/src/tp.lua @@ -74,7 +74,7 @@ function metat.__index:command(cmd, arg) end function metat.__index:sink(snk, pat) - local chunk, err = c:receive(pat) + local chunk, err = self.c:receive(pat) return snk(chunk, err) end From 91928813466cd10b1b4e6f118f2decfb3b2aba33 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 11 Feb 2016 15:57:56 +0300 Subject: [PATCH 011/194] Don't break global mbox table in mbox.split_mbox --- src/mbox.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mbox.lua b/src/mbox.lua index 7724ae2..ed9e781 100644 --- a/src/mbox.lua +++ b/src/mbox.lua @@ -61,7 +61,7 @@ function _M.parse_from(from) end function _M.split_mbox(mbox_s) - mbox = {} + local mbox = {} mbox_s = string.gsub(mbox_s, "\r\n", "\n") .."\n\nFrom \n" local nj, i, j = 1, 1, 1 while 1 do From d075e7322f0ac1de505b025fd3004b8d4123cc56 Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Sun, 21 Feb 2016 11:59:44 +0100 Subject: [PATCH 012/194] Support table errors. LuaSocket wraps error messages raised by newtry() in a table and unpacks them later so that (string) errors raised by 3rd-party code can be passed through as-is. This obviously didn't work when the 3rd-party code raised a table as an error message. This change sets a private metatable on all wrapped LuaSocket exceptions to distinguish them from 3rd-party table errors. --- src/except.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/except.c b/src/except.c index 261ac98..def35a0 100644 --- a/src/except.c +++ b/src/except.c @@ -12,7 +12,7 @@ #if LUA_VERSION_NUM < 502 #define lua_pcallk(L, na, nr, err, ctx, cont) \ - ((void)ctx,(void)cont,lua_pcall(L, na, nr, err)) + (((void)ctx),((void)cont),lua_pcall(L, na, nr, err)) #endif #if LUA_VERSION_NUM < 503 @@ -39,12 +39,11 @@ static luaL_Reg func[] = { * Try factory \*-------------------------------------------------------------------------*/ static void wrap(lua_State *L) { - lua_newtable(L); - lua_pushnumber(L, 1); - lua_pushvalue(L, -3); - lua_settable(L, -3); - lua_insert(L, -2); - lua_pop(L, 1); + lua_createtable(L, 1, 0); + lua_pushvalue(L, -2); + lua_rawseti(L, -2, 1); + lua_pushvalue(L, lua_upvalueindex(2)); + lua_setmetatable(L, -2); } static int finalize(lua_State *L) { @@ -58,15 +57,16 @@ static int finalize(lua_State *L) { } else return lua_gettop(L); } -static int do_nothing(lua_State *L) { +static int do_nothing(lua_State *L) { (void) L; - return 0; + return 0; } static int global_newtry(lua_State *L) { lua_settop(L, 1); if (lua_isnil(L, 1)) lua_pushcfunction(L, do_nothing); - lua_pushcclosure(L, finalize, 1); + lua_pushvalue(L, lua_upvalueindex(1)); + lua_pushcclosure(L, finalize, 2); return 1; } @@ -74,13 +74,16 @@ static int global_newtry(lua_State *L) { * Protect factory \*-------------------------------------------------------------------------*/ static int unwrap(lua_State *L) { - if (lua_istable(L, -1)) { - lua_pushnumber(L, 1); - lua_gettable(L, -2); - lua_pushnil(L); - lua_insert(L, -2); - return 1; - } else return 0; + if (lua_istable(L, -1) && lua_getmetatable(L, -1)) { + int r = lua_rawequal(L, -1, lua_upvalueindex(2)); + lua_pop(L, 1); + if (r) { + lua_pushnil(L); + lua_rawgeti(L, -2, 1); + return 1; + } + } + return 0; } static int protected_finish(lua_State *L, int status, lua_KContext ctx) { @@ -110,7 +113,9 @@ static int protected_(lua_State *L) { } static int global_protect(lua_State *L) { - lua_pushcclosure(L, protected_, 1); + lua_settop(L, 1); + lua_pushvalue(L, lua_upvalueindex(1)); + lua_pushcclosure(L, protected_, 2); return 1; } @@ -118,6 +123,9 @@ static int global_protect(lua_State *L) { * Init module \*-------------------------------------------------------------------------*/ int except_open(lua_State *L) { - luaL_setfuncs(L, func, 0); + lua_newtable(L); /* metatable for wrapped exceptions */ + lua_pushboolean(L, 0); + lua_setfield(L, -2, "__metatable"); + luaL_setfuncs(L, func, 1); return 0; } From fb713cdedb16f8eb67523f17b0d66262b4e9dca1 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Mon, 25 Jan 2016 15:14:34 +0300 Subject: [PATCH 013/194] Add more tests for socket.try/protect --- test/excepttest.lua | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/test/excepttest.lua b/test/excepttest.lua index ce9f197..6904545 100644 --- a/test/excepttest.lua +++ b/test/excepttest.lua @@ -1,6 +1,31 @@ local socket = require("socket") -try = socket.newtry(function() - print("finalized!!!") + +local finalizer_called + +local func = socket.protect(function(err, ...) + local try = socket.newtry(function() + finalizer_called = true + error("ignored") + end) + + if err then + return error(err, 0) + else + return try(...) + end end) -try = socket.protect(try) -print(try(nil, "it works")) + +local ret1, ret2, ret3 = func(false, 1, 2, 3) +assert(not finalizer_called, "unexpected finalizer call") +assert(ret1 == 1 and ret2 == 2 and ret3 == 3, "incorrect return values") + +ret1, ret2, ret3 = func(false, false, "error message") +assert(finalizer_called, "finalizer not called") +assert(ret1 == nil and ret2 == "error message" and ret3 == nil, "incorrect return values") + +local err = {key = "value"} +ret1, ret2 = pcall(func, err) +assert(not ret1, "error not rethrown") +assert(ret2 == err, "incorrect error rethrown") + +print("OK") From 7c1df8a7cd4271309160abfd28fb8011a3fee46f Mon Sep 17 00:00:00 2001 From: mpeterv Date: Tue, 16 Feb 2016 11:44:02 +0300 Subject: [PATCH 014/194] Update HTML docs for try/protect --- doc/socket.html | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/doc/socket.html b/doc/socket.html index 8a81414..a43a208 100644 --- a/doc/socket.html +++ b/doc/socket.html @@ -220,13 +220,6 @@ Returns an equivalent function that instead of throwing exceptions, returns nil followed by an error message.

    -

    -Note: Beware that if your function performs some illegal operation that -raises an error, the protected function will catch the error and return it -as a string. This is because the try function -uses errors as the mechanism to throw exceptions. -

    -

    @@ -424,8 +417,7 @@ socket.try(ret1 [, ret2 ... retN]) Throws an exception in case of error. The exception can only be caught -by the protect function. It does not explode -into an error message. +by the protect function.

    @@ -436,7 +428,10 @@ nested with try.

    The function returns ret1 to retN if -ret1 is not nil. Otherwise, it calls error passing ret2. +ret1 is not nil or false. +Otherwise, it calls error passing ret2 wrapped +in a table with metatable used by protect to +distinguish exceptions from runtime errors.

    
    From 7cab8a5006da807d83f427217e2158079bb78145 Mon Sep 17 00:00:00 2001
    From: Philipp Janda 
    Date: Sun, 21 Feb 2016 12:28:13 +0100
    Subject: [PATCH 015/194] Update comment in except.h
    
    ---
     src/except.h | 23 ++++++++++++++---------
     1 file changed, 14 insertions(+), 9 deletions(-)
    
    diff --git a/src/except.h b/src/except.h
    index 1e7a245..2497c05 100644
    --- a/src/except.h
    +++ b/src/except.h
    @@ -9,21 +9,26 @@
     * error checking was taking a substantial amount of the coding. These
     * function greatly simplify the task of checking errors.
     *
    -* The main idea is that functions should return nil as its first return
    -* value when it finds an error, and return an error message (or value)
    +* The main idea is that functions should return nil as their first return
    +* values when they find an error, and return an error message (or value)
     * following nil. In case of success, as long as the first value is not nil,
     * the other values don't matter.
     *
     * The idea is to nest function calls with the "try" function. This function
    -* checks the first value, and calls "error" on the second if the first is
    -* nil. Otherwise, it returns all values it received. 
    +* checks the first value, and, if it's falsy, wraps the second value in a
    +* table with metatable and calls "error" on it. Otherwise, it returns all
    +* values it received. Basically, it works like the Lua "assert" function,
    +* but it creates errors targeted specifically at "protect".
     *
    -* The protect function returns a new function that behaves exactly like the
    -* function it receives, but the new function doesn't throw exceptions: it
    -* returns nil followed by the error message instead.
    +* The "newtry" function is a factory for "try" functions that call a
    +* finalizer in protected mode before calling "error".
     *
    -* With these two function, it's easy to write functions that throw
    -* exceptions on error, but that don't interrupt the user script. 
    +* The "protect" function returns a new function that behaves exactly like
    +* the function it receives, but the new function catches exceptions thrown
    +* by "try" functions and returns nil followed by the error message instead.
    +*
    +* With these three functions, it's easy to write functions that throw
    +* exceptions on error, but that don't interrupt the user script.
     \*=========================================================================*/
     
     #include "lua.h"
    
    From 9fe38c654f6c62a4f11d993bd79c710af9313fbd Mon Sep 17 00:00:00 2001
    From: Philipp Janda 
    Date: Wed, 24 Feb 2016 00:48:43 +0100
    Subject: [PATCH 016/194] Don't swallow errors in finalizers.
    
    ---
     doc/socket.html     | 3 +--
     src/except.c        | 2 +-
     test/excepttest.lua | 1 -
     3 files changed, 2 insertions(+), 4 deletions(-)
    
    diff --git a/doc/socket.html b/doc/socket.html
    index a43a208..08ef784 100644
    --- a/doc/socket.html
    +++ b/doc/socket.html
    @@ -167,8 +167,7 @@ is  raised.
     
     

    Finalizer is a function that will be called before -try throws the exception. It will be called -in protected mode. +try throws the exception.

    diff --git a/src/except.c b/src/except.c index def35a0..309f8f0 100644 --- a/src/except.c +++ b/src/except.c @@ -49,7 +49,7 @@ static void wrap(lua_State *L) { static int finalize(lua_State *L) { if (!lua_toboolean(L, 1)) { lua_pushvalue(L, lua_upvalueindex(1)); - lua_pcall(L, 0, 0, 0); + lua_call(L, 0, 0); lua_settop(L, 2); wrap(L); lua_error(L); diff --git a/test/excepttest.lua b/test/excepttest.lua index 6904545..80c9cb8 100644 --- a/test/excepttest.lua +++ b/test/excepttest.lua @@ -5,7 +5,6 @@ local finalizer_called local func = socket.protect(function(err, ...) local try = socket.newtry(function() finalizer_called = true - error("ignored") end) if err then From 4392bdcdd40dd433fc8bf4347653ce1a796cb572 Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Wed, 24 Feb 2016 00:57:42 +0100 Subject: [PATCH 017/194] Always put metatable in first upvalue. --- src/except.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/except.c b/src/except.c index 309f8f0..60b5005 100644 --- a/src/except.c +++ b/src/except.c @@ -42,13 +42,13 @@ static void wrap(lua_State *L) { lua_createtable(L, 1, 0); lua_pushvalue(L, -2); lua_rawseti(L, -2, 1); - lua_pushvalue(L, lua_upvalueindex(2)); + lua_pushvalue(L, lua_upvalueindex(1)); lua_setmetatable(L, -2); } static int finalize(lua_State *L) { if (!lua_toboolean(L, 1)) { - lua_pushvalue(L, lua_upvalueindex(1)); + lua_pushvalue(L, lua_upvalueindex(2)); lua_call(L, 0, 0); lua_settop(L, 2); wrap(L); @@ -66,6 +66,7 @@ static int global_newtry(lua_State *L) { lua_settop(L, 1); if (lua_isnil(L, 1)) lua_pushcfunction(L, do_nothing); lua_pushvalue(L, lua_upvalueindex(1)); + lua_insert(L, -2); lua_pushcclosure(L, finalize, 2); return 1; } @@ -75,7 +76,7 @@ static int global_newtry(lua_State *L) { \*-------------------------------------------------------------------------*/ static int unwrap(lua_State *L) { if (lua_istable(L, -1) && lua_getmetatable(L, -1)) { - int r = lua_rawequal(L, -1, lua_upvalueindex(2)); + int r = lua_rawequal(L, -1, lua_upvalueindex(1)); lua_pop(L, 1); if (r) { lua_pushnil(L); @@ -106,7 +107,7 @@ static int protected_cont(lua_State *L) { static int protected_(lua_State *L) { int status; - lua_pushvalue(L, lua_upvalueindex(1)); + lua_pushvalue(L, lua_upvalueindex(2)); lua_insert(L, 1); status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, protected_cont); return protected_finish(L, status, 0); @@ -115,6 +116,7 @@ static int protected_(lua_State *L) { static int global_protect(lua_State *L) { lua_settop(L, 1); lua_pushvalue(L, lua_upvalueindex(1)); + lua_insert(L, 1); lua_pushcclosure(L, protected_, 2); return 1; } From 0341516a2932e077b547f8105e0ea13f3f56f868 Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Wed, 24 Feb 2016 06:59:37 +0100 Subject: [PATCH 018/194] Clarify documentation for try/protect. --- doc/socket.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/socket.html b/doc/socket.html index 08ef784..fec09c4 100644 --- a/doc/socket.html +++ b/doc/socket.html @@ -215,8 +215,9 @@ to throw exceptions.

    -Returns an equivalent function that instead of throwing exceptions, -returns nil followed by an error message. +Returns an equivalent function that instead of throwing exceptions in case of +a failed try call, returns nil +followed by an error message.

    @@ -415,8 +416,9 @@ socket.try(ret1 [, ret2 ... retN])

    -Throws an exception in case of error. The exception can only be caught -by the protect function. +Throws an exception in case ret1 is falsy, using +ret2 as the error message. The exception is supposed to be caught +by a protected function only.

    From cdce73b226cc4da6a073b79bec02a6780d32ff1a Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 4 Mar 2016 14:38:56 -0300 Subject: [PATCH 019/194] Added support for FTP command lists --- doc/socket.html | 6 ++++-- src/ftp.lua | 15 ++++++++++++--- src/ltn12.lua | 3 +++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/doc/socket.html b/doc/socket.html index fec09c4..a99d71b 100644 --- a/doc/socket.html +++ b/doc/socket.html @@ -243,7 +243,9 @@ non-numeric indices) in the arrays will be silently ignored.

    The function returns a list with the sockets ready for reading, a list with the sockets ready for writing and an error message. -The error message is "timeout" if a timeout condition was met and +The error message is "timeout" if a timeout +condition was met, "select failed" if the call +to select failed, and nil otherwise. The returned tables are doubly keyed both by integers and also by the sockets themselves, to simplify the test if a specific socket has @@ -251,7 +253,7 @@ changed status.

    -Note: : select can monitor a limited number +Note: select can monitor a limited number of sockets, as defined by the constant socket._SETSIZE. This number may be as high as 1024 or as low as 64 by default, depending on the system. It is usually possible to change this diff --git a/src/ftp.lua b/src/ftp.lua index 917cd89..e0c3cae 100644 --- a/src/ftp.lua +++ b/src/ftp.lua @@ -271,8 +271,17 @@ _M.command = socket.protect(function(cmdt) local f = _M.open(cmdt.host, cmdt.port, cmdt.create) f:greet() f:login(cmdt.user, cmdt.password) - f.try(f.tp:command(cmdt.command, cmdt.argument)) - if cmdt.check then f.try(f.tp:check(cmdt.check)) end + if type(cmdt.command) == "table" then + local argument = cmdt.argument or {} + local check = cmdt.check or {} + for i,cmd in ipairs(cmdt.command) do + f.try(f.tp:command(cmd, argument[i])) + if check[i] then f.try(f.tp:check(check[i])) end + end + else + f.try(f.tp:command(cmdt.command, cmdt.argument)) + if cmdt.check then f.try(f.tp:check(cmdt.check)) end + end f:quit() return f:close() end) @@ -282,4 +291,4 @@ _M.get = socket.protect(function(gett) else return tget(gett) end end) -return _M \ No newline at end of file +return _M diff --git a/src/ltn12.lua b/src/ltn12.lua index dede0fa..575c5a7 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua @@ -22,6 +22,9 @@ _M.source = source _M.sink = sink _M.pump = pump +local unpack = unpack or table.unpack +local select = base.select + -- 2048 seems to be better in windows... _M.BLOCKSIZE = 2048 _M._VERSION = "LTN12 1.0.3" From 944305dc21350fd2ec32a9552d893da86894fd62 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 4 Mar 2016 15:36:32 -0300 Subject: [PATCH 020/194] Added gettimeout for completeness. Also documented. Rordered manuals so order is alphabetical. --- doc/mime.html | 59 ++-- doc/reference.html | 2 + doc/smtp.html | 235 ++++++------- doc/socket.html | 70 ++-- doc/tcp.html | 315 +++++++++-------- doc/udp.html | 833 +++++++++++++++++++++++---------------------- src/tcp.c | 8 + src/timeout.c | 10 + src/timeout.h | 1 + src/udp.c | 7 + 10 files changed, 804 insertions(+), 736 deletions(-) diff --git a/doc/mime.html b/doc/mime.html index ae136fd..8cb3507 100644 --- a/doc/mime.html +++ b/doc/mime.html @@ -72,34 +72,6 @@ local mime = require("mime")

    High-level filters

    - - -

    -mime.normalize([marker]) -

    - -

    -Converts most common end-of-line markers to a specific given marker. -

    - -

    -Marker is the new marker. It defaults to CRLF, the canonic -end-of-line marker defined by the MIME standard. -

    - -

    -The function returns a filter that performs the conversion. -

    - -

    -Note: There is no perfect solution to this problem. Different end-of-line -markers are an evil that will probably plague developers forever. -This function, however, will work perfectly for text created with any of -the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF), -or the DOS (CRLF) conventions. Even if the data has mixed end-of-line -markers, the function will still work well, although it doesn't -guarantee that the number of empty lines will be correct. -

    @@ -159,6 +131,35 @@ base64 = ltn12.filter.chain( )
    + + +

    +mime.normalize([marker]) +

    + +

    +Converts most common end-of-line markers to a specific given marker. +

    + +

    +Marker is the new marker. It defaults to CRLF, the canonic +end-of-line marker defined by the MIME standard. +

    + +

    +The function returns a filter that performs the conversion. +

    + +

    +Note: There is no perfect solution to this problem. Different end-of-line +markers are an evil that will probably plague developers forever. +This function, however, will work perfectly for text created with any of +the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF), +or the DOS (CRLF) conventions. Even if the data has mixed end-of-line +markers, the function will still work well, although it doesn't +guarantee that the number of empty lines will be correct. +

    +

    @@ -466,7 +467,7 @@ marker.

    Last modified by Diego Nehab on
    -Thu Apr 20 00:25:44 EDT 2006 +Fri Mar 4 15:19:17 BRT 2016

    diff --git a/doc/reference.html b/doc/reference.html index 878e7d2..287dc19 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -187,6 +187,7 @@ Support, Manual"> getpeername, getsockname, getstats, +gettimeout, listen, receive, send, @@ -207,6 +208,7 @@ Support, Manual"> getoption, getpeername, getsockname, +gettimeout, receive, receivefrom, send, diff --git a/doc/smtp.html b/doc/smtp.html index bbbff80..600ec37 100644 --- a/doc/smtp.html +++ b/doc/smtp.html @@ -114,6 +114,124 @@ the SMTP module:
  • ZONE: default time zone. + + +

    +smtp.message(mesgt) +

    + +

    +Returns a simple +LTN12 source that sends an SMTP message body, possibly multipart (arbitrarily deep). +

    + +

    +The only parameter of the function is a table describing the message. +Mesgt has the following form (notice the recursive structure): +

    + +
    + + +
    +mesgt = {
    +  headers = header-table,
    +  body = LTN12 source or string or +multipart-mesgt
    +}

    +multipart-mesgt = {
    +  [preamble = string,]
    +  [1] = mesgt,
    +  [2] = mesgt,
    +  ...
    +  [n] = mesgt,
    +  [epilogue = string,]
    +}
    +
    +
    + +

    +For a simple message, all that is needed is a set of headers +and the body. The message body can be given as a string +or as a simple +LTN12 +source. For multipart messages, the body is a table that +recursively defines each part as an independent message, plus an optional +preamble and epilogue. +

    + +

    +The function returns a simple +LTN12 +source that produces the +message contents as defined by mesgt, chunk by chunk. +Hopefully, the following +example will make things clear. When in doubt, refer to the appropriate RFC +as listed in the introduction.

    + +
    +-- load the smtp support and its friends
    +local smtp = require("socket.smtp")
    +local mime = require("mime")
    +local ltn12 = require("ltn12")
    +
    +-- creates a source to send a message with two parts. The first part is 
    +-- plain text, the second part is a PNG image, encoded as base64.
    +source = smtp.message{
    +  headers = {
    +     -- Remember that headers are *ignored* by smtp.send. 
    +     from = "Sicrano de Oliveira <sicrano@example.com>",
    +     to = "Fulano da Silva <fulano@example.com>",
    +     subject = "Here is a message with attachments"
    +  },
    +  body = {
    +    preamble = "If your client doesn't understand attachments, \r\n" ..
    +               "it will still display the preamble and the epilogue.\r\n" ..
    +               "Preamble will probably appear even in a MIME enabled client.",
    +    -- first part: no headers means plain text, us-ascii.
    +    -- The mime.eol low-level filter normalizes end-of-line markers.
    +    [1] = { 
    +      body = mime.eol(0, [[
    +        Lines in a message body should always end with CRLF. 
    +        The smtp module will *NOT* perform translation. However, the 
    +        send function *DOES* perform SMTP stuffing, whereas the message
    +        function does *NOT*.
    +      ]])
    +    },
    +    -- second part: headers describe content to be a png image, 
    +    -- sent under the base64 transfer content encoding.
    +    -- notice that nothing happens until the message is actually sent. 
    +    -- small chunks are loaded into memory right before transmission and 
    +    -- translation happens on the fly.
    +    [2] = { 
    +      headers = {
    +        ["content-type"] = 'image/png; name="image.png"',
    +        ["content-disposition"] = 'attachment; filename="image.png"',
    +        ["content-description"] = 'a beautiful image',
    +        ["content-transfer-encoding"] = "BASE64"
    +      },
    +      body = ltn12.source.chain(
    +        ltn12.source.file(io.open("image.png", "rb")),
    +        ltn12.filter.chain(
    +          mime.encode("base64"),
    +          mime.wrap()
    +        )
    +      )
    +    },
    +    epilogue = "This might also show up, but after the attachments"
    +  }
    +}
    +
    +-- finally send it
    +r, e = smtp.send{
    +    from = "<sicrano@example.com>",
    +    rcpt = "<fulano@example.com>",
    +    source = source,
    +}
    +
    + +

    @@ -275,123 +393,6 @@ r, e = smtp.send{ } - - -

    -smtp.message(mesgt) -

    - -

    -Returns a simple -LTN12 source that sends an SMTP message body, possibly multipart (arbitrarily deep). -

    - -

    -The only parameter of the function is a table describing the message. -Mesgt has the following form (notice the recursive structure): -

    - -
    - - -
    -mesgt = {
    -  headers = header-table,
    -  body = LTN12 source or string or -multipart-mesgt
    -}

    -multipart-mesgt = {
    -  [preamble = string,]
    -  [1] = mesgt,
    -  [2] = mesgt,
    -  ...
    -  [n] = mesgt,
    -  [epilogue = string,]
    -}
    -
    -
    - -

    -For a simple message, all that is needed is a set of headers -and the body. The message body can be given as a string -or as a simple -LTN12 -source. For multipart messages, the body is a table that -recursively defines each part as an independent message, plus an optional -preamble and epilogue. -

    - -

    -The function returns a simple -LTN12 -source that produces the -message contents as defined by mesgt, chunk by chunk. -Hopefully, the following -example will make things clear. When in doubt, refer to the appropriate RFC -as listed in the introduction.

    - -
    --- load the smtp support and its friends
    -local smtp = require("socket.smtp")
    -local mime = require("mime")
    -local ltn12 = require("ltn12")
    -
    --- creates a source to send a message with two parts. The first part is 
    --- plain text, the second part is a PNG image, encoded as base64.
    -source = smtp.message{
    -  headers = {
    -     -- Remember that headers are *ignored* by smtp.send. 
    -     from = "Sicrano de Oliveira <sicrano@example.com>",
    -     to = "Fulano da Silva <fulano@example.com>",
    -     subject = "Here is a message with attachments"
    -  },
    -  body = {
    -    preamble = "If your client doesn't understand attachments, \r\n" ..
    -               "it will still display the preamble and the epilogue.\r\n" ..
    -               "Preamble will probably appear even in a MIME enabled client.",
    -    -- first part: no headers means plain text, us-ascii.
    -    -- The mime.eol low-level filter normalizes end-of-line markers.
    -    [1] = { 
    -      body = mime.eol(0, [[
    -        Lines in a message body should always end with CRLF. 
    -        The smtp module will *NOT* perform translation. However, the 
    -        send function *DOES* perform SMTP stuffing, whereas the message
    -        function does *NOT*.
    -      ]])
    -    },
    -    -- second part: headers describe content to be a png image, 
    -    -- sent under the base64 transfer content encoding.
    -    -- notice that nothing happens until the message is actually sent. 
    -    -- small chunks are loaded into memory right before transmission and 
    -    -- translation happens on the fly.
    -    [2] = { 
    -      headers = {
    -        ["content-type"] = 'image/png; name="image.png"',
    -        ["content-disposition"] = 'attachment; filename="image.png"',
    -        ["content-description"] = 'a beautiful image',
    -        ["content-transfer-encoding"] = "BASE64"
    -      },
    -      body = ltn12.source.chain(
    -        ltn12.source.file(io.open("image.png", "rb")),
    -        ltn12.filter.chain(
    -          mime.encode("base64"),
    -          mime.wrap()
    -        )
    -      )
    -    },
    -    epilogue = "This might also show up, but after the attachments"
    -  }
    -}
    -
    --- finally send it
    -r, e = smtp.send{
    -    from = "<sicrano@example.com>",
    -    rcpt = "<fulano@example.com>",
    -    source = source,
    -}
    -
    -
  • create: An optional function to be used instead of socket.tcp when the communications socket is created. +
  • maxredirects: An optional number specifying the maximum number of redirects to follow. Defaults to 5 if not specified. A boolean false value means no maximum (unlimited).

    @@ -324,8 +326,8 @@ r, c = http.request {

    -Last modified by Diego Nehab on
    -Thu Apr 20 00:25:26 EDT 2006 +Last modified by Eric Westbrook on
    +Sat Feb 23 19:09:42 UTC 2019

    diff --git a/src/http.lua b/src/http.lua index a386165..8bda0d8 100644 --- a/src/http.lua +++ b/src/http.lua @@ -277,7 +277,9 @@ local function shouldredirect(reqt, code, headers) return (reqt.redirect ~= false) and (code == 301 or code == 302 or code == 303 or code == 307) and (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD") - and (not reqt.nredirects or reqt.nredirects < 5) + and ((false == reqt.maxredirects) + or ((reqt.nredirects or 0) + < (reqt.maxredirects or 5))) end local function shouldreceivebody(reqt, code) @@ -299,6 +301,7 @@ local trequest, tredirect sink = reqt.sink, headers = reqt.headers, proxy = reqt.proxy, + maxredirects = reqt.maxredirects, nredirects = (reqt.nredirects or 0) + 1, create = reqt.create } From e587800164d5d6fb75fe34166978438c949db215 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Thu, 12 Jul 2018 01:10:11 -0600 Subject: [PATCH 071/194] socket.http.request(): simultaneous support for http and https URL schemes, with caller-adjustable scheme-to-transport mappings (default "socket.http" and "ssl.https") --- src/http.lua | 56 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/http.lua b/src/http.lua index 19b4dd3..25eb25d 100644 --- a/src/http.lua +++ b/src/http.lua @@ -26,15 +26,20 @@ _M.TIMEOUT = 60 -- user agent field sent in request _M.USERAGENT = socket._VERSION --- supported schemes +-- supported schemes and their particulars local SCHEMES = { - http = { port = 80 } - , https = { port = 443 }} + http = { + port = 80 + , create = function(t) + return socket.tcp end } + , https = { + port = 443 + , create = function(t) + return require("ssl.https").tcp(t) end }} -- default scheme and port for document retrieval local SCHEME = 'http' local PORT = SCHEMES[SCHEME].port - ----------------------------------------------------------------------------- -- Reads MIME headers from a connection, unfolding where needed ----------------------------------------------------------------------------- @@ -115,13 +120,13 @@ local metat = { __index = {} } function _M.open(host, port, create) -- create socket with user connect function, or with default - local c = socket.try((create or socket.tcp)()) + local c = socket.try(create()) local h = base.setmetatable({ c = c }, metat) -- create finalized try h.try = socket.newtry(function() h:close() end) -- set timeout before connecting h.try(c:settimeout(_M.TIMEOUT)) - h.try(c:connect(host, port or PORT)) + h.try(c:connect(host, port)) -- here everything worked return h end @@ -221,14 +226,13 @@ end local function adjustheaders(reqt) -- default headers - local headhost = reqt.host - local headport = tostring(reqt.port) - local schemeport = tostring(SCHEMES[reqt.scheme].port) - if headport ~= schemeport then - headhost = headhost .. ':' .. headport end + local host = reqt.host + local port = tostring(reqt.port) + if port ~= tostring(SCHEMES[reqt.scheme].port) then + host = host .. ':' .. port end local lower = { ["user-agent"] = _M.USERAGENT, - ["host"] = headhost, + ["host"] = host, ["connection"] = "close, TE", ["te"] = "trailers" } @@ -267,8 +271,13 @@ local function adjustrequest(reqt) local nreqt = reqt.url and url.parse(reqt.url, default) or {} -- explicit components override url for i,v in base.pairs(reqt) do nreqt[i] = v end - if nreqt.port == "" then nreqt.port = PORT end - if not (nreqt.host and nreqt.host ~= "") then + -- default to scheme particulars + local schemedefs, host, port, method + = SCHEMES[nreqt.scheme], nreqt.host, nreqt.port, nreqt.method + if not nreqt.create then nreqt.create = schemedefs.create(nreqt) end + if not (port and port ~= '') then nreqt.port = schemedefs.port end + if not (method and method ~= '') then nreqt.method = 'GET' end + if not (host and host ~= "") then socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'") end -- compute uri if user hasn't overriden @@ -285,8 +294,10 @@ local function shouldredirect(reqt, code, headers) if not location then return false end location = string.gsub(location, "%s", "") if location == "" then return false end - local scheme = string.match(location, "^([%w][%w%+%-%.]*)%:") - if scheme and not SCHEMES[scheme] then return false end + local scheme = url.parse(location).scheme + if scheme and (not SCHEMES[scheme]) then return false end + -- avoid https downgrades + if ('https' == reqt.scheme) and ('https' ~= scheme) then return false end return (reqt.redirect ~= false) and (code == 301 or code == 302 or code == 303 or code == 307) and (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD") @@ -306,10 +317,16 @@ end local trequest, tredirect --[[local]] function tredirect(reqt, location) + -- the RFC says the redirect URL has to be absolute, but some + -- servers do not respect that + local newurl = url.absolute(reqt.url, location) + -- if switching schemes, reset port and create function + if url.parse(newurl).scheme ~= reqt.scheme then + reqt.port = nil + reqt.create = nil end + -- make new request local result, code, headers, status = trequest { - -- the RFC says the redirect URL has to be absolute, but some - -- servers do not respect that - url = url.absolute(reqt.url, location), + url = newurl, source = reqt.source, sink = reqt.sink, headers = reqt.headers, @@ -397,4 +414,5 @@ _M.request = socket.protect(function(reqt, body) else return trequest(reqt) end end) +_M.schemes = SCHEMES return _M From 2a467001f6dbadf447a79dfbd036f32b6a82ce05 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Sun, 24 Feb 2019 16:24:42 -0700 Subject: [PATCH 072/194] http.lua: Error informatively if insufficient LuaSec support --- src/http.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/http.lua b/src/http.lua index 25eb25d..2fa5a26 100644 --- a/src/http.lua +++ b/src/http.lua @@ -35,7 +35,11 @@ local SCHEMES = { , https = { port = 443 , create = function(t) - return require("ssl.https").tcp(t) end }} + local https = assert( + require("ssl.https"), 'LuaSocket: LuaSec not found') + local tcp = assert( + https.tcp, 'LuaSocket: Function tcp() not available from LuaSec') + return tcp(t) end }} -- default scheme and port for document retrieval local SCHEME = 'http' From f06b17c4c918e1132ae78d1075c8c9654fdc016d Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:54:09 -0700 Subject: [PATCH 073/194] luasocket.h: define LUASOCKET_API and LUASOCKET_PRIVATE for export visibility --- src/luasocket.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/luasocket.h b/src/luasocket.h index f75d21f..0121a15 100644 --- a/src/luasocket.h +++ b/src/luasocket.h @@ -18,7 +18,19 @@ * This macro prefixes all exported API functions \*-------------------------------------------------------------------------*/ #ifndef LUASOCKET_API -#define LUASOCKET_API extern +#ifdef _WIN32 +#define LUASOCKET_API __declspec(dllexport) +#else +#define LUASOCKET_API __attribute__ ((visibility ("default"))) +#endif +#endif + +#ifndef LUASOCKET_PRIVATE +#ifdef _WIN32 +#define LUASOCKET_PRIVATE +#else +#define LUASOCKET_PRIVATE __attribute__ ((visibility ("hidden"))) +#endif #endif /*-------------------------------------------------------------------------*\ From efc4bb3e2df90732d46b8b1cdae18c8173bad07b Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:55:04 -0700 Subject: [PATCH 074/194] mime.h: use LUASOCKET_API --- src/mime.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/mime.h b/src/mime.h index 99968a5..e57fc9c 100644 --- a/src/mime.h +++ b/src/mime.h @@ -8,6 +8,7 @@ * and formatting conforming to RFC 2045. It is used by mime.lua, which * provide a higher level interface to this functionality. \*=========================================================================*/ +#include "luasocket.h" #include "lua.h" /*-------------------------------------------------------------------------*\ @@ -17,13 +18,6 @@ #define MIME_COPYRIGHT "Copyright (C) 2004-2013 Diego Nehab" #define MIME_AUTHORS "Diego Nehab" -/*-------------------------------------------------------------------------*\ -* This macro prefixes all exported API functions -\*-------------------------------------------------------------------------*/ -#ifndef MIME_API -#define MIME_API extern -#endif - -MIME_API int luaopen_mime_core(lua_State *L); +LUASOCKET_API int luaopen_mime_core(lua_State *L); #endif /* MIME_H */ From c23bf865ce32666e8f3bb0abd7d82f84a891ce82 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:55:36 -0700 Subject: [PATCH 075/194] unix.h: use LUASOCKET_API --- src/unix.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/unix.h b/src/unix.h index 8cc7a79..a1674ef 100644 --- a/src/unix.h +++ b/src/unix.h @@ -7,16 +7,13 @@ * This module is just an example of how to extend LuaSocket with a new * domain. \*=========================================================================*/ +#include "luasocket.h" #include "lua.h" #include "buffer.h" #include "timeout.h" #include "socket.h" -#ifndef UNIX_API -#define UNIX_API extern -#endif - typedef struct t_unix_ { t_socket sock; t_io io; @@ -25,6 +22,6 @@ typedef struct t_unix_ { } t_unix; typedef t_unix *p_unix; -UNIX_API int luaopen_socket_unix(lua_State *L); +LUASOCKET_API int luaopen_socket_unix(lua_State *L); #endif /* UNIX_H */ From 1f6035070fd5e2185dfb3a3bf48e1d12668c6599 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:56:17 -0700 Subject: [PATCH 076/194] mime.c: use LUASOCKET_API --- src/mime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mime.c b/src/mime.c index 338ecd4..6e359af 100755 --- a/src/mime.c +++ b/src/mime.c @@ -76,7 +76,7 @@ static UC b64unbase[256]; /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -MIME_API int luaopen_mime_core(lua_State *L) +LUASOCKET_API int luaopen_mime_core(lua_State *L) { lua_newtable(L); luaL_setfuncs(L, func, 0); From 16b0026e27d4c77fc5e723d52b811ebc23dddc0c Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:56:28 -0700 Subject: [PATCH 077/194] unix.c: use LUASOCKET_API --- src/unix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/unix.c b/src/unix.c index dbc8710..c618a20 100644 --- a/src/unix.c +++ b/src/unix.c @@ -2,6 +2,8 @@ * Unix domain socket * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" + #include "lua.h" #include "lauxlib.h" @@ -45,7 +47,7 @@ static int compat_socket_unix_call(lua_State *L) /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int luaopen_socket_unix(lua_State *L) +LUASOCKET_API int luaopen_socket_unix(lua_State *L) { int i; lua_newtable(L); From c0374dd46ff7b3a8c1913ade4a3746873d6060c1 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:57:01 -0700 Subject: [PATCH 078/194] auxiliar.c: use LUASOCKET_PRIVATE --- src/auxiliar.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/auxiliar.c b/src/auxiliar.c index 5251549..0bd7927 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c @@ -2,18 +2,18 @@ * Auxiliar routines for class hierarchy manipulation * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" +#include "auxiliar.h" #include #include -#include "auxiliar.h" - /*=========================================================================*\ * Exported functions \*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Initializes the module \*-------------------------------------------------------------------------*/ -int auxiliar_open(lua_State *L) { +LUASOCKET_PRIVATE int auxiliar_open(lua_State *L) { (void) L; return 0; } @@ -22,7 +22,7 @@ int auxiliar_open(lua_State *L) { * Creates a new class with given methods * Methods whose names start with __ are passed directly to the metatable. \*-------------------------------------------------------------------------*/ -void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) { +LUASOCKET_PRIVATE void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) { luaL_newmetatable(L, classname); /* mt */ /* create __index table to place methods */ lua_pushstring(L, "__index"); /* mt,"__index" */ @@ -45,7 +45,7 @@ void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) { /*-------------------------------------------------------------------------*\ * Prints the value of a class in a nice way \*-------------------------------------------------------------------------*/ -int auxiliar_tostring(lua_State *L) { +LUASOCKET_PRIVATE int auxiliar_tostring(lua_State *L) { char buf[32]; if (!lua_getmetatable(L, 1)) goto error; lua_pushstring(L, "__index"); @@ -66,7 +66,7 @@ error: /*-------------------------------------------------------------------------*\ * Insert class into group \*-------------------------------------------------------------------------*/ -void auxiliar_add2group(lua_State *L, const char *classname, const char *groupname) { +LUASOCKET_PRIVATE void auxiliar_add2group(lua_State *L, const char *classname, const char *groupname) { luaL_getmetatable(L, classname); lua_pushstring(L, groupname); lua_pushboolean(L, 1); @@ -77,7 +77,7 @@ void auxiliar_add2group(lua_State *L, const char *classname, const char *groupna /*-------------------------------------------------------------------------*\ * Make sure argument is a boolean \*-------------------------------------------------------------------------*/ -int auxiliar_checkboolean(lua_State *L, int objidx) { +LUASOCKET_PRIVATE int auxiliar_checkboolean(lua_State *L, int objidx) { if (!lua_isboolean(L, objidx)) auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN)); return lua_toboolean(L, objidx); @@ -87,7 +87,7 @@ int auxiliar_checkboolean(lua_State *L, int objidx) { * Return userdata pointer if object belongs to a given class, abort with * error otherwise \*-------------------------------------------------------------------------*/ -void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) { +LUASOCKET_PRIVATE void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) { void *data = auxiliar_getclassudata(L, classname, objidx); if (!data) { char msg[45]; @@ -101,7 +101,7 @@ void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) { * Return userdata pointer if object belongs to a given group, abort with * error otherwise \*-------------------------------------------------------------------------*/ -void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) { +LUASOCKET_PRIVATE void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) { void *data = auxiliar_getgroupudata(L, groupname, objidx); if (!data) { char msg[45]; @@ -114,7 +114,7 @@ void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) { /*-------------------------------------------------------------------------*\ * Set object class \*-------------------------------------------------------------------------*/ -void auxiliar_setclass(lua_State *L, const char *classname, int objidx) { +LUASOCKET_PRIVATE void auxiliar_setclass(lua_State *L, const char *classname, int objidx) { luaL_getmetatable(L, classname); if (objidx < 0) objidx--; lua_setmetatable(L, objidx); @@ -124,7 +124,7 @@ void auxiliar_setclass(lua_State *L, const char *classname, int objidx) { * Get a userdata pointer if object belongs to a given group. Return NULL * otherwise \*-------------------------------------------------------------------------*/ -void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) { +LUASOCKET_PRIVATE void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) { if (!lua_getmetatable(L, objidx)) return NULL; lua_pushstring(L, groupname); @@ -142,7 +142,7 @@ void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) { * Get a userdata pointer if object belongs to a given class. Return NULL * otherwise \*-------------------------------------------------------------------------*/ -void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { +LUASOCKET_PRIVATE void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { return luaL_testudata(L, objidx, classname); } @@ -150,7 +150,7 @@ void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { * Throws error when argument does not have correct type. * Used to be part of lauxlib in Lua 5.1, was dropped from 5.2. \*-------------------------------------------------------------------------*/ -int auxiliar_typeerror (lua_State *L, int narg, const char *tname) { +LUASOCKET_PRIVATE int auxiliar_typeerror (lua_State *L, int narg, const char *tname) { const char *msg = lua_pushfstring(L, "%s expected, got %s", tname, luaL_typename(L, narg)); return luaL_argerror(L, narg, msg); From b95527e140fd0ec573ca0e83c5f64dffadd7e228 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:57:25 -0700 Subject: [PATCH 079/194] buffer.c: use LUASOCKET_PRIVATE --- src/buffer.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index fff1634..357730a 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -2,6 +2,8 @@ * Input/Output interface for Lua programs * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" + #include "lua.h" #include "lauxlib.h" #include "compat.h" @@ -32,7 +34,7 @@ static int sendraw(p_buffer buf, const char *data, size_t count, size_t *sent); /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int buffer_open(lua_State *L) { +LUASOCKET_PRIVATE int buffer_open(lua_State *L) { (void) L; return 0; } @@ -40,7 +42,7 @@ int buffer_open(lua_State *L) { /*-------------------------------------------------------------------------*\ * Initializes C structure \*-------------------------------------------------------------------------*/ -void buffer_init(p_buffer buf, p_io io, p_timeout tm) { +LUASOCKET_PRIVATE void buffer_init(p_buffer buf, p_io io, p_timeout tm) { buf->first = buf->last = 0; buf->io = io; buf->tm = tm; @@ -51,7 +53,7 @@ void buffer_init(p_buffer buf, p_io io, p_timeout tm) { /*-------------------------------------------------------------------------*\ * object:getstats() interface \*-------------------------------------------------------------------------*/ -int buffer_meth_getstats(lua_State *L, p_buffer buf) { +LUASOCKET_PRIVATE int buffer_meth_getstats(lua_State *L, p_buffer buf) { lua_pushnumber(L, (lua_Number) buf->received); lua_pushnumber(L, (lua_Number) buf->sent); lua_pushnumber(L, timeout_gettime() - buf->birthday); @@ -61,7 +63,7 @@ int buffer_meth_getstats(lua_State *L, p_buffer buf) { /*-------------------------------------------------------------------------*\ * object:setstats() interface \*-------------------------------------------------------------------------*/ -int buffer_meth_setstats(lua_State *L, p_buffer buf) { +LUASOCKET_PRIVATE int buffer_meth_setstats(lua_State *L, p_buffer buf) { buf->received = (long) luaL_optnumber(L, 2, (lua_Number) buf->received); buf->sent = (long) luaL_optnumber(L, 3, (lua_Number) buf->sent); if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4); @@ -72,7 +74,7 @@ int buffer_meth_setstats(lua_State *L, p_buffer buf) { /*-------------------------------------------------------------------------*\ * object:send() interface \*-------------------------------------------------------------------------*/ -int buffer_meth_send(lua_State *L, p_buffer buf) { +LUASOCKET_PRIVATE int buffer_meth_send(lua_State *L, p_buffer buf) { int top = lua_gettop(L); int err = IO_DONE; size_t size = 0, sent = 0; @@ -105,7 +107,7 @@ int buffer_meth_send(lua_State *L, p_buffer buf) { /*-------------------------------------------------------------------------*\ * object:receive() interface \*-------------------------------------------------------------------------*/ -int buffer_meth_receive(lua_State *L, p_buffer buf) { +LUASOCKET_PRIVATE int buffer_meth_receive(lua_State *L, p_buffer buf) { int err = IO_DONE, top = lua_gettop(L); luaL_Buffer b; size_t size; @@ -154,7 +156,7 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) { /*-------------------------------------------------------------------------*\ * Determines if there is any data in the read buffer \*-------------------------------------------------------------------------*/ -int buffer_isempty(p_buffer buf) { +LUASOCKET_PRIVATE int buffer_isempty(p_buffer buf) { return buf->first >= buf->last; } From 2bf6730fd559e06727903eec77e52b29637c2af1 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:58:30 -0700 Subject: [PATCH 080/194] pragma.c: use LUASOCKET_PRIVATE --- src/compat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compat.c b/src/compat.c index 988fa68..1290f70 100644 --- a/src/compat.c +++ b/src/compat.c @@ -1,10 +1,11 @@ +#include "luasocket.h" #include "compat.h" #if LUA_VERSION_NUM==501 /* ** Adapted from Lua 5.2 */ -void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { +LUASOCKET_PRIVATE void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { luaL_checkstack(L, nup+1, "too many upvalues"); for (; l->name != NULL; l++) { /* fill the table with given functions */ int i; @@ -20,7 +21,7 @@ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { /* ** Duplicated from Lua 5.2 */ -void *luaL_testudata (lua_State *L, int ud, const char *tname) { +LUASOCKET_PRIVATE void *luaL_testudata (lua_State *L, int ud, const char *tname) { void *p = lua_touserdata(L, ud); if (p != NULL) { /* value is a userdata? */ if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ From 395729d4314dfeda2a095760cf2de042af7581f8 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:58:45 -0700 Subject: [PATCH 081/194] except.c: use LUASOCKET_PRIVATE --- src/except.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/except.c b/src/except.c index 60b5005..dab70e7 100644 --- a/src/except.c +++ b/src/except.c @@ -2,6 +2,8 @@ * Simple exception support * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" + #include #include "lua.h" @@ -124,7 +126,7 @@ static int global_protect(lua_State *L) { /*-------------------------------------------------------------------------*\ * Init module \*-------------------------------------------------------------------------*/ -int except_open(lua_State *L) { +LUASOCKET_PRIVATE int except_open(lua_State *L) { lua_newtable(L); /* metatable for wrapped exceptions */ lua_pushboolean(L, 0); lua_setfield(L, -2, "__metatable"); From 731b23bc891fdf6136af7457972b8a8f8f1b55ec Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:58:54 -0700 Subject: [PATCH 082/194] inet.c: use LUASOCKET_PRIVATE --- src/inet.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/inet.c b/src/inet.c index f4c8404..bed8a7c 100644 --- a/src/inet.c +++ b/src/inet.c @@ -2,6 +2,8 @@ * Internet domain functions * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" + #include #include #include @@ -38,7 +40,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int inet_open(lua_State *L) +LUASOCKET_PRIVATE int inet_open(lua_State *L) { lua_pushstring(L, "dns"); lua_newtable(L); @@ -143,7 +145,7 @@ static int inet_global_toip(lua_State *L) return 2; } -int inet_optfamily(lua_State* L, int narg, const char* def) +LUASOCKET_PRIVATE int inet_optfamily(lua_State* L, int narg, const char* def) { static const char* optname[] = { "unspec", "inet", "inet6", NULL }; static int optvalue[] = { AF_UNSPEC, AF_INET, AF_INET6, 0 }; @@ -151,7 +153,7 @@ int inet_optfamily(lua_State* L, int narg, const char* def) return optvalue[luaL_checkoption(L, narg, def, optname)]; } -int inet_optsocktype(lua_State* L, int narg, const char* def) +LUASOCKET_PRIVATE int inet_optsocktype(lua_State* L, int narg, const char* def) { static const char* optname[] = { "stream", "dgram", NULL }; static int optvalue[] = { SOCK_STREAM, SOCK_DGRAM, 0 }; @@ -242,7 +244,7 @@ static int inet_global_gethostname(lua_State *L) /*-------------------------------------------------------------------------*\ * Retrieves socket peer name \*-------------------------------------------------------------------------*/ -int inet_meth_getpeername(lua_State *L, p_socket ps, int family) +LUASOCKET_PRIVATE int inet_meth_getpeername(lua_State *L, p_socket ps, int family) { int err; struct sockaddr_storage peer; @@ -276,7 +278,7 @@ int inet_meth_getpeername(lua_State *L, p_socket ps, int family) /*-------------------------------------------------------------------------*\ * Retrieves socket local name \*-------------------------------------------------------------------------*/ -int inet_meth_getsockname(lua_State *L, p_socket ps, int family) +LUASOCKET_PRIVATE int inet_meth_getsockname(lua_State *L, p_socket ps, int family) { int err; struct sockaddr_storage peer; @@ -352,7 +354,7 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp) /*-------------------------------------------------------------------------*\ * Tries to create a new inet socket \*-------------------------------------------------------------------------*/ -const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { +LUASOCKET_PRIVATE const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { const char *err = socket_strerror(socket_create(ps, family, type, protocol)); if (err == NULL && family == AF_INET6) { int yes = 1; @@ -364,7 +366,7 @@ const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { /*-------------------------------------------------------------------------*\ * "Disconnects" a DGRAM socket \*-------------------------------------------------------------------------*/ -const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) +LUASOCKET_PRIVATE const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) { switch (family) { case AF_INET: { @@ -391,7 +393,7 @@ const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) /*-------------------------------------------------------------------------*\ * Tries to connect to remote address (address, port) \*-------------------------------------------------------------------------*/ -const char *inet_tryconnect(p_socket ps, int *family, const char *address, +LUASOCKET_PRIVATE const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *serv, p_timeout tm, struct addrinfo *connecthints) { struct addrinfo *iterator = NULL, *resolved = NULL; @@ -437,7 +439,7 @@ const char *inet_tryconnect(p_socket ps, int *family, const char *address, /*-------------------------------------------------------------------------*\ * Tries to accept a socket \*-------------------------------------------------------------------------*/ -const char *inet_tryaccept(p_socket server, int family, p_socket client, +LUASOCKET_PRIVATE const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm) { socklen_t len; t_sockaddr_storage addr; @@ -453,7 +455,7 @@ const char *inet_tryaccept(p_socket server, int family, p_socket client, /*-------------------------------------------------------------------------*\ * Tries to bind socket to (address, port) \*-------------------------------------------------------------------------*/ -const char *inet_trybind(p_socket ps, int *family, const char *address, +LUASOCKET_PRIVATE const char *inet_trybind(p_socket ps, int *family, const char *address, const char *serv, struct addrinfo *bindhints) { struct addrinfo *iterator = NULL, *resolved = NULL; const char *err = NULL; @@ -497,7 +499,7 @@ const char *inet_trybind(p_socket ps, int *family, const char *address, * Some systems do not provide these so that we provide our own. \*-------------------------------------------------------------------------*/ #ifdef LUASOCKET_INET_ATON -int inet_aton(const char *cp, struct in_addr *inp) +LUASOCKET_PRIVATE int inet_aton(const char *cp, struct in_addr *inp) { unsigned int a = 0, b = 0, c = 0, d = 0; int n = 0, r; @@ -519,7 +521,7 @@ int inet_aton(const char *cp, struct in_addr *inp) #endif #ifdef LUASOCKET_INET_PTON -int inet_pton(int af, const char *src, void *dst) +LUASOCKET_PRIVATE int inet_pton(int af, const char *src, void *dst) { struct addrinfo hints, *res; int ret = 1; From 3f19a052e8f0c014365e9a07aaf82afd586f3ee1 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:59:09 -0700 Subject: [PATCH 083/194] io.c: use LUASOCKET_PRIVATE --- src/io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/io.c b/src/io.c index a4230ce..f1a2b9d 100644 --- a/src/io.c +++ b/src/io.c @@ -2,6 +2,7 @@ * Input/Output abstraction * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" #include "io.h" /*=========================================================================*\ @@ -10,7 +11,7 @@ /*-------------------------------------------------------------------------*\ * Initializes C structure \*-------------------------------------------------------------------------*/ -void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { +LUASOCKET_PRIVATE void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { io->send = send; io->recv = recv; io->error = error; @@ -20,7 +21,7 @@ void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { /*-------------------------------------------------------------------------*\ * I/O error strings \*-------------------------------------------------------------------------*/ -const char *io_strerror(int err) { +LUASOCKET_PRIVATE const char *io_strerror(int err) { switch (err) { case IO_DONE: return NULL; case IO_CLOSED: return "closed"; From ef2a3fcedb8c03a2e64942cb794f4ffd6a9beef7 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:59:19 -0700 Subject: [PATCH 084/194] options.c: use LUASOCKET_PRIVATE --- src/options.c | 94 +++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/src/options.c b/src/options.c index bbadec3..b0bacbf 100644 --- a/src/options.c +++ b/src/options.c @@ -2,14 +2,12 @@ * Common option interface * LuaSocket toolkit \*=========================================================================*/ -#include - +#include "luasocket.h" #include "lauxlib.h" - #include "auxiliar.h" #include "options.h" #include "inet.h" - +#include /*=========================================================================*\ * Internal functions prototypes @@ -31,7 +29,7 @@ static int opt_get(lua_State *L, p_socket ps, int level, int name, /*-------------------------------------------------------------------------*\ * Calls appropriate option handler \*-------------------------------------------------------------------------*/ -int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps) +LUASOCKET_PRIVATE int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps) { const char *name = luaL_checkstring(L, 2); /* obj, name, ... */ while (opt->name && strcmp(name, opt->name)) @@ -44,7 +42,7 @@ int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps) return opt->func(L, ps); } -int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) +LUASOCKET_PRIVATE int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) { const char *name = luaL_checkstring(L, 2); /* obj, name, ... */ while (opt->name && strcmp(name, opt->name)) @@ -58,165 +56,165 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) } /* enables reuse of local address */ -int opt_set_reuseaddr(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_reuseaddr(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); } -int opt_get_reuseaddr(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_reuseaddr(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); } /* enables reuse of local port */ -int opt_set_reuseport(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_reuseport(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); } -int opt_get_reuseport(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_reuseport(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); } /* disables the Naggle algorithm */ -int opt_set_tcp_nodelay(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_tcp_nodelay(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); } -int opt_get_tcp_nodelay(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_tcp_nodelay(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); } #ifdef TCP_KEEPIDLE -int opt_get_tcp_keepidle(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_tcp_keepidle(lua_State *L, p_socket ps) { return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE); } -int opt_set_tcp_keepidle(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_tcp_keepidle(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE); } #endif #ifdef TCP_KEEPCNT -int opt_get_tcp_keepcnt(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_tcp_keepcnt(lua_State *L, p_socket ps) { return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPCNT); } -int opt_set_tcp_keepcnt(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_tcp_keepcnt(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPCNT); } #endif #ifdef TCP_KEEPINTVL -int opt_get_tcp_keepintvl(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_tcp_keepintvl(lua_State *L, p_socket ps) { return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL); } -int opt_set_tcp_keepintvl(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_tcp_keepintvl(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL); } #endif -int opt_set_keepalive(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_keepalive(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); } -int opt_get_keepalive(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_keepalive(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); } -int opt_set_dontroute(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_dontroute(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE); } -int opt_get_dontroute(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_dontroute(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, SOL_SOCKET, SO_DONTROUTE); } -int opt_set_broadcast(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_broadcast(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_BROADCAST); } -int opt_set_recv_buf_size(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_recv_buf_size(lua_State *L, p_socket ps) { return opt_setint(L, ps, SOL_SOCKET, SO_RCVBUF); } -int opt_get_recv_buf_size(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_recv_buf_size(lua_State *L, p_socket ps) { return opt_getint(L, ps, SOL_SOCKET, SO_RCVBUF); } -int opt_get_send_buf_size(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_send_buf_size(lua_State *L, p_socket ps) { return opt_getint(L, ps, SOL_SOCKET, SO_SNDBUF); } -int opt_set_send_buf_size(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_send_buf_size(lua_State *L, p_socket ps) { return opt_setint(L, ps, SOL_SOCKET, SO_SNDBUF); } -int opt_get_broadcast(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_broadcast(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, SOL_SOCKET, SO_BROADCAST); } -int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); } -int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps) { return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); } -int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS); } -int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps) { return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS); } -int opt_set_ip_multicast_loop(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip_multicast_loop(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP); } -int opt_get_ip_multicast_loop(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_ip_multicast_loop(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP); } -int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP); } -int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP); } -int opt_set_linger(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_linger(lua_State *L, p_socket ps) { struct linger li; /* obj, name, table */ if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE)); @@ -233,7 +231,7 @@ int opt_set_linger(lua_State *L, p_socket ps) return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li)); } -int opt_get_linger(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_linger(lua_State *L, p_socket ps) { struct linger li; /* obj, name */ int len = sizeof(li); @@ -248,12 +246,12 @@ int opt_get_linger(lua_State *L, p_socket ps) return 1; } -int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IP, IP_MULTICAST_TTL); } -int opt_set_ip_multicast_if(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip_multicast_if(lua_State *L, p_socket ps) { const char *address = luaL_checkstring(L, 3); /* obj, name, ip */ struct in_addr val; @@ -264,7 +262,7 @@ int opt_set_ip_multicast_if(lua_State *L, p_socket ps) (char *) &val, sizeof(val)); } -int opt_get_ip_multicast_if(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_ip_multicast_if(lua_State *L, p_socket ps) { struct in_addr val; socklen_t len = sizeof(val); @@ -277,32 +275,32 @@ int opt_get_ip_multicast_if(lua_State *L, p_socket ps) return 1; } -int opt_set_ip_add_membership(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip_add_membership(lua_State *L, p_socket ps) { return opt_setmembership(L, ps, IPPROTO_IP, IP_ADD_MEMBERSHIP); } -int opt_set_ip_drop_membersip(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip_drop_membersip(lua_State *L, p_socket ps) { return opt_setmembership(L, ps, IPPROTO_IP, IP_DROP_MEMBERSHIP); } -int opt_set_ip6_add_membership(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip6_add_membership(lua_State *L, p_socket ps) { return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP); } -int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps) { return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP); } -int opt_get_ip6_v6only(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_ip6_v6only(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); } -int opt_set_ip6_v6only(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_set_ip6_v6only(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); } @@ -393,7 +391,7 @@ static int opt_getboolean(lua_State *L, p_socket ps, int level, int name) return 1; } -int opt_get_error(lua_State *L, p_socket ps) +LUASOCKET_PRIVATE int opt_get_error(lua_State *L, p_socket ps) { int val = 0; socklen_t len = sizeof(val); From fae993c118cd1b88b35d5760b233b790ac9e1109 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 15:59:29 -0700 Subject: [PATCH 085/194] select.c: use LUASOCKET_PRIVATE --- src/select.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/select.c b/src/select.c index 9d133b7..b615b19 100644 --- a/src/select.c +++ b/src/select.c @@ -2,7 +2,7 @@ * Select implementation * LuaSocket toolkit \*=========================================================================*/ -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" @@ -12,6 +12,8 @@ #include "timeout.h" #include "select.h" +#include + /*=========================================================================*\ * Internal function prototypes. \*=========================================================================*/ @@ -37,7 +39,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int select_open(lua_State *L) { +LUASOCKET_PRIVATE int select_open(lua_State *L) { lua_pushstring(L, "_SETSIZE"); lua_pushinteger(L, FD_SETSIZE); lua_rawset(L, -3); From 898f2df025a3bcc9b1639f64d407fba0ac9acefc Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:00:38 -0700 Subject: [PATCH 086/194] serial.c: include luasocket.h --- src/serial.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/serial.c b/src/serial.c index 7bdb21c..cb46edb 100644 --- a/src/serial.c +++ b/src/serial.c @@ -2,6 +2,8 @@ * Serial stream * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" + #include #include "lua.h" From 525d703e16c1f557b95f742f7d2681ad6815f92f Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:00:51 -0700 Subject: [PATCH 087/194] tcp.c: use LUASOCKET_PRIVATE --- src/tcp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tcp.c b/src/tcp.c index c7384b4..cc5b6a7 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -2,18 +2,21 @@ * TCP object * LuaSocket toolkit \*=========================================================================*/ -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" -#include "compat.h" +#include "compat.h" #include "auxiliar.h" + #include "socket.h" #include "inet.h" #include "options.h" #include "tcp.h" +#include + /*=========================================================================*\ * Internal function prototypes \*=========================================================================*/ @@ -126,7 +129,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int tcp_open(lua_State *L) +LUASOCKET_PRIVATE int tcp_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "tcp{master}", tcp_methods); From 87c2dee13e05d5474e2acde7f5dca29edd589335 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:01:04 -0700 Subject: [PATCH 088/194] timeout.c: use LUASOCKET_PRIVATE --- src/timeout.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/timeout.c b/src/timeout.c index 5a601d5..8fb8f55 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -2,9 +2,7 @@ * Timeout management functions * LuaSocket toolkit \*=========================================================================*/ -#include -#include -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" @@ -13,6 +11,10 @@ #include "auxiliar.h" #include "timeout.h" +#include +#include +#include + #ifdef _WIN32 #include #else @@ -46,7 +48,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initialize structure \*-------------------------------------------------------------------------*/ -void timeout_init(p_timeout tm, double block, double total) { +LUASOCKET_PRIVATE void timeout_init(p_timeout tm, double block, double total) { tm->block = block; tm->total = total; } @@ -59,7 +61,7 @@ void timeout_init(p_timeout tm, double block, double total) { * Returns * the number of ms left or -1 if there is no time limit \*-------------------------------------------------------------------------*/ -double timeout_get(p_timeout tm) { +LUASOCKET_PRIVATE double timeout_get(p_timeout tm) { if (tm->block < 0.0 && tm->total < 0.0) { return -1; } else if (tm->block < 0.0) { @@ -80,7 +82,7 @@ double timeout_get(p_timeout tm) { * Returns * start field of structure \*-------------------------------------------------------------------------*/ -double timeout_getstart(p_timeout tm) { +LUASOCKET_PRIVATE double timeout_getstart(p_timeout tm) { return tm->start; } @@ -92,7 +94,7 @@ double timeout_getstart(p_timeout tm) { * Returns * the number of ms left or -1 if there is no time limit \*-------------------------------------------------------------------------*/ -double timeout_getretry(p_timeout tm) { +LUASOCKET_PRIVATE double timeout_getretry(p_timeout tm) { if (tm->block < 0.0 && tm->total < 0.0) { return -1; } else if (tm->block < 0.0) { @@ -112,7 +114,7 @@ double timeout_getretry(p_timeout tm) { * Input * tm: timeout control structure \*-------------------------------------------------------------------------*/ -p_timeout timeout_markstart(p_timeout tm) { +LUASOCKET_PRIVATE p_timeout timeout_markstart(p_timeout tm) { tm->start = timeout_gettime(); return tm; } @@ -123,7 +125,7 @@ p_timeout timeout_markstart(p_timeout tm) { * time in s. \*-------------------------------------------------------------------------*/ #ifdef _WIN32 -double timeout_gettime(void) { +LUASOCKET_PRIVATE double timeout_gettime(void) { FILETIME ft; double t; GetSystemTimeAsFileTime(&ft); @@ -133,7 +135,7 @@ double timeout_gettime(void) { return (t - 11644473600.0); } #else -double timeout_gettime(void) { +LUASOCKET_PRIVATE double timeout_gettime(void) { struct timeval v; gettimeofday(&v, (struct timezone *) NULL); /* Unix Epoch time (time since January 1, 1970 (UTC)) */ @@ -144,7 +146,7 @@ double timeout_gettime(void) { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int timeout_open(lua_State *L) { +LUASOCKET_PRIVATE int timeout_open(lua_State *L) { luaL_setfuncs(L, func, 0); return 0; } @@ -155,7 +157,7 @@ int timeout_open(lua_State *L) { * time: time out value in seconds * mode: "b" for block timeout, "t" for total timeout. (default: b) \*-------------------------------------------------------------------------*/ -int timeout_meth_settimeout(lua_State *L, p_timeout tm) { +LUASOCKET_PRIVATE int timeout_meth_settimeout(lua_State *L, p_timeout tm) { double t = luaL_optnumber(L, 2, -1); const char *mode = luaL_optstring(L, 3, "b"); switch (*mode) { @@ -177,7 +179,7 @@ int timeout_meth_settimeout(lua_State *L, p_timeout tm) { * Gets timeout values for IO operations * Lua Output: block, total \*-------------------------------------------------------------------------*/ -int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { +LUASOCKET_PRIVATE int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { lua_pushnumber(L, tm->block); lua_pushnumber(L, tm->total); return 2; @@ -199,7 +201,7 @@ static int timeout_lua_gettime(lua_State *L) * Sleep for n seconds. \*-------------------------------------------------------------------------*/ #ifdef _WIN32 -int timeout_lua_sleep(lua_State *L) +LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) { double n = luaL_checknumber(L, 1); if (n < 0.0) n = 0.0; @@ -209,7 +211,7 @@ int timeout_lua_sleep(lua_State *L) return 0; } #else -int timeout_lua_sleep(lua_State *L) +LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) { double n = luaL_checknumber(L, 1); struct timespec t, r; From 30a0a6003b3150af8b317cc8e39ebfa43636e2d0 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:01:21 -0700 Subject: [PATCH 089/194] udp.c: use LUASOCKET_PRIVATE --- src/udp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/udp.c b/src/udp.c index 037f9a4..99a766f 100644 --- a/src/udp.c +++ b/src/udp.c @@ -2,8 +2,7 @@ * UDP object * LuaSocket toolkit \*=========================================================================*/ -#include -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" @@ -15,6 +14,9 @@ #include "options.h" #include "udp.h" +#include +#include + /* min and max macros */ #ifndef MIN #define MIN(x, y) ((x) < (y) ? x : y) @@ -122,7 +124,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int udp_open(lua_State *L) { +LUASOCKET_PRIVATE int udp_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "udp{connected}", udp_methods); auxiliar_newclass(L, "udp{unconnected}", udp_methods); From 678d558c5f5db9af64d33ae78c37056a44848b4c Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:01:33 -0700 Subject: [PATCH 090/194] unixdgram.c: use LUASOCKET_PRIVATE --- src/unixdgram.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/unixdgram.c b/src/unixdgram.c index 0d6f18c..840257a 100644 --- a/src/unixdgram.c +++ b/src/unixdgram.c @@ -2,8 +2,7 @@ * Unix domain socket dgram submodule * LuaSocket toolkit \*=========================================================================*/ -#include -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" @@ -13,6 +12,10 @@ #include "socket.h" #include "options.h" #include "unix.h" + +#include +#include + #include #define UNIXDGRAM_DATAGRAMSIZE 8192 @@ -83,7 +86,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int unixdgram_open(lua_State *L) +LUASOCKET_PRIVATE int unixdgram_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "unixdgram{connected}", unixdgram_methods); From fe437ee844e8e51ef0b7437bb34efd8c18927a75 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:01:44 -0700 Subject: [PATCH 091/194] unixstream.c: use LUASOCKET_PRIVATE --- src/unixstream.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/unixstream.c b/src/unixstream.c index 0b9055c..ce2d3af 100644 --- a/src/unixstream.c +++ b/src/unixstream.c @@ -2,7 +2,7 @@ * Unix domain socket stream sub module * LuaSocket toolkit \*=========================================================================*/ -#include +#include "luasocket.h" #include "lua.h" #include "lauxlib.h" @@ -12,6 +12,8 @@ #include "socket.h" #include "options.h" #include "unixstream.h" + +#include #include /*=========================================================================*\ @@ -80,7 +82,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int unixstream_open(lua_State *L) +LUASOCKET_PRIVATE int unixstream_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "unixstream{master}", unixstream_methods); From d7ffc2f4e69ff24a88f00456cd9a538ecc90d14c Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:04:16 -0700 Subject: [PATCH 092/194] usocket.c use LUASOCKET_PRIVATE --- src/usocket.c | 58 ++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/usocket.c b/src/usocket.c index 6e7f8f6..08a961d 100644 --- a/src/usocket.c +++ b/src/usocket.c @@ -6,12 +6,14 @@ * The penalty of calling select to avoid busy-wait is only paid when * the I/O call fail in the first place. \*=========================================================================*/ -#include -#include +#include "luasocket.h" #include "socket.h" #include "pierror.h" +#include +#include + /*-------------------------------------------------------------------------*\ * Wait for readable/writable/connected socket with timeout \*-------------------------------------------------------------------------*/ @@ -21,7 +23,7 @@ #define WAITFD_R POLLIN #define WAITFD_W POLLOUT #define WAITFD_C (POLLIN|POLLOUT) -int socket_waitfd(p_socket ps, int sw, p_timeout tm) { +LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) { int ret; struct pollfd pfd; pfd.fd = *ps; @@ -43,7 +45,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) { #define WAITFD_W 2 #define WAITFD_C (WAITFD_R|WAITFD_W) -int socket_waitfd(p_socket ps, int sw, p_timeout tm) { +LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) { int ret; fd_set rfds, wfds, *rp, *wp; struct timeval tv, *tp; @@ -75,7 +77,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int socket_open(void) { +LUASOCKET_PRIVATE int socket_open(void) { /* installs a handler to ignore sigpipe or it will crash us */ signal(SIGPIPE, SIG_IGN); return 1; @@ -84,14 +86,14 @@ int socket_open(void) { /*-------------------------------------------------------------------------*\ * Close module \*-------------------------------------------------------------------------*/ -int socket_close(void) { +LUASOCKET_PRIVATE int socket_close(void) { return 1; } /*-------------------------------------------------------------------------*\ * Close and inutilize socket \*-------------------------------------------------------------------------*/ -void socket_destroy(p_socket ps) { +LUASOCKET_PRIVATE void socket_destroy(p_socket ps) { if (*ps != SOCKET_INVALID) { close(*ps); *ps = SOCKET_INVALID; @@ -101,7 +103,7 @@ void socket_destroy(p_socket ps) { /*-------------------------------------------------------------------------*\ * Select with timeout control \*-------------------------------------------------------------------------*/ -int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, +LUASOCKET_PRIVATE int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm) { int ret; do { @@ -118,7 +120,7 @@ int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, /*-------------------------------------------------------------------------*\ * Creates and sets up a socket \*-------------------------------------------------------------------------*/ -int socket_create(p_socket ps, int domain, int type, int protocol) { +LUASOCKET_PRIVATE int socket_create(p_socket ps, int domain, int type, int protocol) { *ps = socket(domain, type, protocol); if (*ps != SOCKET_INVALID) return IO_DONE; else return errno; @@ -127,7 +129,7 @@ int socket_create(p_socket ps, int domain, int type, int protocol) { /*-------------------------------------------------------------------------*\ * Binds or returns error message \*-------------------------------------------------------------------------*/ -int socket_bind(p_socket ps, SA *addr, socklen_t len) { +LUASOCKET_PRIVATE int socket_bind(p_socket ps, SA *addr, socklen_t len) { int err = IO_DONE; socket_setblocking(ps); if (bind(*ps, addr, len) < 0) err = errno; @@ -138,7 +140,7 @@ int socket_bind(p_socket ps, SA *addr, socklen_t len) { /*-------------------------------------------------------------------------*\ * \*-------------------------------------------------------------------------*/ -int socket_listen(p_socket ps, int backlog) { +LUASOCKET_PRIVATE int socket_listen(p_socket ps, int backlog) { int err = IO_DONE; if (listen(*ps, backlog)) err = errno; return err; @@ -147,14 +149,14 @@ int socket_listen(p_socket ps, int backlog) { /*-------------------------------------------------------------------------*\ * \*-------------------------------------------------------------------------*/ -void socket_shutdown(p_socket ps, int how) { +LUASOCKET_PRIVATE void socket_shutdown(p_socket ps, int how) { shutdown(*ps, how); } /*-------------------------------------------------------------------------*\ * Connects or returns error message \*-------------------------------------------------------------------------*/ -int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { +LUASOCKET_PRIVATE int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { int err; /* avoid calling on closed sockets */ if (*ps == SOCKET_INVALID) return IO_CLOSED; @@ -176,7 +178,7 @@ int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { /*-------------------------------------------------------------------------*\ * Accept with timeout \*-------------------------------------------------------------------------*/ -int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout tm) { +LUASOCKET_PRIVATE int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout tm) { if (*ps == SOCKET_INVALID) return IO_CLOSED; for ( ;; ) { int err; @@ -193,7 +195,7 @@ int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout /*-------------------------------------------------------------------------*\ * Send with timeout \*-------------------------------------------------------------------------*/ -int socket_send(p_socket ps, const char *data, size_t count, +LUASOCKET_PRIVATE int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm) { int err; @@ -227,7 +229,7 @@ int socket_send(p_socket ps, const char *data, size_t count, /*-------------------------------------------------------------------------*\ * Sendto with timeout \*-------------------------------------------------------------------------*/ -int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, +LUASOCKET_PRIVATE int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t len, p_timeout tm) { int err; @@ -252,7 +254,7 @@ int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, /*-------------------------------------------------------------------------*\ * Receive with timeout \*-------------------------------------------------------------------------*/ -int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { +LUASOCKET_PRIVATE int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { int err; *got = 0; if (*ps == SOCKET_INVALID) return IO_CLOSED; @@ -274,7 +276,7 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm /*-------------------------------------------------------------------------*\ * Recvfrom with timeout \*-------------------------------------------------------------------------*/ -int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, +LUASOCKET_PRIVATE int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *len, p_timeout tm) { int err; *got = 0; @@ -302,7 +304,7 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, * with send/recv replaced with write/read. We can't just use write/read * in the socket version, because behaviour when size is zero is different. \*-------------------------------------------------------------------------*/ -int socket_write(p_socket ps, const char *data, size_t count, +LUASOCKET_PRIVATE int socket_write(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm) { int err; @@ -337,7 +339,7 @@ int socket_write(p_socket ps, const char *data, size_t count, * Read with timeout * See note for socket_write \*-------------------------------------------------------------------------*/ -int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { +LUASOCKET_PRIVATE int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { int err; *got = 0; if (*ps == SOCKET_INVALID) return IO_CLOSED; @@ -359,7 +361,7 @@ int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm /*-------------------------------------------------------------------------*\ * Put socket into blocking mode \*-------------------------------------------------------------------------*/ -void socket_setblocking(p_socket ps) { +LUASOCKET_PRIVATE void socket_setblocking(p_socket ps) { int flags = fcntl(*ps, F_GETFL, 0); flags &= (~(O_NONBLOCK)); fcntl(*ps, F_SETFL, flags); @@ -368,7 +370,7 @@ void socket_setblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * Put socket into non-blocking mode \*-------------------------------------------------------------------------*/ -void socket_setnonblocking(p_socket ps) { +LUASOCKET_PRIVATE void socket_setnonblocking(p_socket ps) { int flags = fcntl(*ps, F_GETFL, 0); flags |= O_NONBLOCK; fcntl(*ps, F_SETFL, flags); @@ -377,7 +379,7 @@ void socket_setnonblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * DNS helpers \*-------------------------------------------------------------------------*/ -int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) { +LUASOCKET_PRIVATE int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) { *hp = gethostbyaddr(addr, len, AF_INET); if (*hp) return IO_DONE; else if (h_errno) return h_errno; @@ -385,7 +387,7 @@ int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) { else return IO_UNKNOWN; } -int socket_gethostbyname(const char *addr, struct hostent **hp) { +LUASOCKET_PRIVATE int socket_gethostbyname(const char *addr, struct hostent **hp) { *hp = gethostbyname(addr); if (*hp) return IO_DONE; else if (h_errno) return h_errno; @@ -397,7 +399,7 @@ int socket_gethostbyname(const char *addr, struct hostent **hp) { * Error translation functions * Make sure important error messages are standard \*-------------------------------------------------------------------------*/ -const char *socket_hoststrerror(int err) { +LUASOCKET_PRIVATE const char *socket_hoststrerror(int err) { if (err <= 0) return io_strerror(err); switch (err) { case HOST_NOT_FOUND: return PIE_HOST_NOT_FOUND; @@ -405,7 +407,7 @@ const char *socket_hoststrerror(int err) { } } -const char *socket_strerror(int err) { +LUASOCKET_PRIVATE const char *socket_strerror(int err) { if (err <= 0) return io_strerror(err); switch (err) { case EADDRINUSE: return PIE_ADDRINUSE; @@ -421,12 +423,12 @@ const char *socket_strerror(int err) { } } -const char *socket_ioerror(p_socket ps, int err) { +LUASOCKET_PRIVATE const char *socket_ioerror(p_socket ps, int err) { (void) ps; return socket_strerror(err); } -const char *socket_gaistrerror(int err) { +LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) { if (err == 0) return NULL; switch (err) { case EAI_AGAIN: return PIE_AGAIN; From f8183bab875f541af3932fe4e430fcff8bd8aba0 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:04:29 -0700 Subject: [PATCH 093/194] usocket.c: use LUASOCKET_PRIVATE --- src/wsocket.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/wsocket.c b/src/wsocket.c index ac8411f..c281058 100755 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -5,6 +5,8 @@ * The penalty of calling select to avoid busy-wait is only paid when * the I/O call fail in the first place. \*=========================================================================*/ +#include "luasocket.h" + #include #include "socket.h" @@ -16,7 +18,7 @@ static const char *wstrerror(int err); /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int socket_open(void) { +LUASOCKET_PRIVATE int socket_open(void) { WSADATA wsaData; WORD wVersionRequested = MAKEWORD(2, 0); int err = WSAStartup(wVersionRequested, &wsaData ); @@ -32,7 +34,7 @@ int socket_open(void) { /*-------------------------------------------------------------------------*\ * Close module \*-------------------------------------------------------------------------*/ -int socket_close(void) { +LUASOCKET_PRIVATE int socket_close(void) { WSACleanup(); return 1; } @@ -45,7 +47,7 @@ int socket_close(void) { #define WAITFD_E 4 #define WAITFD_C (WAITFD_E|WAITFD_W) -int socket_waitfd(p_socket ps, int sw, p_timeout tm) { +LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) { int ret; fd_set rfds, wfds, efds, *rp = NULL, *wp = NULL, *ep = NULL; struct timeval tv, *tp = NULL; @@ -73,7 +75,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) { /*-------------------------------------------------------------------------*\ * Select with int timeout in ms \*-------------------------------------------------------------------------*/ -int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, +LUASOCKET_PRIVATE int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm) { struct timeval tv; double t = timeout_get(tm); @@ -88,7 +90,7 @@ int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, /*-------------------------------------------------------------------------*\ * Close and inutilize socket \*-------------------------------------------------------------------------*/ -void socket_destroy(p_socket ps) { +LUASOCKET_PRIVATE void socket_destroy(p_socket ps) { if (*ps != SOCKET_INVALID) { socket_setblocking(ps); /* close can take a long time on WIN32 */ closesocket(*ps); @@ -99,7 +101,7 @@ void socket_destroy(p_socket ps) { /*-------------------------------------------------------------------------*\ * \*-------------------------------------------------------------------------*/ -void socket_shutdown(p_socket ps, int how) { +LUASOCKET_PRIVATE void socket_shutdown(p_socket ps, int how) { socket_setblocking(ps); shutdown(*ps, how); socket_setnonblocking(ps); @@ -108,7 +110,7 @@ void socket_shutdown(p_socket ps, int how) { /*-------------------------------------------------------------------------*\ * Creates and sets up a socket \*-------------------------------------------------------------------------*/ -int socket_create(p_socket ps, int domain, int type, int protocol) { +LUASOCKET_PRIVATE int socket_create(p_socket ps, int domain, int type, int protocol) { *ps = socket(domain, type, protocol); if (*ps != SOCKET_INVALID) return IO_DONE; else return WSAGetLastError(); @@ -117,7 +119,7 @@ int socket_create(p_socket ps, int domain, int type, int protocol) { /*-------------------------------------------------------------------------*\ * Connects or returns error message \*-------------------------------------------------------------------------*/ -int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { +LUASOCKET_PRIVATE int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { int err; /* don't call on closed socket */ if (*ps == SOCKET_INVALID) return IO_CLOSED; @@ -146,7 +148,7 @@ int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { /*-------------------------------------------------------------------------*\ * Binds or returns error message \*-------------------------------------------------------------------------*/ -int socket_bind(p_socket ps, SA *addr, socklen_t len) { +LUASOCKET_PRIVATE int socket_bind(p_socket ps, SA *addr, socklen_t len) { int err = IO_DONE; socket_setblocking(ps); if (bind(*ps, addr, len) < 0) err = WSAGetLastError(); @@ -157,7 +159,7 @@ int socket_bind(p_socket ps, SA *addr, socklen_t len) { /*-------------------------------------------------------------------------*\ * \*-------------------------------------------------------------------------*/ -int socket_listen(p_socket ps, int backlog) { +LUASOCKET_PRIVATE int socket_listen(p_socket ps, int backlog) { int err = IO_DONE; socket_setblocking(ps); if (listen(*ps, backlog) < 0) err = WSAGetLastError(); @@ -168,7 +170,7 @@ int socket_listen(p_socket ps, int backlog) { /*-------------------------------------------------------------------------*\ * Accept with timeout \*-------------------------------------------------------------------------*/ -int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, +LUASOCKET_PRIVATE int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout tm) { if (*ps == SOCKET_INVALID) return IO_CLOSED; for ( ;; ) { @@ -190,7 +192,7 @@ int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, * this can take an awful lot of time and we will end up blocked. * Therefore, whoever calls this function should not pass a huge buffer. \*-------------------------------------------------------------------------*/ -int socket_send(p_socket ps, const char *data, size_t count, +LUASOCKET_PRIVATE int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm) { int err; @@ -218,7 +220,7 @@ int socket_send(p_socket ps, const char *data, size_t count, /*-------------------------------------------------------------------------*\ * Sendto with timeout \*-------------------------------------------------------------------------*/ -int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, +LUASOCKET_PRIVATE int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t len, p_timeout tm) { int err; @@ -239,7 +241,7 @@ int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, /*-------------------------------------------------------------------------*\ * Receive with timeout \*-------------------------------------------------------------------------*/ -int socket_recv(p_socket ps, char *data, size_t count, size_t *got, +LUASOCKET_PRIVATE int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { int err, prev = IO_DONE; @@ -268,7 +270,7 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got, /*-------------------------------------------------------------------------*\ * Recvfrom with timeout \*-------------------------------------------------------------------------*/ -int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, +LUASOCKET_PRIVATE int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *len, p_timeout tm) { int err, prev = IO_DONE; @@ -297,7 +299,7 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, /*-------------------------------------------------------------------------*\ * Put socket into blocking mode \*-------------------------------------------------------------------------*/ -void socket_setblocking(p_socket ps) { +LUASOCKET_PRIVATE void socket_setblocking(p_socket ps) { u_long argp = 0; ioctlsocket(*ps, FIONBIO, &argp); } @@ -305,7 +307,7 @@ void socket_setblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * Put socket into non-blocking mode \*-------------------------------------------------------------------------*/ -void socket_setnonblocking(p_socket ps) { +LUASOCKET_PRIVATE void socket_setnonblocking(p_socket ps) { u_long argp = 1; ioctlsocket(*ps, FIONBIO, &argp); } @@ -313,13 +315,13 @@ void socket_setnonblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * DNS helpers \*-------------------------------------------------------------------------*/ -int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) { +LUASOCKET_PRIVATE int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) { *hp = gethostbyaddr(addr, len, AF_INET); if (*hp) return IO_DONE; else return WSAGetLastError(); } -int socket_gethostbyname(const char *addr, struct hostent **hp) { +LUASOCKET_PRIVATE int socket_gethostbyname(const char *addr, struct hostent **hp) { *hp = gethostbyname(addr); if (*hp) return IO_DONE; else return WSAGetLastError(); @@ -328,7 +330,7 @@ int socket_gethostbyname(const char *addr, struct hostent **hp) { /*-------------------------------------------------------------------------*\ * Error translation functions \*-------------------------------------------------------------------------*/ -const char *socket_hoststrerror(int err) { +LUASOCKET_PRIVATE const char *socket_hoststrerror(int err) { if (err <= 0) return io_strerror(err); switch (err) { case WSAHOST_NOT_FOUND: return PIE_HOST_NOT_FOUND; @@ -336,7 +338,7 @@ const char *socket_hoststrerror(int err) { } } -const char *socket_strerror(int err) { +LUASOCKET_PRIVATE const char *socket_strerror(int err) { if (err <= 0) return io_strerror(err); switch (err) { case WSAEADDRINUSE: return PIE_ADDRINUSE; @@ -350,12 +352,12 @@ const char *socket_strerror(int err) { } } -const char *socket_ioerror(p_socket ps, int err) { +LUASOCKET_PRIVATE const char *socket_ioerror(p_socket ps, int err) { (void) ps; return socket_strerror(err); } -static const char *wstrerror(int err) { +LUASOCKET_PRIVATE static const char *wstrerror(int err) { switch (err) { case WSAEINTR: return "Interrupted function call"; case WSAEACCES: return PIE_ACCESS; // "Permission denied"; @@ -404,7 +406,7 @@ static const char *wstrerror(int err) { } } -const char *socket_gaistrerror(int err) { +LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) { if (err == 0) return NULL; switch (err) { case EAI_AGAIN: return PIE_AGAIN; From 2d8f0d99011b267ed354ab6e8317d93b9627eed4 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:04:49 -0700 Subject: [PATCH 094/194] src/makefile: remove visibility and dllexport defines in favor of in-source labeling --- src/makefile | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/makefile b/src/makefile index cc1ec7e..74bf3d5 100644 --- a/src/makefile +++ b/src/makefile @@ -149,12 +149,8 @@ PLATS= macosx linux win32 mingw solaris SO_macosx=so O_macosx=o CC_macosx=gcc -DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' -CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common \ - -fvisibility=hidden +DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN +CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc SOCKET_macosx=usocket.o @@ -165,12 +161,9 @@ SOCKET_macosx=usocket.o SO_linux=so O_linux=o CC_linux=gcc -DEF_linux=-DLUASOCKET_$(DEBUG) \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' +DEF_linux=-DLUASOCKET_$(DEBUG) CFLAGS_linux=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ - -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden + -Wimplicit -O2 -ggdb3 -fpic LDFLAGS_linux=-O -shared -fpic -o LD_linux=gcc SOCKET_linux=usocket.o @@ -181,12 +174,9 @@ SOCKET_linux=usocket.o SO_freebsd=so O_freebsd=o CC_freebsd=gcc -DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' +DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN CFLAGS_freebsd=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ - -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden + -Wimplicit -O2 -ggdb3 -fpic LDFLAGS_freebsd=-O -shared -fpic -o LD_freebsd=gcc SOCKET_freebsd=usocket.o @@ -197,12 +187,9 @@ SOCKET_freebsd=usocket.o SO_solaris=so O_solaris=o CC_solaris=gcc -DEF_solaris=-DLUASOCKET_$(DEBUG) \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' +DEF_solaris=-DLUASOCKET_$(DEBUG) CFLAGS_solaris=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ - -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden + -Wimplicit -O2 -ggdb3 -fpic LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o LD_solaris=gcc SOCKET_solaris=usocket.o @@ -214,10 +201,8 @@ SO_mingw=dll O_mingw=o CC_mingw=gcc DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) \ - -DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \ - -DMIME_API='__declspec(dllexport)' -CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common \ - -fvisibility=hidden + -DWINVER=0x0501 +CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o LD_mingw=gcc SOCKET_mingw=wsocket.o @@ -230,8 +215,8 @@ SO_win32=dll O_win32=obj CC_win32=cl DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \ - //D "LUASOCKET_API=__declspec(dllexport)" //D "_CRT_SECURE_NO_WARNINGS" \ - //D "_WINDLL" //D "MIME_API=__declspec(dllexport)" \ + //D "_CRT_SECURE_NO_WARNINGS" \ + //D "_WINDLL" \ //D "LUASOCKET_$(DEBUG)" CFLAGS_win32=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo LDFLAGS_win32= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \ From e2e43d62fa925e7e22385505ed0c635255c77c0a Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 25 Feb 2019 16:06:30 -0700 Subject: [PATCH 095/194] rockspecs: remove visibility and dllexport defines in favor of in-source labeling --- luasocket-scm-0.rockspec | 199 ++++++++++++++----------- rockspec/luasocket-3.0rc2-1.rockspec | 209 +++++++++++++++------------ 2 files changed, 231 insertions(+), 177 deletions(-) diff --git a/luasocket-scm-0.rockspec b/luasocket-scm-0.rockspec index c827e46..6cdb0ce 100644 --- a/luasocket-scm-0.rockspec +++ b/luasocket-scm-0.rockspec @@ -1,105 +1,132 @@ package = "LuaSocket" version = "scm-0" source = { - url = "https://github.com/diegonehab/luasocket/archive/master.zip", - dir = "luasocket-master", + url = "git://github.com/diegonehab/luasocket.git" + , branch="master" } description = { - summary = "Network support for the Lua language", - detailed = [[ + summary = "Network support for the Lua language", + detailed = [[ LuaSocket is a Lua extension library that is composed by two parts: a C core that provides support for the TCP and UDP transport layers, and a set of Lua modules that add support for functionality commonly needed by applications that deal with the Internet. ]], - homepage = "http://luaforge.net/projects/luasocket/", - license = "MIT" + homepage = "http://luaforge.net/projects/luasocket/", + license = "MIT" } dependencies = { - "lua >= 5.1" + "lua >= 5.1" } local function make_plat(plat) - local defines = { - unix = { - "LUASOCKET_DEBUG", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - macosx = { - "LUASOCKET_DEBUG", - "UNIX_HAS_SUN_LEN", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - win32 = { - "LUASOCKET_DEBUG", - "NDEBUG", - "LUASOCKET_API=__declspec(dllexport)", - "MIME_API=__declspec(dllexport)" - }, - mingw32 = { - "LUASOCKET_DEBUG", - "LUASOCKET_INET_PTON", - "WINVER=0x0501", - "LUASOCKET_API=__declspec(dllexport)", - "MIME_API=__declspec(dllexport)" - } - } - local modules = { - ["socket.core"] = { - sources = { "src/luasocket.c", "src/timeout.c", "src/buffer.c", "src/io.c", "src/auxiliar.c", "src/options.c", "src/inet.c", "src/except.c", "src/select.c", "src/tcp.c", "src/udp.c", "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["mime.core"] = { - sources = { "src/mime.c", "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["socket.http"] = "src/http.lua", - ["socket.url"] = "src/url.lua", - ["socket.tp"] = "src/tp.lua", - ["socket.ftp"] = "src/ftp.lua", - ["socket.headers"] = "src/headers.lua", - ["socket.smtp"] = "src/smtp.lua", - ltn12 = "src/ltn12.lua", - socket = "src/socket.lua", - mime = "src/mime.lua" - } - if plat == "unix" or plat == "macosx" or plat == "haiku" then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" - if plat == "haiku" then - modules["socket.core"].libraries = {"network"} - end - modules["socket.unix"] = { - sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/unix.c", "src/unixdgram.c", "src/unixstream.c" }, - defines = defines[plat], - incdir = "/src" - } - modules["socket.serial"] = { - sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/serial.c" }, - defines = defines[plat], - incdir = "/src" - } - end - if plat == "win32" or plat == "mingw32" then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" - modules["socket.core"].libraries = { "ws2_32" } - end - return { modules = modules } + local defines = { + unix = { + "LUASOCKET_DEBUG" + }, + macosx = { + "LUASOCKET_DEBUG", + "UNIX_HAS_SUN_LEN" + }, + win32 = { + "LUASOCKET_DEBUG", + "NDEBUG" + }, + mingw32 = { + "LUASOCKET_DEBUG", + "LUASOCKET_INET_PTON", + "WINVER=0x0501" + } + } + local modules = { + ["socket.core"] = { + sources = { + "src/luasocket.c" + , "src/timeout.c" + , "src/buffer.c" + , "src/io.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/inet.c" + , "src/except.c" + , "src/select.c" + , "src/tcp.c" + , "src/udp.c" + , "src/compat.c" }, + defines = defines[plat], + incdir = "/src" + }, + ["mime.core"] = { + sources = { "src/mime.c", "src/compat.c" }, + defines = defines[plat], + incdir = "/src" + }, + ["socket.http"] = "src/http.lua", + ["socket.url"] = "src/url.lua", + ["socket.tp"] = "src/tp.lua", + ["socket.ftp"] = "src/ftp.lua", + ["socket.headers"] = "src/headers.lua", + ["socket.smtp"] = "src/smtp.lua", + ltn12 = "src/ltn12.lua", + socket = "src/socket.lua", + mime = "src/mime.lua" + } + if plat == "unix" + or plat == "macosx" + or plat == "haiku" + then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" + if plat == "haiku" then + modules["socket.core"].libraries = {"network"} + end + modules["socket.unix"] = { + sources = { + "src/buffer.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/timeout.c" + , "src/io.c" + , "src/usocket.c" + , "src/unix.c" + , "src/unixdgram.c" + , "src/unixstream.c" }, + defines = defines[plat], + incdir = "/src" + } + modules["socket.serial"] = { + sources = { + "src/buffer.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/timeout.c" + , "src/io.c" + , "src/usocket.c" + , "src/serial.c" }, + defines = defines[plat], + incdir = "/src" + } + end + if plat == "win32" + or plat == "mingw32" + then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" + modules["socket.core"].libraries = { "ws2_32" } + end + return { modules = modules } end build = { - type = "builtin", - platforms = { - unix = make_plat("unix"), - macosx = make_plat("macosx"), - haiku = make_plat("haiku"), - win32 = make_plat("win32"), - mingw32 = make_plat("mingw32") - }, - copy_directories = { "doc", "samples", "etc", "test" } + type = "builtin", + platforms = { + unix = make_plat("unix"), + macosx = make_plat("macosx"), + haiku = make_plat("haiku"), + win32 = make_plat("win32"), + mingw32 = make_plat("mingw32") + }, + copy_directories = { + "doc" + , "samples" + , "etc" + , "test" } } diff --git a/rockspec/luasocket-3.0rc2-1.rockspec b/rockspec/luasocket-3.0rc2-1.rockspec index 8e37a4a..2b299f3 100644 --- a/rockspec/luasocket-3.0rc2-1.rockspec +++ b/rockspec/luasocket-3.0rc2-1.rockspec @@ -1,105 +1,132 @@ package = "LuaSocket" version = "3.0rc2-1" source = { - url = "git://github.com/diegonehab/luasocket.git", - tag = "v3.0-rc2", + url = "git://github.com/diegonehab/luasocket.git", + tag = "v3.0-rc2", } description = { - summary = "Network support for the Lua language", - detailed = [[ - LuaSocket is a Lua extension library that is composed by two parts: a C core - that provides support for the TCP and UDP transport layers, and a set of Lua - modules that add support for functionality commonly needed by applications - that deal with the Internet. - ]], - homepage = "http://luaforge.net/projects/luasocket/", - license = "MIT" + summary = "Network support for the Lua language", + detailed = [[ + LuaSocket is a Lua extension library that is composed by two parts: a C core + that provides support for the TCP and UDP transport layers, and a set of Lua + modules that add support for functionality commonly needed by applications + that deal with the Internet. + ]], + homepage = "http://luaforge.net/projects/luasocket/", + license = "MIT" } dependencies = { - "lua >= 5.1" + "lua >= 5.1" } local function make_plat(plat) - local defines = { - unix = { - "LUASOCKET_DEBUG", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - macosx = { - "LUASOCKET_DEBUG", - "UNIX_HAS_SUN_LEN", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - win32 = { - "LUASOCKET_DEBUG", - "NDEBUG", - "LUASOCKET_API=__declspec(dllexport)", - "MIME_API=__declspec(dllexport)" - }, - mingw32 = { - "LUASOCKET_DEBUG", - "LUASOCKET_INET_PTON", - "WINVER=0x0501", - "LUASOCKET_API=__declspec(dllexport)", - "MIME_API=__declspec(dllexport)" - } - } - local modules = { - ["socket.core"] = { - sources = { "src/luasocket.c", "src/timeout.c", "src/buffer.c", "src/io.c", "src/auxiliar.c", "src/options.c", "src/inet.c", "src/except.c", "src/select.c", "src/tcp.c", "src/udp.c", "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["mime.core"] = { - sources = { "src/mime.c", "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["socket.http"] = "src/http.lua", - ["socket.url"] = "src/url.lua", - ["socket.tp"] = "src/tp.lua", - ["socket.ftp"] = "src/ftp.lua", - ["socket.headers"] = "src/headers.lua", - ["socket.smtp"] = "src/smtp.lua", - ltn12 = "src/ltn12.lua", - socket = "src/socket.lua", - mime = "src/mime.lua" - } - if plat == "unix" or plat == "macosx" or plat == "haiku" then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" - if plat == "haiku" then - modules["socket.core"].libraries = {"network"} - end - modules["socket.unix"] = { - sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/unix.c" }, - defines = defines[plat], - incdir = "/src" - } - modules["socket.serial"] = { - sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", "src/usocket.c", "src/serial.c" }, - defines = defines[plat], - incdir = "/src" - } - end - if plat == "win32" or plat == "mingw32" then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" - modules["socket.core"].libraries = { "ws2_32" } - end - return { modules = modules } + local defines = { + unix = { + "LUASOCKET_DEBUG" + }, + macosx = { + "LUASOCKET_DEBUG", + "UNIX_HAS_SUN_LEN" + }, + win32 = { + "LUASOCKET_DEBUG", + "NDEBUG" + }, + mingw32 = { + "LUASOCKET_DEBUG", + "LUASOCKET_INET_PTON", + "WINVER=0x0501" + } + } + local modules = { + ["socket.core"] = { + sources = { + "src/luasocket.c" + , "src/timeout.c" + , "src/buffer.c" + , "src/io.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/inet.c" + , "src/except.c" + , "src/select.c" + , "src/tcp.c" + , "src/udp.c" + , "src/compat.c" }, + defines = defines[plat], + incdir = "/src" + }, + ["mime.core"] = { + sources = { "src/mime.c", "src/compat.c" }, + defines = defines[plat], + incdir = "/src" + }, + ["socket.http"] = "src/http.lua", + ["socket.url"] = "src/url.lua", + ["socket.tp"] = "src/tp.lua", + ["socket.ftp"] = "src/ftp.lua", + ["socket.headers"] = "src/headers.lua", + ["socket.smtp"] = "src/smtp.lua", + ltn12 = "src/ltn12.lua", + socket = "src/socket.lua", + mime = "src/mime.lua" + } + if plat == "unix" + or plat == "macosx" + or plat == "haiku" + then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" + if plat == "haiku" then + modules["socket.core"].libraries = {"network"} + end + modules["socket.unix"] = { + sources = { + "src/buffer.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/timeout.c" + , "src/io.c" + , "src/usocket.c" + , "src/unix.c" + , "src/unixdgram.c" + , "src/unixstream.c" }, + defines = defines[plat], + incdir = "/src" + } + modules["socket.serial"] = { + sources = { + "src/buffer.c" + , "src/auxiliar.c" + , "src/options.c" + , "src/timeout.c" + , "src/io.c" + , "src/usocket.c" + , "src/serial.c" }, + defines = defines[plat], + incdir = "/src" + } + end + if plat == "win32" + or plat == "mingw32" + then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" + modules["socket.core"].libraries = { "ws2_32" } + end + return { modules = modules } end build = { - type = "builtin", - platforms = { - unix = make_plat("unix"), - macosx = make_plat("macosx"), - haiku = make_plat("haiku"), - win32 = make_plat("win32"), - mingw32 = make_plat("mingw32") - }, - copy_directories = { "doc", "samples", "etc", "test" } + type = "builtin", + platforms = { + unix = make_plat("unix"), + macosx = make_plat("macosx"), + haiku = make_plat("haiku"), + win32 = make_plat("win32"), + mingw32 = make_plat("mingw32") + }, + copy_directories = { + "doc" + , "samples" + , "etc" + , "test" } } From d9afe3fd9ccf64a0686683f5453937c08611aa28 Mon Sep 17 00:00:00 2001 From: Mojca Miklavec Date: Wed, 21 Mar 2018 18:02:46 +0100 Subject: [PATCH 096/194] Only use EAI_OVERFLOW, AI_NUMERICSERV if defined Some systems like Mac OS X 10.5 (and lower) do not have EAI_OVERFLOW and AI_NUMERICSERV defined. These variables are used to avoid a potentially slow name resolution for the hostname (which will always be an ip address) and for service name (which will always be an actual port number). The code might be slower, but it should still work. Closes: #242 --- src/udp.c | 5 ++++- src/usocket.c | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/udp.c b/src/udp.c index 99a766f..e59fa1b 100644 --- a/src/udp.c +++ b/src/udp.c @@ -188,7 +188,10 @@ static int meth_sendto(lua_State *L) { memset(&aihint, 0, sizeof(aihint)); aihint.ai_family = udp->family; aihint.ai_socktype = SOCK_DGRAM; - aihint.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV; + aihint.ai_flags = AI_NUMERICHOST; +#ifdef AI_NUMERICSERV + aihint.ai_flags |= AI_NUMERICSERV; +#endif err = getaddrinfo(ip, port, &aihint, &ai); if (err) { lua_pushnil(L); diff --git a/src/usocket.c b/src/usocket.c index 08a961d..aee876d 100644 --- a/src/usocket.c +++ b/src/usocket.c @@ -440,7 +440,9 @@ LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) { case EAI_FAMILY: return PIE_FAMILY; case EAI_MEMORY: return PIE_MEMORY; case EAI_NONAME: return PIE_NONAME; +#ifdef EAI_OVERFLOW case EAI_OVERFLOW: return PIE_OVERFLOW; +#endif #ifdef EAI_PROTOCOL case EAI_PROTOCOL: return PIE_PROTOCOL; #endif From 297f9d0277ca4c93a5bd4306e0d31a4a98940089 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Thu, 28 Feb 2019 18:40:30 -0700 Subject: [PATCH 097/194] bugfix: http.lua multischeme change that got dropped during PR conflict resolution --- src/http.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/http.lua b/src/http.lua index 2fa5a26..6a3416e 100644 --- a/src/http.lua +++ b/src/http.lua @@ -264,10 +264,8 @@ end -- default url parts local default = { - host = "", - port = PORT, - path ="/", - scheme = SCHEME + path ="/" + , scheme = "http" } local function adjustrequest(reqt) From 1e4255e2a937d46dd46695eea56b570090427001 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 1 Mar 2019 20:46:37 -0300 Subject: [PATCH 098/194] 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 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) - - $(BUILD) + + $(LUALDIR) + + + $(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 From c7215bef07cb855844d1da42d2e64c5be869d5b7 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sat, 2 Mar 2019 17:47:18 -0300 Subject: [PATCH 099/194] Remove .filters and hardcoded platform. --- mime.vcxproj | 3 +-- mime.vcxproj.filters | 16 ------------- socket.vcxproj | 3 +-- socket.vcxproj.filters | 51 ------------------------------------------ 4 files changed, 2 insertions(+), 71 deletions(-) delete mode 100644 mime.vcxproj.filters delete mode 100644 socket.vcxproj.filters diff --git a/mime.vcxproj b/mime.vcxproj index 6a7b35a..43acee9 100755 --- a/mime.vcxproj +++ b/mime.vcxproj @@ -24,7 +24,6 @@ {128E8BD0-174A-48F0-8771-92B1E8D18713} Win32Proj - 10.0.15063.0 @@ -202,4 +201,4 @@ - + \ No newline at end of file diff --git a/mime.vcxproj.filters b/mime.vcxproj.filters deleted file mode 100644 index 621215b..0000000 --- a/mime.vcxproj.filters +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - {fad87a86-297c-4881-a114-73b967bb3c92} - - - - - cdir - - - \ No newline at end of file diff --git a/socket.vcxproj b/socket.vcxproj index e639216..305c094 100755 --- a/socket.vcxproj +++ b/socket.vcxproj @@ -35,7 +35,6 @@ {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A} Win32Proj - 10.0.15063.0 @@ -213,4 +212,4 @@ - + \ No newline at end of file diff --git a/socket.vcxproj.filters b/socket.vcxproj.filters deleted file mode 100644 index 38f2f07..0000000 --- a/socket.vcxproj.filters +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - cdir - - - cdir - - - ldir - - - ldir - - - ldir - - - ldir - - - ldir - - - ldir - - - - - {b053460d-5439-4e3a-a2eb-c31a95b5691f} - - - {b301b82c-37cb-4e05-9333-194e92ed7a62} - - - \ No newline at end of file From 03b72d8f7ee5e35f76f97da299ce676946023725 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sat, 9 Mar 2019 23:23:48 -0300 Subject: [PATCH 100/194] Use static initialization This helps with multi-threaded apps. --- src/makefile | 3 +- src/mime.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 145 insertions(+), 10 deletions(-) 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); From 2af4872a401cbd0c1255e19ee26620f0431dd9f5 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sun, 10 Mar 2019 00:47:17 -0300 Subject: [PATCH 101/194] Fix formatting. --- src/mime.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mime.c b/src/mime.c index ce28826..0e9863b 100755 --- a/src/mime.c +++ b/src/mime.c @@ -61,7 +61,7 @@ static luaL_Reg func[] = { \*-------------------------------------------------------------------------*/ enum {QP_PLAIN, QP_QUOTED, QP_CR, QP_IF_LAST}; -static UC qpclass[] = { +static const UC qpclass[] = { QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_IF_LAST, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_CR, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, @@ -237,10 +237,10 @@ static int mime_global_wrp(lua_State *L) return 2; } +#if 0 /*-------------------------------------------------------------------------*\ * Fill base64 decode map. \*-------------------------------------------------------------------------*/ -#if 0 static void b64setup(UC *unbase) { int i; @@ -448,11 +448,11 @@ static int mime_global_unb64(lua_State *L) * To encode one byte, we need to see the next two. * Worst case is when we see a space, and wonder if a CRLF is comming \*-------------------------------------------------------------------------*/ +#if 0 /*-------------------------------------------------------------------------*\ * Split quoted-printable characters into classes * Precompute reverse map for encoding \*-------------------------------------------------------------------------*/ -#if 0 static void qpsetup(UC *cl, UC *unbase) { From 98800e9129a63e8d0f751108d79efdffe58e98f7 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:55:43 -0700 Subject: [PATCH 102/194] auxiliar: pragma visibility --- src/auxiliar.c | 26 +++++++++++--------------- src/auxiliar.h | 16 +++++++++------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/auxiliar.c b/src/auxiliar.c index 0bd7927..93a66a0 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c @@ -7,13 +7,10 @@ #include #include -/*=========================================================================*\ -* Exported functions -\*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Initializes the module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int auxiliar_open(lua_State *L) { +int auxiliar_open(lua_State *L) { (void) L; return 0; } @@ -22,7 +19,7 @@ LUASOCKET_PRIVATE int auxiliar_open(lua_State *L) { * Creates a new class with given methods * Methods whose names start with __ are passed directly to the metatable. \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) { +void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) { luaL_newmetatable(L, classname); /* mt */ /* create __index table to place methods */ lua_pushstring(L, "__index"); /* mt,"__index" */ @@ -45,7 +42,7 @@ LUASOCKET_PRIVATE void auxiliar_newclass(lua_State *L, const char *classname, lu /*-------------------------------------------------------------------------*\ * Prints the value of a class in a nice way \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int auxiliar_tostring(lua_State *L) { +int auxiliar_tostring(lua_State *L) { char buf[32]; if (!lua_getmetatable(L, 1)) goto error; lua_pushstring(L, "__index"); @@ -66,7 +63,7 @@ error: /*-------------------------------------------------------------------------*\ * Insert class into group \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void auxiliar_add2group(lua_State *L, const char *classname, const char *groupname) { +void auxiliar_add2group(lua_State *L, const char *classname, const char *groupname) { luaL_getmetatable(L, classname); lua_pushstring(L, groupname); lua_pushboolean(L, 1); @@ -77,7 +74,7 @@ LUASOCKET_PRIVATE void auxiliar_add2group(lua_State *L, const char *classname, c /*-------------------------------------------------------------------------*\ * Make sure argument is a boolean \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int auxiliar_checkboolean(lua_State *L, int objidx) { +int auxiliar_checkboolean(lua_State *L, int objidx) { if (!lua_isboolean(L, objidx)) auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN)); return lua_toboolean(L, objidx); @@ -87,7 +84,7 @@ LUASOCKET_PRIVATE int auxiliar_checkboolean(lua_State *L, int objidx) { * Return userdata pointer if object belongs to a given class, abort with * error otherwise \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) { +void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) { void *data = auxiliar_getclassudata(L, classname, objidx); if (!data) { char msg[45]; @@ -101,7 +98,7 @@ LUASOCKET_PRIVATE void *auxiliar_checkclass(lua_State *L, const char *classname, * Return userdata pointer if object belongs to a given group, abort with * error otherwise \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) { +void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) { void *data = auxiliar_getgroupudata(L, groupname, objidx); if (!data) { char msg[45]; @@ -114,7 +111,7 @@ LUASOCKET_PRIVATE void *auxiliar_checkgroup(lua_State *L, const char *groupname, /*-------------------------------------------------------------------------*\ * Set object class \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void auxiliar_setclass(lua_State *L, const char *classname, int objidx) { +void auxiliar_setclass(lua_State *L, const char *classname, int objidx) { luaL_getmetatable(L, classname); if (objidx < 0) objidx--; lua_setmetatable(L, objidx); @@ -124,7 +121,7 @@ LUASOCKET_PRIVATE void auxiliar_setclass(lua_State *L, const char *classname, in * Get a userdata pointer if object belongs to a given group. Return NULL * otherwise \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) { +void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) { if (!lua_getmetatable(L, objidx)) return NULL; lua_pushstring(L, groupname); @@ -142,7 +139,7 @@ LUASOCKET_PRIVATE void *auxiliar_getgroupudata(lua_State *L, const char *groupna * Get a userdata pointer if object belongs to a given class. Return NULL * otherwise \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { +void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { return luaL_testudata(L, objidx, classname); } @@ -150,9 +147,8 @@ LUASOCKET_PRIVATE void *auxiliar_getclassudata(lua_State *L, const char *classna * Throws error when argument does not have correct type. * Used to be part of lauxlib in Lua 5.1, was dropped from 5.2. \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int auxiliar_typeerror (lua_State *L, int narg, const char *tname) { +int auxiliar_typeerror (lua_State *L, int narg, const char *tname) { const char *msg = lua_pushfstring(L, "%s expected, got %s", tname, luaL_typename(L, narg)); return luaL_argerror(L, narg, msg); } - diff --git a/src/auxiliar.h b/src/auxiliar.h index 65511d4..234b00a 100644 --- a/src/auxiliar.h +++ b/src/auxiliar.h @@ -29,20 +29,22 @@ * reverse mapping are done using lauxlib. \*=========================================================================*/ -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" +#include "luasocket.h" + +#pragma GCC visibility push(hidden) int auxiliar_open(lua_State *L); void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func); +int auxiliar_tostring(lua_State *L); void auxiliar_add2group(lua_State *L, const char *classname, const char *group); -void auxiliar_setclass(lua_State *L, const char *classname, int objidx); +int auxiliar_checkboolean(lua_State *L, int objidx); void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx); void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx); -void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); +void auxiliar_setclass(lua_State *L, const char *classname, int objidx); void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); -int auxiliar_checkboolean(lua_State *L, int objidx); -int auxiliar_tostring(lua_State *L); +void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); int auxiliar_typeerror(lua_State *L, int narg, const char *tname); +#pragma GCC visibility pop + #endif /* AUXILIAR_H */ From e3ac49efbda8b432470b57eae6fade7501c3da03 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:56:01 -0700 Subject: [PATCH 103/194] buffer: pragma visibility --- src/buffer.c | 19 +++++++------------ src/buffer.h | 11 +++++++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 357730a..ac5c531 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -3,11 +3,6 @@ * LuaSocket toolkit \*=========================================================================*/ #include "luasocket.h" - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - #include "buffer.h" /*=========================================================================*\ @@ -34,7 +29,7 @@ static int sendraw(p_buffer buf, const char *data, size_t count, size_t *sent); /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int buffer_open(lua_State *L) { +int buffer_open(lua_State *L) { (void) L; return 0; } @@ -42,7 +37,7 @@ LUASOCKET_PRIVATE int buffer_open(lua_State *L) { /*-------------------------------------------------------------------------*\ * Initializes C structure \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void buffer_init(p_buffer buf, p_io io, p_timeout tm) { +void buffer_init(p_buffer buf, p_io io, p_timeout tm) { buf->first = buf->last = 0; buf->io = io; buf->tm = tm; @@ -53,7 +48,7 @@ LUASOCKET_PRIVATE void buffer_init(p_buffer buf, p_io io, p_timeout tm) { /*-------------------------------------------------------------------------*\ * object:getstats() interface \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int buffer_meth_getstats(lua_State *L, p_buffer buf) { +int buffer_meth_getstats(lua_State *L, p_buffer buf) { lua_pushnumber(L, (lua_Number) buf->received); lua_pushnumber(L, (lua_Number) buf->sent); lua_pushnumber(L, timeout_gettime() - buf->birthday); @@ -63,7 +58,7 @@ LUASOCKET_PRIVATE int buffer_meth_getstats(lua_State *L, p_buffer buf) { /*-------------------------------------------------------------------------*\ * object:setstats() interface \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int buffer_meth_setstats(lua_State *L, p_buffer buf) { +int buffer_meth_setstats(lua_State *L, p_buffer buf) { buf->received = (long) luaL_optnumber(L, 2, (lua_Number) buf->received); buf->sent = (long) luaL_optnumber(L, 3, (lua_Number) buf->sent); if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4); @@ -74,7 +69,7 @@ LUASOCKET_PRIVATE int buffer_meth_setstats(lua_State *L, p_buffer buf) { /*-------------------------------------------------------------------------*\ * object:send() interface \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int buffer_meth_send(lua_State *L, p_buffer buf) { +int buffer_meth_send(lua_State *L, p_buffer buf) { int top = lua_gettop(L); int err = IO_DONE; size_t size = 0, sent = 0; @@ -107,7 +102,7 @@ LUASOCKET_PRIVATE int buffer_meth_send(lua_State *L, p_buffer buf) { /*-------------------------------------------------------------------------*\ * object:receive() interface \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int buffer_meth_receive(lua_State *L, p_buffer buf) { +int buffer_meth_receive(lua_State *L, p_buffer buf) { int err = IO_DONE, top = lua_gettop(L); luaL_Buffer b; size_t size; @@ -156,7 +151,7 @@ LUASOCKET_PRIVATE int buffer_meth_receive(lua_State *L, p_buffer buf) { /*-------------------------------------------------------------------------*\ * Determines if there is any data in the read buffer \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int buffer_isempty(p_buffer buf) { +int buffer_isempty(p_buffer buf) { return buf->first >= buf->last; } diff --git a/src/buffer.h b/src/buffer.h index 1281bb3..4218ea0 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -15,8 +15,7 @@ * The module is built on top of the I/O abstraction defined in io.h and the * timeout management is done with the timeout.h interface. \*=========================================================================*/ -#include "lua.h" - +#include "luasocket.h" #include "io.h" #include "timeout.h" @@ -34,12 +33,16 @@ typedef struct t_buffer_ { } t_buffer; typedef t_buffer *p_buffer; +#pragma GCC visibility push(hidden) + int buffer_open(lua_State *L); void buffer_init(p_buffer buf, p_io io, p_timeout tm); -int buffer_meth_send(lua_State *L, p_buffer buf); -int buffer_meth_receive(lua_State *L, p_buffer buf); int buffer_meth_getstats(lua_State *L, p_buffer buf); int buffer_meth_setstats(lua_State *L, p_buffer buf); +int buffer_meth_send(lua_State *L, p_buffer buf); +int buffer_meth_receive(lua_State *L, p_buffer buf); int buffer_isempty(p_buffer buf); +#pragma GCC visibility pop + #endif /* BUF_H */ From 133774cd3db0d8ce8ccc1df8538a6d44552fc1f0 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:56:48 -0700 Subject: [PATCH 104/194] compat: pragma visibility --- src/compat.c | 5 +++-- src/compat.h | 18 +++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/compat.c b/src/compat.c index 1290f70..34ffdaf 100644 --- a/src/compat.c +++ b/src/compat.c @@ -2,10 +2,11 @@ #include "compat.h" #if LUA_VERSION_NUM==501 + /* ** Adapted from Lua 5.2 */ -LUASOCKET_PRIVATE void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { +void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { luaL_checkstack(L, nup+1, "too many upvalues"); for (; l->name != NULL; l++) { /* fill the table with given functions */ int i; @@ -21,7 +22,7 @@ LUASOCKET_PRIVATE void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) /* ** Duplicated from Lua 5.2 */ -LUASOCKET_PRIVATE void *luaL_testudata (lua_State *L, int ud, const char *tname) { +void *luasocket_testudata (lua_State *L, int ud, const char *tname) { void *p = lua_touserdata(L, ud); if (p != NULL) { /* value is a userdata? */ if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ diff --git a/src/compat.h b/src/compat.h index 49e83f9..8c32b07 100644 --- a/src/compat.h +++ b/src/compat.h @@ -1,14 +1,18 @@ #ifndef COMPAT_H #define COMPAT_H -#include "lua.h" -#include "lauxlib.h" - #if LUA_VERSION_NUM==501 -#define luaL_setfuncs socket_setfuncs -#define luaL_testudata socket_testudata -void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); -void *luaL_testudata ( lua_State *L, int arg, const char *tname); + +#pragma GCC visibility push(hidden) + +void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup); +void *luasocket_testudata ( lua_State *L, int arg, const char *tname); + +#pragma GCC visibility pop + +#define luaL_setfuncs luasocket_setfuncs +#define luaL_testudata luasocket_testudata + #endif #endif From 4bf3eb6db2315fef8f3d18c8ce742752f7e4fda2 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:57:00 -0700 Subject: [PATCH 105/194] except: pragma visibility --- src/except.c | 10 ++-------- src/except.h | 6 +++++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/except.c b/src/except.c index dab70e7..9c3317f 100644 --- a/src/except.c +++ b/src/except.c @@ -3,14 +3,8 @@ * LuaSocket toolkit \*=========================================================================*/ #include "luasocket.h" - -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - #include "except.h" +#include #if LUA_VERSION_NUM < 502 #define lua_pcallk(L, na, nr, err, ctx, cont) \ @@ -126,7 +120,7 @@ static int global_protect(lua_State *L) { /*-------------------------------------------------------------------------*\ * Init module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int except_open(lua_State *L) { +int except_open(lua_State *L) { lua_newtable(L); /* metatable for wrapped exceptions */ lua_pushboolean(L, 0); lua_setfield(L, -2, "__metatable"); diff --git a/src/except.h b/src/except.h index 2497c05..baa7b09 100644 --- a/src/except.h +++ b/src/except.h @@ -31,8 +31,12 @@ * exceptions on error, but that don't interrupt the user script. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" + +#pragma GCC visibility push(hidden) int except_open(lua_State *L); +#pragma GCC visibility pop + #endif From 611cdd19cc8cf783f028d558cf23e9397db4fa1f Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:57:14 -0700 Subject: [PATCH 106/194] inet: pragma visibility --- src/inet.c | 34 +++++++++++++--------------------- src/inet.h | 22 ++++++++++++---------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/inet.c b/src/inet.c index bed8a7c..ec73fea 100644 --- a/src/inet.c +++ b/src/inet.c @@ -3,17 +3,12 @@ * LuaSocket toolkit \*=========================================================================*/ #include "luasocket.h" +#include "inet.h" #include #include #include -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - -#include "inet.h" - /*=========================================================================*\ * Internal function prototypes. \*=========================================================================*/ @@ -34,13 +29,10 @@ static luaL_Reg func[] = { { NULL, NULL} }; -/*=========================================================================*\ -* Exported functions -\*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int inet_open(lua_State *L) +int inet_open(lua_State *L) { lua_pushstring(L, "dns"); lua_newtable(L); @@ -145,7 +137,7 @@ static int inet_global_toip(lua_State *L) return 2; } -LUASOCKET_PRIVATE int inet_optfamily(lua_State* L, int narg, const char* def) +int inet_optfamily(lua_State* L, int narg, const char* def) { static const char* optname[] = { "unspec", "inet", "inet6", NULL }; static int optvalue[] = { AF_UNSPEC, AF_INET, AF_INET6, 0 }; @@ -153,7 +145,7 @@ LUASOCKET_PRIVATE int inet_optfamily(lua_State* L, int narg, const char* def) return optvalue[luaL_checkoption(L, narg, def, optname)]; } -LUASOCKET_PRIVATE int inet_optsocktype(lua_State* L, int narg, const char* def) +int inet_optsocktype(lua_State* L, int narg, const char* def) { static const char* optname[] = { "stream", "dgram", NULL }; static int optvalue[] = { SOCK_STREAM, SOCK_DGRAM, 0 }; @@ -244,7 +236,7 @@ static int inet_global_gethostname(lua_State *L) /*-------------------------------------------------------------------------*\ * Retrieves socket peer name \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int inet_meth_getpeername(lua_State *L, p_socket ps, int family) +int inet_meth_getpeername(lua_State *L, p_socket ps, int family) { int err; struct sockaddr_storage peer; @@ -278,7 +270,7 @@ LUASOCKET_PRIVATE int inet_meth_getpeername(lua_State *L, p_socket ps, int famil /*-------------------------------------------------------------------------*\ * Retrieves socket local name \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int inet_meth_getsockname(lua_State *L, p_socket ps, int family) +int inet_meth_getsockname(lua_State *L, p_socket ps, int family) { int err; struct sockaddr_storage peer; @@ -354,7 +346,7 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp) /*-------------------------------------------------------------------------*\ * Tries to create a new inet socket \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { +const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { const char *err = socket_strerror(socket_create(ps, family, type, protocol)); if (err == NULL && family == AF_INET6) { int yes = 1; @@ -366,7 +358,7 @@ LUASOCKET_PRIVATE const char *inet_trycreate(p_socket ps, int family, int type, /*-------------------------------------------------------------------------*\ * "Disconnects" a DGRAM socket \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) +const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) { switch (family) { case AF_INET: { @@ -393,7 +385,7 @@ LUASOCKET_PRIVATE const char *inet_trydisconnect(p_socket ps, int family, p_time /*-------------------------------------------------------------------------*\ * Tries to connect to remote address (address, port) \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE const char *inet_tryconnect(p_socket ps, int *family, const char *address, +const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *serv, p_timeout tm, struct addrinfo *connecthints) { struct addrinfo *iterator = NULL, *resolved = NULL; @@ -439,7 +431,7 @@ LUASOCKET_PRIVATE const char *inet_tryconnect(p_socket ps, int *family, const ch /*-------------------------------------------------------------------------*\ * Tries to accept a socket \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE const char *inet_tryaccept(p_socket server, int family, p_socket client, +const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm) { socklen_t len; t_sockaddr_storage addr; @@ -455,7 +447,7 @@ LUASOCKET_PRIVATE const char *inet_tryaccept(p_socket server, int family, p_sock /*-------------------------------------------------------------------------*\ * Tries to bind socket to (address, port) \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE const char *inet_trybind(p_socket ps, int *family, const char *address, +const char *inet_trybind(p_socket ps, int *family, const char *address, const char *serv, struct addrinfo *bindhints) { struct addrinfo *iterator = NULL, *resolved = NULL; const char *err = NULL; @@ -499,7 +491,7 @@ LUASOCKET_PRIVATE const char *inet_trybind(p_socket ps, int *family, const char * Some systems do not provide these so that we provide our own. \*-------------------------------------------------------------------------*/ #ifdef LUASOCKET_INET_ATON -LUASOCKET_PRIVATE int inet_aton(const char *cp, struct in_addr *inp) +int inet_aton(const char *cp, struct in_addr *inp) { unsigned int a = 0, b = 0, c = 0, d = 0; int n = 0, r; @@ -521,7 +513,7 @@ LUASOCKET_PRIVATE int inet_aton(const char *cp, struct in_addr *inp) #endif #ifdef LUASOCKET_INET_PTON -LUASOCKET_PRIVATE int inet_pton(int af, const char *src, void *dst) +int inet_pton(int af, const char *src, void *dst) { struct addrinfo hints, *res; int ret = 1; diff --git a/src/inet.h b/src/inet.h index feb3541..2e00e58 100644 --- a/src/inet.h +++ b/src/inet.h @@ -14,7 +14,7 @@ * * The Lua functions toip and tohostname are also implemented here. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" #include "socket.h" #include "timeout.h" @@ -22,21 +22,21 @@ #define LUASOCKET_INET_ATON #endif +#pragma GCC visibility push(hidden) + int inet_open(lua_State *L); -const char *inet_trycreate(p_socket ps, int family, int type, int protocol); -const char *inet_tryconnect(p_socket ps, int *family, const char *address, - const char *serv, p_timeout tm, struct addrinfo *connecthints); -const char *inet_trybind(p_socket ps, int *family, const char *address, - const char *serv, struct addrinfo *bindhints); -const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm); -const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm); +int inet_optfamily(lua_State* L, int narg, const char* def); +int inet_optsocktype(lua_State* L, int narg, const char* def); int inet_meth_getpeername(lua_State *L, p_socket ps, int family); int inet_meth_getsockname(lua_State *L, p_socket ps, int family); -int inet_optfamily(lua_State* L, int narg, const char* def); -int inet_optsocktype(lua_State* L, int narg, const char* def); +const char *inet_trycreate(p_socket ps, int family, int type, int protocol); +const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm); +const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *serv, p_timeout tm, struct addrinfo *connecthints); +const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm); +const char *inet_trybind(p_socket ps, int *family, const char *address, const char *serv, struct addrinfo *bindhints); #ifdef LUASOCKET_INET_ATON int inet_aton(const char *cp, struct in_addr *inp); @@ -47,4 +47,6 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); int inet_pton(int af, const char *src, void *dst); #endif +#pragma GCC visibility pop + #endif /* INET_H */ From ee30e4643d276c82775010534cb4877a31bde2f9 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:57:25 -0700 Subject: [PATCH 107/194] io: pragma visibility --- src/io.c | 7 ++----- src/io.h | 8 +++++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/io.c b/src/io.c index f1a2b9d..5ad4b3a 100644 --- a/src/io.c +++ b/src/io.c @@ -5,13 +5,10 @@ #include "luasocket.h" #include "io.h" -/*=========================================================================*\ -* Exported functions -\*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Initializes C structure \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { +void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { io->send = send; io->recv = recv; io->error = error; @@ -21,7 +18,7 @@ LUASOCKET_PRIVATE void io_init(p_io io, p_send send, p_recv recv, p_error error, /*-------------------------------------------------------------------------*\ * I/O error strings \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE const char *io_strerror(int err) { +const char *io_strerror(int err) { switch (err) { case IO_DONE: return NULL; case IO_CLOSED: return "closed"; diff --git a/src/io.h b/src/io.h index 8cca08a..e08eb0e 100644 --- a/src/io.h +++ b/src/io.h @@ -12,9 +12,7 @@ * The module socket.h implements this interface, and thus the module tcp.h * is very simple. \*=========================================================================*/ -#include -#include "lua.h" - +#include "luasocket.h" #include "timeout.h" /* IO error codes */ @@ -58,8 +56,12 @@ typedef struct t_io_ { } t_io; typedef t_io *p_io; +#pragma GCC visibility push(hidden) + void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); const char *io_strerror(int err); +#pragma GCC visibility pop + #endif /* IO_H */ From 2015290cb47a804e098a0bf44d349955e453c23a Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:57:34 -0700 Subject: [PATCH 108/194] luasocket: include centralization --- src/luasocket.c | 10 ---------- src/luasocket.h | 13 ++++--------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/luasocket.c b/src/luasocket.c index d2752a7..0fd99f7 100755 --- a/src/luasocket.c +++ b/src/luasocket.c @@ -12,16 +12,6 @@ * standard Lua read and write functions. \*=========================================================================*/ -/*=========================================================================*\ -* Standard include files -\*=========================================================================*/ -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - -/*=========================================================================*\ -* LuaSocket includes -\*=========================================================================*/ #include "luasocket.h" #include "auxiliar.h" #include "except.h" diff --git a/src/luasocket.h b/src/luasocket.h index 0121a15..d22b1be 100644 --- a/src/luasocket.h +++ b/src/luasocket.h @@ -6,9 +6,8 @@ * Diego Nehab * 9/11/1999 \*=========================================================================*/ -#include "lua.h" -/*-------------------------------------------------------------------------*\ +/*-------------------------------------------------------------------------* \ * Current socket library version \*-------------------------------------------------------------------------*/ #define LUASOCKET_VERSION "LuaSocket 3.0-rc1" @@ -25,13 +24,9 @@ #endif #endif -#ifndef LUASOCKET_PRIVATE -#ifdef _WIN32 -#define LUASOCKET_PRIVATE -#else -#define LUASOCKET_PRIVATE __attribute__ ((visibility ("hidden"))) -#endif -#endif +#include "lua.h" +#include "lauxlib.h" +#include "compat.h" /*-------------------------------------------------------------------------*\ * Initializes the library. From 83648f8df2a6ec6d3061b2642ae8739da94eadbe Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:58:27 -0700 Subject: [PATCH 109/194] mime: include reorg --- src/mime.c | 8 ++------ src/mime.h | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/mime.c b/src/mime.c index 0e9863b..6c210e4 100755 --- a/src/mime.c +++ b/src/mime.c @@ -2,15 +2,11 @@ * MIME support functions * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" +#include "mime.h" #include #include -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - -#include "mime.h" - /*=========================================================================*\ * Don't want to trust escape character constants \*=========================================================================*/ diff --git a/src/mime.h b/src/mime.h index e57fc9c..4d938f4 100644 --- a/src/mime.h +++ b/src/mime.h @@ -9,7 +9,6 @@ * provide a higher level interface to this functionality. \*=========================================================================*/ #include "luasocket.h" -#include "lua.h" /*-------------------------------------------------------------------------*\ * Current MIME library version From ce6a08d57de42f8f2a78fd63b1b2bc90b3cc0156 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:58:46 -0700 Subject: [PATCH 110/194] options: pragma visibility --- src/options.c | 176 +++++++++++++++++++++++++++++--------------------- src/options.h | 134 +++++++++++++++++++++----------------- 2 files changed, 175 insertions(+), 135 deletions(-) diff --git a/src/options.c b/src/options.c index b0bacbf..06ab58d 100644 --- a/src/options.c +++ b/src/options.c @@ -3,7 +3,6 @@ * LuaSocket toolkit \*=========================================================================*/ #include "luasocket.h" -#include "lauxlib.h" #include "auxiliar.h" #include "options.h" #include "inet.h" @@ -29,7 +28,7 @@ static int opt_get(lua_State *L, p_socket ps, int level, int name, /*-------------------------------------------------------------------------*\ * Calls appropriate option handler \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps) +int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps) { const char *name = luaL_checkstring(L, 2); /* obj, name, ... */ while (opt->name && strcmp(name, opt->name)) @@ -42,7 +41,7 @@ LUASOCKET_PRIVATE int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps) return opt->func(L, ps); } -LUASOCKET_PRIVATE int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) +int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) { const char *name = luaL_checkstring(L, 2); /* obj, name, ... */ while (opt->name && strcmp(name, opt->name)) @@ -55,166 +54,188 @@ LUASOCKET_PRIVATE int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) return opt->func(L, ps); } +// ------------------------------------------------------- /* enables reuse of local address */ -LUASOCKET_PRIVATE int opt_set_reuseaddr(lua_State *L, p_socket ps) +int opt_set_reuseaddr(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); } -LUASOCKET_PRIVATE int opt_get_reuseaddr(lua_State *L, p_socket ps) +int opt_get_reuseaddr(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); } +// ------------------------------------------------------- /* enables reuse of local port */ -LUASOCKET_PRIVATE int opt_set_reuseport(lua_State *L, p_socket ps) +int opt_set_reuseport(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); } -LUASOCKET_PRIVATE int opt_get_reuseport(lua_State *L, p_socket ps) +int opt_get_reuseport(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); } -/* disables the Naggle algorithm */ -LUASOCKET_PRIVATE int opt_set_tcp_nodelay(lua_State *L, p_socket ps) +// ------------------------------------------------------- +/* disables the Nagle algorithm */ +int opt_set_tcp_nodelay(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); } -LUASOCKET_PRIVATE int opt_get_tcp_nodelay(lua_State *L, p_socket ps) +int opt_get_tcp_nodelay(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); } +// ------------------------------------------------------- #ifdef TCP_KEEPIDLE -LUASOCKET_PRIVATE int opt_get_tcp_keepidle(lua_State *L, p_socket ps) + +int opt_get_tcp_keepidle(lua_State *L, p_socket ps) { return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE); } -LUASOCKET_PRIVATE int opt_set_tcp_keepidle(lua_State *L, p_socket ps) +int opt_set_tcp_keepidle(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE); } + #endif +// ------------------------------------------------------- #ifdef TCP_KEEPCNT -LUASOCKET_PRIVATE int opt_get_tcp_keepcnt(lua_State *L, p_socket ps) + +int opt_get_tcp_keepcnt(lua_State *L, p_socket ps) { return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPCNT); } -LUASOCKET_PRIVATE int opt_set_tcp_keepcnt(lua_State *L, p_socket ps) +int opt_set_tcp_keepcnt(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPCNT); } + #endif +// ------------------------------------------------------- #ifdef TCP_KEEPINTVL -LUASOCKET_PRIVATE int opt_get_tcp_keepintvl(lua_State *L, p_socket ps) + +int opt_get_tcp_keepintvl(lua_State *L, p_socket ps) { return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL); } -LUASOCKET_PRIVATE int opt_set_tcp_keepintvl(lua_State *L, p_socket ps) +int opt_set_tcp_keepintvl(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL); } + #endif -LUASOCKET_PRIVATE int opt_set_keepalive(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_keepalive(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); } -LUASOCKET_PRIVATE int opt_get_keepalive(lua_State *L, p_socket ps) +int opt_get_keepalive(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); } -LUASOCKET_PRIVATE int opt_set_dontroute(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_dontroute(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE); } -LUASOCKET_PRIVATE int opt_get_dontroute(lua_State *L, p_socket ps) +int opt_get_dontroute(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, SOL_SOCKET, SO_DONTROUTE); } -LUASOCKET_PRIVATE int opt_set_broadcast(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_broadcast(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_BROADCAST); } -LUASOCKET_PRIVATE int opt_set_recv_buf_size(lua_State *L, p_socket ps) -{ - return opt_setint(L, ps, SOL_SOCKET, SO_RCVBUF); -} - -LUASOCKET_PRIVATE int opt_get_recv_buf_size(lua_State *L, p_socket ps) -{ - return opt_getint(L, ps, SOL_SOCKET, SO_RCVBUF); -} - -LUASOCKET_PRIVATE int opt_get_send_buf_size(lua_State *L, p_socket ps) -{ - return opt_getint(L, ps, SOL_SOCKET, SO_SNDBUF); -} - -LUASOCKET_PRIVATE int opt_set_send_buf_size(lua_State *L, p_socket ps) -{ - return opt_setint(L, ps, SOL_SOCKET, SO_SNDBUF); -} - -LUASOCKET_PRIVATE int opt_get_broadcast(lua_State *L, p_socket ps) +int opt_get_broadcast(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, SOL_SOCKET, SO_BROADCAST); } -LUASOCKET_PRIVATE int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_recv_buf_size(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, SOL_SOCKET, SO_RCVBUF); +} + +int opt_get_recv_buf_size(lua_State *L, p_socket ps) +{ + return opt_getint(L, ps, SOL_SOCKET, SO_RCVBUF); +} + +// ------------------------------------------------------- +int opt_get_send_buf_size(lua_State *L, p_socket ps) +{ + return opt_getint(L, ps, SOL_SOCKET, SO_SNDBUF); +} + +int opt_set_send_buf_size(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, SOL_SOCKET, SO_SNDBUF); +} + +// ------------------------------------------------------- +int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); } -LUASOCKET_PRIVATE int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps) +int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps) { return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); } -LUASOCKET_PRIVATE int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS); } -LUASOCKET_PRIVATE int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps) +int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps) { return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS); } -LUASOCKET_PRIVATE int opt_set_ip_multicast_loop(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_ip_multicast_loop(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP); } -LUASOCKET_PRIVATE int opt_get_ip_multicast_loop(lua_State *L, p_socket ps) +int opt_get_ip_multicast_loop(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP); } -LUASOCKET_PRIVATE int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP); } -LUASOCKET_PRIVATE int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps) +int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP); } -LUASOCKET_PRIVATE int opt_set_linger(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_linger(lua_State *L, p_socket ps) { struct linger li; /* obj, name, table */ if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE)); @@ -231,7 +252,7 @@ LUASOCKET_PRIVATE int opt_set_linger(lua_State *L, p_socket ps) return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li)); } -LUASOCKET_PRIVATE int opt_get_linger(lua_State *L, p_socket ps) +int opt_get_linger(lua_State *L, p_socket ps) { struct linger li; /* obj, name */ int len = sizeof(li); @@ -246,12 +267,14 @@ LUASOCKET_PRIVATE int opt_get_linger(lua_State *L, p_socket ps) return 1; } -LUASOCKET_PRIVATE int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IP, IP_MULTICAST_TTL); } -LUASOCKET_PRIVATE int opt_set_ip_multicast_if(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_ip_multicast_if(lua_State *L, p_socket ps) { const char *address = luaL_checkstring(L, 3); /* obj, name, ip */ struct in_addr val; @@ -262,7 +285,7 @@ LUASOCKET_PRIVATE int opt_set_ip_multicast_if(lua_State *L, p_socket ps) (char *) &val, sizeof(val)); } -LUASOCKET_PRIVATE int opt_get_ip_multicast_if(lua_State *L, p_socket ps) +int opt_get_ip_multicast_if(lua_State *L, p_socket ps) { struct in_addr val; socklen_t len = sizeof(val); @@ -275,36 +298,52 @@ LUASOCKET_PRIVATE int opt_get_ip_multicast_if(lua_State *L, p_socket ps) return 1; } -LUASOCKET_PRIVATE int opt_set_ip_add_membership(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_ip_add_membership(lua_State *L, p_socket ps) { return opt_setmembership(L, ps, IPPROTO_IP, IP_ADD_MEMBERSHIP); } -LUASOCKET_PRIVATE int opt_set_ip_drop_membersip(lua_State *L, p_socket ps) +int opt_set_ip_drop_membersip(lua_State *L, p_socket ps) { return opt_setmembership(L, ps, IPPROTO_IP, IP_DROP_MEMBERSHIP); } -LUASOCKET_PRIVATE int opt_set_ip6_add_membership(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_set_ip6_add_membership(lua_State *L, p_socket ps) { return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP); } -LUASOCKET_PRIVATE int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps) +int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps) { return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP); } - -LUASOCKET_PRIVATE int opt_get_ip6_v6only(lua_State *L, p_socket ps) +// ------------------------------------------------------- +int opt_get_ip6_v6only(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); } -LUASOCKET_PRIVATE int opt_set_ip6_v6only(lua_State *L, p_socket ps) +int opt_set_ip6_v6only(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); } +// ------------------------------------------------------- +int opt_get_error(lua_State *L, p_socket ps) +{ + int val = 0; + socklen_t len = sizeof(val); + if (getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *) &val, &len) < 0) { + lua_pushnil(L); + lua_pushstring(L, "getsockopt failed"); + return 2; + } + lua_pushstring(L, socket_strerror(val)); + return 1; +} + /*=========================================================================*\ * Auxiliar functions \*=========================================================================*/ @@ -391,19 +430,6 @@ static int opt_getboolean(lua_State *L, p_socket ps, int level, int name) return 1; } -LUASOCKET_PRIVATE int opt_get_error(lua_State *L, p_socket ps) -{ - int val = 0; - socklen_t len = sizeof(val); - if (getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *) &val, &len) < 0) { - lua_pushnil(L); - lua_pushstring(L, "getsockopt failed"); - return 2; - } - lua_pushstring(L, socket_strerror(val)); - return 1; -} - static int opt_setboolean(lua_State *L, p_socket ps, int level, int name) { int val = auxiliar_checkboolean(L, 3); /* obj, name, bool */ diff --git a/src/options.h b/src/options.h index fb82c4d..1457f43 100644 --- a/src/options.h +++ b/src/options.h @@ -8,7 +8,7 @@ * modules UDP and TCP. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" #include "socket.h" /* option registry */ @@ -18,67 +18,81 @@ typedef struct t_opt { } t_opt; typedef t_opt *p_opt; -/* supported options for setoption */ -int opt_set_dontroute(lua_State *L, p_socket ps); -int opt_set_broadcast(lua_State *L, p_socket ps); -int opt_set_tcp_nodelay(lua_State *L, p_socket ps); -#ifdef TCP_KEEPIDLE -int opt_set_tcp_keepidle(lua_State *L, p_socket ps); -#endif -#ifdef TCP_KEEPCNT -int opt_set_tcp_keepcnt(lua_State *L, p_socket ps); -#endif -#ifdef TCP_KEEPINTVL -int opt_set_tcp_keepintvl(lua_State *L, p_socket ps); -#endif -int opt_set_keepalive(lua_State *L, p_socket ps); -int opt_set_linger(lua_State *L, p_socket ps); -int opt_set_reuseaddr(lua_State *L, p_socket ps); -int opt_set_reuseport(lua_State *L, p_socket ps); -int opt_set_ip_multicast_if(lua_State *L, p_socket ps); -int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps); -int opt_set_ip_multicast_loop(lua_State *L, p_socket ps); -int opt_set_ip_add_membership(lua_State *L, p_socket ps); -int opt_set_ip_drop_membersip(lua_State *L, p_socket ps); -int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps); -int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps); -int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps); -int opt_set_ip6_add_membership(lua_State *L, p_socket ps); -int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps); -int opt_set_ip6_v6only(lua_State *L, p_socket ps); -int opt_set_recv_buf_size(lua_State *L, p_socket ps); -int opt_set_send_buf_size(lua_State *L, p_socket ps); +#pragma GCC visibility push(hidden) -/* supported options for getoption */ -int opt_get_dontroute(lua_State *L, p_socket ps); -int opt_get_broadcast(lua_State *L, p_socket ps); -int opt_get_reuseaddr(lua_State *L, p_socket ps); -int opt_get_reuseport(lua_State *L, p_socket ps); -int opt_get_tcp_nodelay(lua_State *L, p_socket ps); -#ifdef TCP_KEEPIDLE -int opt_get_tcp_keepidle(lua_State *L, p_socket ps); -#endif -#ifdef TCP_KEEPCNT -int opt_get_tcp_keepcnt(lua_State *L, p_socket ps); -#endif -#ifdef TCP_KEEPINTVL -int opt_get_tcp_keepintvl(lua_State *L, p_socket ps); -#endif -int opt_get_keepalive(lua_State *L, p_socket ps); -int opt_get_linger(lua_State *L, p_socket ps); -int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); -int opt_get_ip_multicast_if(lua_State *L, p_socket ps); -int opt_get_error(lua_State *L, p_socket ps); -int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps); -int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps); -int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps); -int opt_get_ip6_v6only(lua_State *L, p_socket ps); -int opt_get_reuseport(lua_State *L, p_socket ps); -int opt_get_recv_buf_size(lua_State *L, p_socket ps); -int opt_get_send_buf_size(lua_State *L, p_socket ps); - -/* invokes the appropriate option handler */ int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps); +int opt_set_reuseaddr(lua_State *L, p_socket ps); +int opt_get_reuseaddr(lua_State *L, p_socket ps); + +int opt_set_reuseport(lua_State *L, p_socket ps); +int opt_get_reuseport(lua_State *L, p_socket ps); + +int opt_set_tcp_nodelay(lua_State *L, p_socket ps); +int opt_get_tcp_nodelay(lua_State *L, p_socket ps); + +#ifdef TCP_KEEPIDLE +int opt_set_tcp_keepidle(lua_State *L, p_socket ps); +int opt_get_tcp_keepidle(lua_State *L, p_socket ps); +#endif + +#ifdef TCP_KEEPCNT +int opt_set_tcp_keepcnt(lua_State *L, p_socket ps); +int opt_get_tcp_keepcnt(lua_State *L, p_socket ps); +#endif + +#ifdef TCP_KEEPINTVL +int opt_set_tcp_keepintvl(lua_State *L, p_socket ps); +int opt_get_tcp_keepintvl(lua_State *L, p_socket ps); +#endif + +int opt_set_keepalive(lua_State *L, p_socket ps); +int opt_get_keepalive(lua_State *L, p_socket ps); + +int opt_set_dontroute(lua_State *L, p_socket ps); +int opt_get_dontroute(lua_State *L, p_socket ps); + +int opt_set_broadcast(lua_State *L, p_socket ps); +int opt_get_broadcast(lua_State *L, p_socket ps); + +int opt_set_recv_buf_size(lua_State *L, p_socket ps); +int opt_get_recv_buf_size(lua_State *L, p_socket ps); + +int opt_set_send_buf_size(lua_State *L, p_socket ps); +int opt_get_send_buf_size(lua_State *L, p_socket ps); + +int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps); +int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps); + +int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps); +int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps); + +int opt_set_ip_multicast_loop(lua_State *L, p_socket ps); +int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); + +int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps); +int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps); + +int opt_set_linger(lua_State *L, p_socket ps); +int opt_get_linger(lua_State *L, p_socket ps); + +int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps); + +int opt_set_ip_multicast_if(lua_State *L, p_socket ps); +int opt_get_ip_multicast_if(lua_State *L, p_socket ps); + +int opt_set_ip_add_membership(lua_State *L, p_socket ps); +int opt_set_ip_drop_membersip(lua_State *L, p_socket ps); + +int opt_set_ip6_add_membership(lua_State *L, p_socket ps); +int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps); + +int opt_set_ip6_v6only(lua_State *L, p_socket ps); +int opt_get_ip6_v6only(lua_State *L, p_socket ps); + +int opt_get_error(lua_State *L, p_socket ps); + +#pragma GCC visibility pop + #endif From c2245f35c500b44bde6295f3f47cffd1c7b7e260 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:59:01 -0700 Subject: [PATCH 111/194] select: pragma visibility --- src/select.c | 10 +--------- src/select.h | 4 ++++ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/select.c b/src/select.c index b615b19..bb47c45 100644 --- a/src/select.c +++ b/src/select.c @@ -4,10 +4,6 @@ \*=========================================================================*/ #include "luasocket.h" -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - #include "socket.h" #include "timeout.h" #include "select.h" @@ -33,13 +29,10 @@ static luaL_Reg func[] = { {NULL, NULL} }; -/*=========================================================================*\ -* Exported functions -\*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int select_open(lua_State *L) { +int select_open(lua_State *L) { lua_pushstring(L, "_SETSIZE"); lua_pushinteger(L, FD_SETSIZE); lua_rawset(L, -3); @@ -219,4 +212,3 @@ static void make_assoc(lua_State *L, int tab) { i = i+1; } } - diff --git a/src/select.h b/src/select.h index 8750200..95272db 100644 --- a/src/select.h +++ b/src/select.h @@ -10,6 +10,10 @@ * true if there is data ready for reading (required for buffered input). \*=========================================================================*/ +#pragma GCC visibility push(hidden) + int select_open(lua_State *L); +#pragma GCC visibility pop + #endif /* SELECT_H */ From c8b9b40eda1325929ce8fae31564e9b29957167c Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:00:38 -0700 Subject: [PATCH 112/194] serial.c: pragma visibiliity --- src/serial.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/serial.c b/src/serial.c index cb46edb..21485d3 100644 --- a/src/serial.c +++ b/src/serial.c @@ -4,15 +4,12 @@ \*=========================================================================*/ #include "luasocket.h" -#include - -#include "lua.h" -#include "lauxlib.h" - #include "auxiliar.h" #include "socket.h" #include "options.h" #include "unix.h" + +#include #include /* From 1fa10673f717a08f9ef51ff9357adf7b8458f9a5 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:00:54 -0700 Subject: [PATCH 113/194] socket.h: pragma visibility --- src/socket.h | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/socket.h b/src/socket.h index 63573de..4adc562 100644 --- a/src/socket.h +++ b/src/socket.h @@ -28,51 +28,42 @@ \*=========================================================================*/ #include "timeout.h" -/* we are lazy... */ +/* convenient shorthand */ typedef struct sockaddr SA; /*=========================================================================*\ * Functions bellow implement a comfortable platform independent * interface to sockets \*=========================================================================*/ + +#pragma GCC visibility push(hidden) + +int socket_waitfd(p_socket ps, int sw, p_timeout tm); int socket_open(void); int socket_close(void); void socket_destroy(p_socket ps); -void socket_shutdown(p_socket ps, int how); -int socket_sendto(p_socket ps, const char *data, size_t count, - size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm); -int socket_recvfrom(p_socket ps, char *data, size_t count, - size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm); - -void socket_setnonblocking(p_socket ps); -void socket_setblocking(p_socket ps); - -int socket_waitfd(p_socket ps, int sw, p_timeout tm); -int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, - p_timeout tm); - -int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); +int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm); int socket_create(p_socket ps, int domain, int type, int protocol); int socket_bind(p_socket ps, SA *addr, socklen_t addr_len); int socket_listen(p_socket ps, int backlog); -int socket_accept(p_socket ps, p_socket pa, SA *addr, - socklen_t *addr_len, p_timeout tm); - -const char *socket_hoststrerror(int err); -const char *socket_gaistrerror(int err); -const char *socket_strerror(int err); - -/* these are perfect to use with the io abstraction module - and the buffered input module */ -int socket_send(p_socket ps, const char *data, size_t count, - size_t *sent, p_timeout tm); +void socket_shutdown(p_socket ps, int how); +int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); +int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *addr_len, p_timeout tm); +int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm); +int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm); int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); -int socket_write(p_socket ps, const char *data, size_t count, - size_t *sent, p_timeout tm); +int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm); +int socket_write(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm); int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); -const char *socket_ioerror(p_socket ps, int err); - +void socket_setblocking(p_socket ps); +void socket_setnonblocking(p_socket ps); int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp); int socket_gethostbyname(const char *addr, struct hostent **hp); +const char *socket_hoststrerror(int err); +const char *socket_strerror(int err); +const char *socket_ioerror(p_socket ps, int err); +const char *socket_gaistrerror(int err); + +#pragma GCC visibility pop #endif /* SOCKET_H */ From 86e1b3f45f57358d6b2a6666043df9a4a2f963c5 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:01:06 -0700 Subject: [PATCH 114/194] tcp: pragma visibility --- src/tcp.c | 7 +------ src/tcp.h | 6 +++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/tcp.c b/src/tcp.c index cc5b6a7..5876bfb 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -4,12 +4,7 @@ \*=========================================================================*/ #include "luasocket.h" -#include "lua.h" -#include "lauxlib.h" - -#include "compat.h" #include "auxiliar.h" - #include "socket.h" #include "inet.h" #include "options.h" @@ -129,7 +124,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int tcp_open(lua_State *L) +int tcp_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "tcp{master}", tcp_methods); diff --git a/src/tcp.h b/src/tcp.h index eded620..9b12b53 100644 --- a/src/tcp.h +++ b/src/tcp.h @@ -14,7 +14,7 @@ * tcp objects either connected to some address or returned by the accept * method of a server object. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" #include "buffer.h" #include "timeout.h" @@ -30,6 +30,10 @@ typedef struct t_tcp_ { typedef t_tcp *p_tcp; +#pragma GCC visibility push(hidden) + int tcp_open(lua_State *L); +#pragma GCC visibility pop + #endif /* TCP_H */ From 42a1a732b79fa6153c61da645b786da883bbd0b5 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:01:16 -0700 Subject: [PATCH 115/194] timeout: pragma visibility --- src/timeout.c | 36 ++++++++++++++++++++---------------- src/timeout.h | 13 ++++++++++--- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/timeout.c b/src/timeout.c index 8fb8f55..0e3ee27 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -4,10 +4,6 @@ \*=========================================================================*/ #include "luasocket.h" -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - #include "auxiliar.h" #include "timeout.h" @@ -30,6 +26,10 @@ #define MAX(x, y) ((x) > (y) ? x : y) #endif +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + /*=========================================================================*\ * Internal function prototypes \*=========================================================================*/ @@ -48,7 +48,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initialize structure \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void timeout_init(p_timeout tm, double block, double total) { +void timeout_init(p_timeout tm, double block, double total) { tm->block = block; tm->total = total; } @@ -61,7 +61,7 @@ LUASOCKET_PRIVATE void timeout_init(p_timeout tm, double block, double total) { * Returns * the number of ms left or -1 if there is no time limit \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE double timeout_get(p_timeout tm) { +double timeout_get(p_timeout tm) { if (tm->block < 0.0 && tm->total < 0.0) { return -1; } else if (tm->block < 0.0) { @@ -82,7 +82,7 @@ LUASOCKET_PRIVATE double timeout_get(p_timeout tm) { * Returns * start field of structure \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE double timeout_getstart(p_timeout tm) { +double timeout_getstart(p_timeout tm) { return tm->start; } @@ -94,7 +94,7 @@ LUASOCKET_PRIVATE double timeout_getstart(p_timeout tm) { * Returns * the number of ms left or -1 if there is no time limit \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE double timeout_getretry(p_timeout tm) { +double timeout_getretry(p_timeout tm) { if (tm->block < 0.0 && tm->total < 0.0) { return -1; } else if (tm->block < 0.0) { @@ -114,7 +114,7 @@ LUASOCKET_PRIVATE double timeout_getretry(p_timeout tm) { * Input * tm: timeout control structure \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE p_timeout timeout_markstart(p_timeout tm) { +p_timeout timeout_markstart(p_timeout tm) { tm->start = timeout_gettime(); return tm; } @@ -125,7 +125,7 @@ LUASOCKET_PRIVATE p_timeout timeout_markstart(p_timeout tm) { * time in s. \*-------------------------------------------------------------------------*/ #ifdef _WIN32 -LUASOCKET_PRIVATE double timeout_gettime(void) { +double timeout_gettime(void) { FILETIME ft; double t; GetSystemTimeAsFileTime(&ft); @@ -135,7 +135,7 @@ LUASOCKET_PRIVATE double timeout_gettime(void) { return (t - 11644473600.0); } #else -LUASOCKET_PRIVATE double timeout_gettime(void) { +double timeout_gettime(void) { struct timeval v; gettimeofday(&v, (struct timezone *) NULL); /* Unix Epoch time (time since January 1, 1970 (UTC)) */ @@ -146,7 +146,7 @@ LUASOCKET_PRIVATE double timeout_gettime(void) { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int timeout_open(lua_State *L) { +int timeout_open(lua_State *L) { luaL_setfuncs(L, func, 0); return 0; } @@ -157,7 +157,7 @@ LUASOCKET_PRIVATE int timeout_open(lua_State *L) { * time: time out value in seconds * mode: "b" for block timeout, "t" for total timeout. (default: b) \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int timeout_meth_settimeout(lua_State *L, p_timeout tm) { +int timeout_meth_settimeout(lua_State *L, p_timeout tm) { double t = luaL_optnumber(L, 2, -1); const char *mode = luaL_optstring(L, 3, "b"); switch (*mode) { @@ -179,7 +179,7 @@ LUASOCKET_PRIVATE int timeout_meth_settimeout(lua_State *L, p_timeout tm) { * Gets timeout values for IO operations * Lua Output: block, total \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { +int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { lua_pushnumber(L, tm->block); lua_pushnumber(L, tm->total); return 2; @@ -201,7 +201,7 @@ static int timeout_lua_gettime(lua_State *L) * Sleep for n seconds. \*-------------------------------------------------------------------------*/ #ifdef _WIN32 -LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) +int timeout_lua_sleep(lua_State *L) { double n = luaL_checknumber(L, 1); if (n < 0.0) n = 0.0; @@ -211,7 +211,7 @@ LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) return 0; } #else -LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) +int timeout_lua_sleep(lua_State *L) { double n = luaL_checknumber(L, 1); struct timespec t, r; @@ -228,3 +228,7 @@ LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) return 0; } #endif + +#ifndef _WIN32 +#pragma GCC visibility pop +#endif diff --git a/src/timeout.h b/src/timeout.h index af90231..df05eaf 100644 --- a/src/timeout.h +++ b/src/timeout.h @@ -4,7 +4,7 @@ * Timeout management functions * LuaSocket toolkit \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" /* timeout control structure */ typedef struct t_timeout_ { @@ -14,16 +14,23 @@ typedef struct t_timeout_ { } t_timeout; typedef t_timeout *p_timeout; -int timeout_open(lua_State *L); +#pragma GCC visibility push(hidden) + void timeout_init(p_timeout tm, double block, double total); double timeout_get(p_timeout tm); +double timeout_getstart(p_timeout tm); double timeout_getretry(p_timeout tm); p_timeout timeout_markstart(p_timeout tm); -double timeout_getstart(p_timeout tm); + double timeout_gettime(void); + +int timeout_open(lua_State *L); + int timeout_meth_settimeout(lua_State *L, p_timeout tm); int timeout_meth_gettimeout(lua_State *L, p_timeout tm); +#pragma GCC visibility pop + #define timeout_iszero(tm) ((tm)->block == 0.0) #endif /* TIMEOUT_H */ From d71e6bc459ecb21f0cffc874c29176b762ecbd93 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:01:25 -0700 Subject: [PATCH 116/194] udp: pragma visibility --- src/udp.c | 6 +----- src/udp.h | 6 +++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/udp.c b/src/udp.c index e59fa1b..62b6a20 100644 --- a/src/udp.c +++ b/src/udp.c @@ -4,10 +4,6 @@ \*=========================================================================*/ #include "luasocket.h" -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - #include "auxiliar.h" #include "socket.h" #include "inet.h" @@ -124,7 +120,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int udp_open(lua_State *L) { +int udp_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "udp{connected}", udp_methods); auxiliar_newclass(L, "udp{unconnected}", udp_methods); diff --git a/src/udp.h b/src/udp.h index be9b6a5..9e80ccd 100644 --- a/src/udp.h +++ b/src/udp.h @@ -12,7 +12,7 @@ * with a call to the setpeername function. The same function can be used to * break the connection. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" #include "timeout.h" #include "socket.h" @@ -26,6 +26,10 @@ typedef struct t_udp_ { } t_udp; typedef t_udp *p_udp; +#pragma GCC visibility push(hidden) + int udp_open(lua_State *L); +#pragma GCC visibility pop + #endif /* UDP_H */ From 5d07d9b2275fba742a297acde76636f6054a7906 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:01:46 -0700 Subject: [PATCH 117/194] unix: include reorg --- src/unix.c | 3 --- src/unix.h | 1 - 2 files changed, 4 deletions(-) diff --git a/src/unix.c b/src/unix.c index c618a20..268d8b2 100644 --- a/src/unix.c +++ b/src/unix.c @@ -4,9 +4,6 @@ \*=========================================================================*/ #include "luasocket.h" -#include "lua.h" -#include "lauxlib.h" - #include "unixstream.h" #include "unixdgram.h" diff --git a/src/unix.h b/src/unix.h index a1674ef..c203561 100644 --- a/src/unix.h +++ b/src/unix.h @@ -8,7 +8,6 @@ * domain. \*=========================================================================*/ #include "luasocket.h" -#include "lua.h" #include "buffer.h" #include "timeout.h" From d27b1a79453dbafe122ca8aa59413a7cb8750c8d Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:02:01 -0700 Subject: [PATCH 118/194] unixdgram: pragma visibility --- src/unixdgram.c | 7 ++----- src/unixdgram.h | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/unixdgram.c b/src/unixdgram.c index 840257a..3ac3c5e 100644 --- a/src/unixdgram.c +++ b/src/unixdgram.c @@ -4,10 +4,6 @@ \*=========================================================================*/ #include "luasocket.h" -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - #include "auxiliar.h" #include "socket.h" #include "options.h" @@ -26,6 +22,7 @@ ((size_t) (((struct sockaddr_un *) 0)->sun_path) \ + strlen ((ptr)->sun_path)) #endif + /*=========================================================================*\ * Internal function prototypes \*=========================================================================*/ @@ -86,7 +83,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int unixdgram_open(lua_State *L) +int unixdgram_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "unixdgram{connected}", unixdgram_methods); diff --git a/src/unixdgram.h b/src/unixdgram.h index 7187966..433fe25 100644 --- a/src/unixdgram.h +++ b/src/unixdgram.h @@ -15,6 +15,10 @@ #include "unix.h" +#pragma GCC visibility push(hidden) + int unixdgram_open(lua_State *L); +#pragma GCC visibility pop + #endif /* UNIXDGRAM_H */ From 4e363330a3b9e6ba082869f87820690e501f0a2d Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:02:13 -0700 Subject: [PATCH 119/194] unixstream: pragma visibility --- src/unixstream.c | 6 +----- src/unixstream.h | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/unixstream.c b/src/unixstream.c index ce2d3af..02aced9 100644 --- a/src/unixstream.c +++ b/src/unixstream.c @@ -4,10 +4,6 @@ \*=========================================================================*/ #include "luasocket.h" -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - #include "auxiliar.h" #include "socket.h" #include "options.h" @@ -82,7 +78,7 @@ static luaL_Reg func[] = { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int unixstream_open(lua_State *L) +int unixstream_open(lua_State *L) { /* create classes */ auxiliar_newclass(L, "unixstream{master}", unixstream_methods); diff --git a/src/unixstream.h b/src/unixstream.h index ef1d071..8ffba8f 100644 --- a/src/unixstream.h +++ b/src/unixstream.h @@ -16,6 +16,10 @@ \*=========================================================================*/ #include "unix.h" +#pragma GCC visibility push(hidden) + int unixstream_open(lua_State *L); +#pragma GCC visibility pop + #endif /* UNIXSTREAM_H */ From 8b2dcdcf7d98194e9d501c0a76a048606761983f Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:02:24 -0700 Subject: [PATCH 120/194] usocket: pragma visibility --- src/usocket.c | 53 ++++++++++++++++++++++++------------------------- src/wsocket.c | 55 +++++++++++++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 51 deletions(-) diff --git a/src/usocket.c b/src/usocket.c index aee876d..acfe186 100644 --- a/src/usocket.c +++ b/src/usocket.c @@ -23,7 +23,7 @@ #define WAITFD_R POLLIN #define WAITFD_W POLLOUT #define WAITFD_C (POLLIN|POLLOUT) -LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) { +int socket_waitfd(p_socket ps, int sw, p_timeout tm) { int ret; struct pollfd pfd; pfd.fd = *ps; @@ -45,7 +45,7 @@ LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) { #define WAITFD_W 2 #define WAITFD_C (WAITFD_R|WAITFD_W) -LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) { +int socket_waitfd(p_socket ps, int sw, p_timeout tm) { int ret; fd_set rfds, wfds, *rp, *wp; struct timeval tv, *tp; @@ -77,7 +77,7 @@ LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) { /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_open(void) { +int socket_open(void) { /* installs a handler to ignore sigpipe or it will crash us */ signal(SIGPIPE, SIG_IGN); return 1; @@ -86,14 +86,14 @@ LUASOCKET_PRIVATE int socket_open(void) { /*-------------------------------------------------------------------------*\ * Close module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_close(void) { +int socket_close(void) { return 1; } /*-------------------------------------------------------------------------*\ * Close and inutilize socket \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void socket_destroy(p_socket ps) { +void socket_destroy(p_socket ps) { if (*ps != SOCKET_INVALID) { close(*ps); *ps = SOCKET_INVALID; @@ -103,7 +103,7 @@ LUASOCKET_PRIVATE void socket_destroy(p_socket ps) { /*-------------------------------------------------------------------------*\ * Select with timeout control \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, +int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm) { int ret; do { @@ -120,7 +120,7 @@ LUASOCKET_PRIVATE int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_s /*-------------------------------------------------------------------------*\ * Creates and sets up a socket \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_create(p_socket ps, int domain, int type, int protocol) { +int socket_create(p_socket ps, int domain, int type, int protocol) { *ps = socket(domain, type, protocol); if (*ps != SOCKET_INVALID) return IO_DONE; else return errno; @@ -129,7 +129,7 @@ LUASOCKET_PRIVATE int socket_create(p_socket ps, int domain, int type, int proto /*-------------------------------------------------------------------------*\ * Binds or returns error message \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_bind(p_socket ps, SA *addr, socklen_t len) { +int socket_bind(p_socket ps, SA *addr, socklen_t len) { int err = IO_DONE; socket_setblocking(ps); if (bind(*ps, addr, len) < 0) err = errno; @@ -140,7 +140,7 @@ LUASOCKET_PRIVATE int socket_bind(p_socket ps, SA *addr, socklen_t len) { /*-------------------------------------------------------------------------*\ * \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_listen(p_socket ps, int backlog) { +int socket_listen(p_socket ps, int backlog) { int err = IO_DONE; if (listen(*ps, backlog)) err = errno; return err; @@ -149,14 +149,14 @@ LUASOCKET_PRIVATE int socket_listen(p_socket ps, int backlog) { /*-------------------------------------------------------------------------*\ * \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void socket_shutdown(p_socket ps, int how) { +void socket_shutdown(p_socket ps, int how) { shutdown(*ps, how); } /*-------------------------------------------------------------------------*\ * Connects or returns error message \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { +int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { int err; /* avoid calling on closed sockets */ if (*ps == SOCKET_INVALID) return IO_CLOSED; @@ -178,7 +178,7 @@ LUASOCKET_PRIVATE int socket_connect(p_socket ps, SA *addr, socklen_t len, p_tim /*-------------------------------------------------------------------------*\ * Accept with timeout \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout tm) { +int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout tm) { if (*ps == SOCKET_INVALID) return IO_CLOSED; for ( ;; ) { int err; @@ -195,7 +195,7 @@ LUASOCKET_PRIVATE int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_ /*-------------------------------------------------------------------------*\ * Send with timeout \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_send(p_socket ps, const char *data, size_t count, +int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm) { int err; @@ -229,7 +229,7 @@ LUASOCKET_PRIVATE int socket_send(p_socket ps, const char *data, size_t count, /*-------------------------------------------------------------------------*\ * Sendto with timeout \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, +int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t len, p_timeout tm) { int err; @@ -254,7 +254,7 @@ LUASOCKET_PRIVATE int socket_sendto(p_socket ps, const char *data, size_t count, /*-------------------------------------------------------------------------*\ * Receive with timeout \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { +int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { int err; *got = 0; if (*ps == SOCKET_INVALID) return IO_CLOSED; @@ -276,7 +276,7 @@ LUASOCKET_PRIVATE int socket_recv(p_socket ps, char *data, size_t count, size_t /*-------------------------------------------------------------------------*\ * Recvfrom with timeout \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, +int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *len, p_timeout tm) { int err; *got = 0; @@ -304,7 +304,7 @@ LUASOCKET_PRIVATE int socket_recvfrom(p_socket ps, char *data, size_t count, siz * with send/recv replaced with write/read. We can't just use write/read * in the socket version, because behaviour when size is zero is different. \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_write(p_socket ps, const char *data, size_t count, +int socket_write(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm) { int err; @@ -339,7 +339,7 @@ LUASOCKET_PRIVATE int socket_write(p_socket ps, const char *data, size_t count, * Read with timeout * See note for socket_write \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { +int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { int err; *got = 0; if (*ps == SOCKET_INVALID) return IO_CLOSED; @@ -361,7 +361,7 @@ LUASOCKET_PRIVATE int socket_read(p_socket ps, char *data, size_t count, size_t /*-------------------------------------------------------------------------*\ * Put socket into blocking mode \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void socket_setblocking(p_socket ps) { +void socket_setblocking(p_socket ps) { int flags = fcntl(*ps, F_GETFL, 0); flags &= (~(O_NONBLOCK)); fcntl(*ps, F_SETFL, flags); @@ -370,7 +370,7 @@ LUASOCKET_PRIVATE void socket_setblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * Put socket into non-blocking mode \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void socket_setnonblocking(p_socket ps) { +void socket_setnonblocking(p_socket ps) { int flags = fcntl(*ps, F_GETFL, 0); flags |= O_NONBLOCK; fcntl(*ps, F_SETFL, flags); @@ -379,7 +379,7 @@ LUASOCKET_PRIVATE void socket_setnonblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * DNS helpers \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) { +int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) { *hp = gethostbyaddr(addr, len, AF_INET); if (*hp) return IO_DONE; else if (h_errno) return h_errno; @@ -387,7 +387,7 @@ LUASOCKET_PRIVATE int socket_gethostbyaddr(const char *addr, socklen_t len, stru else return IO_UNKNOWN; } -LUASOCKET_PRIVATE int socket_gethostbyname(const char *addr, struct hostent **hp) { +int socket_gethostbyname(const char *addr, struct hostent **hp) { *hp = gethostbyname(addr); if (*hp) return IO_DONE; else if (h_errno) return h_errno; @@ -399,7 +399,7 @@ LUASOCKET_PRIVATE int socket_gethostbyname(const char *addr, struct hostent **hp * Error translation functions * Make sure important error messages are standard \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE const char *socket_hoststrerror(int err) { +const char *socket_hoststrerror(int err) { if (err <= 0) return io_strerror(err); switch (err) { case HOST_NOT_FOUND: return PIE_HOST_NOT_FOUND; @@ -407,7 +407,7 @@ LUASOCKET_PRIVATE const char *socket_hoststrerror(int err) { } } -LUASOCKET_PRIVATE const char *socket_strerror(int err) { +const char *socket_strerror(int err) { if (err <= 0) return io_strerror(err); switch (err) { case EADDRINUSE: return PIE_ADDRINUSE; @@ -423,12 +423,12 @@ LUASOCKET_PRIVATE const char *socket_strerror(int err) { } } -LUASOCKET_PRIVATE const char *socket_ioerror(p_socket ps, int err) { +const char *socket_ioerror(p_socket ps, int err) { (void) ps; return socket_strerror(err); } -LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) { +const char *socket_gaistrerror(int err) { if (err == 0) return NULL; switch (err) { case EAI_AGAIN: return PIE_AGAIN; @@ -452,4 +452,3 @@ LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) { default: return gai_strerror(err); } } - diff --git a/src/wsocket.c b/src/wsocket.c index c281058..1da984c 100755 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -12,13 +12,17 @@ #include "socket.h" #include "pierror.h" +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + /* WinSock doesn't have a strerror... */ static const char *wstrerror(int err); /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_open(void) { +int socket_open(void) { WSADATA wsaData; WORD wVersionRequested = MAKEWORD(2, 0); int err = WSAStartup(wVersionRequested, &wsaData ); @@ -34,7 +38,7 @@ LUASOCKET_PRIVATE int socket_open(void) { /*-------------------------------------------------------------------------*\ * Close module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_close(void) { +int socket_close(void) { WSACleanup(); return 1; } @@ -47,7 +51,7 @@ LUASOCKET_PRIVATE int socket_close(void) { #define WAITFD_E 4 #define WAITFD_C (WAITFD_E|WAITFD_W) -LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) { +int socket_waitfd(p_socket ps, int sw, p_timeout tm) { int ret; fd_set rfds, wfds, efds, *rp = NULL, *wp = NULL, *ep = NULL; struct timeval tv, *tp = NULL; @@ -75,7 +79,7 @@ LUASOCKET_PRIVATE int socket_waitfd(p_socket ps, int sw, p_timeout tm) { /*-------------------------------------------------------------------------*\ * Select with int timeout in ms \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, +int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm) { struct timeval tv; double t = timeout_get(tm); @@ -90,7 +94,7 @@ LUASOCKET_PRIVATE int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_s /*-------------------------------------------------------------------------*\ * Close and inutilize socket \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void socket_destroy(p_socket ps) { +void socket_destroy(p_socket ps) { if (*ps != SOCKET_INVALID) { socket_setblocking(ps); /* close can take a long time on WIN32 */ closesocket(*ps); @@ -101,7 +105,7 @@ LUASOCKET_PRIVATE void socket_destroy(p_socket ps) { /*-------------------------------------------------------------------------*\ * \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void socket_shutdown(p_socket ps, int how) { +void socket_shutdown(p_socket ps, int how) { socket_setblocking(ps); shutdown(*ps, how); socket_setnonblocking(ps); @@ -110,7 +114,7 @@ LUASOCKET_PRIVATE void socket_shutdown(p_socket ps, int how) { /*-------------------------------------------------------------------------*\ * Creates and sets up a socket \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_create(p_socket ps, int domain, int type, int protocol) { +int socket_create(p_socket ps, int domain, int type, int protocol) { *ps = socket(domain, type, protocol); if (*ps != SOCKET_INVALID) return IO_DONE; else return WSAGetLastError(); @@ -119,7 +123,7 @@ LUASOCKET_PRIVATE int socket_create(p_socket ps, int domain, int type, int proto /*-------------------------------------------------------------------------*\ * Connects or returns error message \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { +int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { int err; /* don't call on closed socket */ if (*ps == SOCKET_INVALID) return IO_CLOSED; @@ -148,7 +152,7 @@ LUASOCKET_PRIVATE int socket_connect(p_socket ps, SA *addr, socklen_t len, p_tim /*-------------------------------------------------------------------------*\ * Binds or returns error message \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_bind(p_socket ps, SA *addr, socklen_t len) { +int socket_bind(p_socket ps, SA *addr, socklen_t len) { int err = IO_DONE; socket_setblocking(ps); if (bind(*ps, addr, len) < 0) err = WSAGetLastError(); @@ -159,7 +163,7 @@ LUASOCKET_PRIVATE int socket_bind(p_socket ps, SA *addr, socklen_t len) { /*-------------------------------------------------------------------------*\ * \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_listen(p_socket ps, int backlog) { +int socket_listen(p_socket ps, int backlog) { int err = IO_DONE; socket_setblocking(ps); if (listen(*ps, backlog) < 0) err = WSAGetLastError(); @@ -170,7 +174,7 @@ LUASOCKET_PRIVATE int socket_listen(p_socket ps, int backlog) { /*-------------------------------------------------------------------------*\ * Accept with timeout \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, +int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout tm) { if (*ps == SOCKET_INVALID) return IO_CLOSED; for ( ;; ) { @@ -192,7 +196,7 @@ LUASOCKET_PRIVATE int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_ * this can take an awful lot of time and we will end up blocked. * Therefore, whoever calls this function should not pass a huge buffer. \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_send(p_socket ps, const char *data, size_t count, +int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm) { int err; @@ -220,7 +224,7 @@ LUASOCKET_PRIVATE int socket_send(p_socket ps, const char *data, size_t count, /*-------------------------------------------------------------------------*\ * Sendto with timeout \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, +int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t len, p_timeout tm) { int err; @@ -241,7 +245,7 @@ LUASOCKET_PRIVATE int socket_sendto(p_socket ps, const char *data, size_t count, /*-------------------------------------------------------------------------*\ * Receive with timeout \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_recv(p_socket ps, char *data, size_t count, size_t *got, +int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { int err, prev = IO_DONE; @@ -270,7 +274,7 @@ LUASOCKET_PRIVATE int socket_recv(p_socket ps, char *data, size_t count, size_t /*-------------------------------------------------------------------------*\ * Recvfrom with timeout \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, +int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *len, p_timeout tm) { int err, prev = IO_DONE; @@ -299,7 +303,7 @@ LUASOCKET_PRIVATE int socket_recvfrom(p_socket ps, char *data, size_t count, siz /*-------------------------------------------------------------------------*\ * Put socket into blocking mode \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void socket_setblocking(p_socket ps) { +void socket_setblocking(p_socket ps) { u_long argp = 0; ioctlsocket(*ps, FIONBIO, &argp); } @@ -307,7 +311,7 @@ LUASOCKET_PRIVATE void socket_setblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * Put socket into non-blocking mode \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE void socket_setnonblocking(p_socket ps) { +void socket_setnonblocking(p_socket ps) { u_long argp = 1; ioctlsocket(*ps, FIONBIO, &argp); } @@ -315,13 +319,13 @@ LUASOCKET_PRIVATE void socket_setnonblocking(p_socket ps) { /*-------------------------------------------------------------------------*\ * DNS helpers \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) { +int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) { *hp = gethostbyaddr(addr, len, AF_INET); if (*hp) return IO_DONE; else return WSAGetLastError(); } -LUASOCKET_PRIVATE int socket_gethostbyname(const char *addr, struct hostent **hp) { +int socket_gethostbyname(const char *addr, struct hostent **hp) { *hp = gethostbyname(addr); if (*hp) return IO_DONE; else return WSAGetLastError(); @@ -330,7 +334,7 @@ LUASOCKET_PRIVATE int socket_gethostbyname(const char *addr, struct hostent **hp /*-------------------------------------------------------------------------*\ * Error translation functions \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE const char *socket_hoststrerror(int err) { +const char *socket_hoststrerror(int err) { if (err <= 0) return io_strerror(err); switch (err) { case WSAHOST_NOT_FOUND: return PIE_HOST_NOT_FOUND; @@ -338,7 +342,7 @@ LUASOCKET_PRIVATE const char *socket_hoststrerror(int err) { } } -LUASOCKET_PRIVATE const char *socket_strerror(int err) { +const char *socket_strerror(int err) { if (err <= 0) return io_strerror(err); switch (err) { case WSAEADDRINUSE: return PIE_ADDRINUSE; @@ -352,12 +356,12 @@ LUASOCKET_PRIVATE const char *socket_strerror(int err) { } } -LUASOCKET_PRIVATE const char *socket_ioerror(p_socket ps, int err) { +const char *socket_ioerror(p_socket ps, int err) { (void) ps; return socket_strerror(err); } -LUASOCKET_PRIVATE static const char *wstrerror(int err) { +static const char *wstrerror(int err) { switch (err) { case WSAEINTR: return "Interrupted function call"; case WSAEACCES: return PIE_ACCESS; // "Permission denied"; @@ -406,7 +410,7 @@ LUASOCKET_PRIVATE static const char *wstrerror(int err) { } } -LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) { +const char *socket_gaistrerror(int err) { if (err == 0) return NULL; switch (err) { case EAI_AGAIN: return PIE_AGAIN; @@ -433,3 +437,6 @@ LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) { } } +#ifndef _WIN32 +#pragma GCC visibility pop +#endif From c8d0fdda544b32ee0b7bcd38b26933ecc2c8a95b Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 21:05:38 -0700 Subject: [PATCH 121/194] src/makefile: serial += compat --- src/makefile | 1 + 1 file changed, 1 insertion(+) 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) \ From 33883e78c82b66c5e044da2257841b54231d51c5 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Thu, 28 Feb 2019 07:14:57 -0700 Subject: [PATCH 122/194] rockspecs: serial += compat --- luasocket-scm-0.rockspec | 1 + rockspec/luasocket-3.0rc2-1.rockspec | 1 + 2 files changed, 2 insertions(+) diff --git a/luasocket-scm-0.rockspec b/luasocket-scm-0.rockspec index 6cdb0ce..9681a97 100644 --- a/luasocket-scm-0.rockspec +++ b/luasocket-scm-0.rockspec @@ -96,6 +96,7 @@ local function make_plat(plat) modules["socket.serial"] = { sources = { "src/buffer.c" + , "src/compat.c" , "src/auxiliar.c" , "src/options.c" , "src/timeout.c" diff --git a/rockspec/luasocket-3.0rc2-1.rockspec b/rockspec/luasocket-3.0rc2-1.rockspec index 2b299f3..7d0714c 100644 --- a/rockspec/luasocket-3.0rc2-1.rockspec +++ b/rockspec/luasocket-3.0rc2-1.rockspec @@ -96,6 +96,7 @@ local function make_plat(plat) modules["socket.serial"] = { sources = { "src/buffer.c" + , "src/compat.c" , "src/auxiliar.c" , "src/options.c" , "src/timeout.c" From 3a37ab88906bcdbad17051decc0e4c4c141a17c9 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Thu, 28 Feb 2019 07:23:25 -0700 Subject: [PATCH 123/194] rockspecs: unix += compat --- luasocket-scm-0.rockspec | 1 + rockspec/luasocket-3.0rc2-1.rockspec | 1 + 2 files changed, 2 insertions(+) diff --git a/luasocket-scm-0.rockspec b/luasocket-scm-0.rockspec index 9681a97..b4bf377 100644 --- a/luasocket-scm-0.rockspec +++ b/luasocket-scm-0.rockspec @@ -82,6 +82,7 @@ local function make_plat(plat) modules["socket.unix"] = { sources = { "src/buffer.c" + , "src/compat.c" , "src/auxiliar.c" , "src/options.c" , "src/timeout.c" diff --git a/rockspec/luasocket-3.0rc2-1.rockspec b/rockspec/luasocket-3.0rc2-1.rockspec index 7d0714c..dfe5275 100644 --- a/rockspec/luasocket-3.0rc2-1.rockspec +++ b/rockspec/luasocket-3.0rc2-1.rockspec @@ -82,6 +82,7 @@ local function make_plat(plat) modules["socket.unix"] = { sources = { "src/buffer.c" + , "src/compat.c" , "src/auxiliar.c" , "src/options.c" , "src/timeout.c" From 21514304be9e98a4386cb18542582068a59c5586 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Thu, 28 Feb 2019 16:32:07 -0700 Subject: [PATCH 124/194] wrap visibility pragmas in #ifndef _WIN32 --- src/auxiliar.h | 4 ++++ src/buffer.h | 4 ++++ src/compat.h | 4 ++++ src/except.h | 4 ++++ src/inet.h | 4 ++++ src/io.h | 5 ++++- src/options.h | 4 ++++ src/select.h | 4 ++++ src/socket.h | 4 ++++ src/tcp.h | 4 ++++ src/timeout.c | 8 -------- src/timeout.h | 4 ++++ src/udp.h | 4 ++++ src/unixdgram.h | 4 ++++ src/unixstream.h | 4 ++++ src/wsocket.c | 8 -------- 16 files changed, 56 insertions(+), 17 deletions(-) diff --git a/src/auxiliar.h b/src/auxiliar.h index 234b00a..e8c3ead 100644 --- a/src/auxiliar.h +++ b/src/auxiliar.h @@ -31,7 +31,9 @@ #include "luasocket.h" +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int auxiliar_open(lua_State *L); void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func); @@ -45,6 +47,8 @@ void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); int auxiliar_typeerror(lua_State *L, int narg, const char *tname); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* AUXILIAR_H */ diff --git a/src/buffer.h b/src/buffer.h index 4218ea0..a0901fc 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -33,7 +33,9 @@ typedef struct t_buffer_ { } t_buffer; typedef t_buffer *p_buffer; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int buffer_open(lua_State *L); void buffer_init(p_buffer buf, p_io io, p_timeout tm); @@ -43,6 +45,8 @@ int buffer_meth_send(lua_State *L, p_buffer buf); int buffer_meth_receive(lua_State *L, p_buffer buf); int buffer_isempty(p_buffer buf); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* BUF_H */ diff --git a/src/compat.h b/src/compat.h index 8c32b07..fa2d7d7 100644 --- a/src/compat.h +++ b/src/compat.h @@ -3,12 +3,16 @@ #if LUA_VERSION_NUM==501 +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup); void *luasocket_testudata ( lua_State *L, int arg, const char *tname); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #define luaL_setfuncs luasocket_setfuncs #define luaL_testudata luasocket_testudata diff --git a/src/except.h b/src/except.h index baa7b09..71c31fd 100644 --- a/src/except.h +++ b/src/except.h @@ -33,10 +33,14 @@ #include "luasocket.h" +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int except_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif diff --git a/src/inet.h b/src/inet.h index 2e00e58..5618b61 100644 --- a/src/inet.h +++ b/src/inet.h @@ -22,7 +22,9 @@ #define LUASOCKET_INET_ATON #endif +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int inet_open(lua_State *L); @@ -47,6 +49,8 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); int inet_pton(int af, const char *src, void *dst); #endif +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* INET_H */ diff --git a/src/io.h b/src/io.h index e08eb0e..b8a54df 100644 --- a/src/io.h +++ b/src/io.h @@ -56,12 +56,15 @@ typedef struct t_io_ { } t_io; typedef t_io *p_io; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); const char *io_strerror(int err); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* IO_H */ - diff --git a/src/options.h b/src/options.h index 1457f43..41f7337 100644 --- a/src/options.h +++ b/src/options.h @@ -18,7 +18,9 @@ typedef struct t_opt { } t_opt; typedef t_opt *p_opt; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps); @@ -93,6 +95,8 @@ int opt_get_ip6_v6only(lua_State *L, p_socket ps); int opt_get_error(lua_State *L, p_socket ps); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif diff --git a/src/select.h b/src/select.h index 95272db..5d45fe7 100644 --- a/src/select.h +++ b/src/select.h @@ -10,10 +10,14 @@ * true if there is data ready for reading (required for buffered input). \*=========================================================================*/ +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int select_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* SELECT_H */ diff --git a/src/socket.h b/src/socket.h index 4adc562..e541f27 100644 --- a/src/socket.h +++ b/src/socket.h @@ -36,7 +36,9 @@ typedef struct sockaddr SA; * interface to sockets \*=========================================================================*/ +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int socket_waitfd(p_socket ps, int sw, p_timeout tm); int socket_open(void); @@ -64,6 +66,8 @@ const char *socket_strerror(int err); const char *socket_ioerror(p_socket ps, int err); const char *socket_gaistrerror(int err); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* SOCKET_H */ diff --git a/src/tcp.h b/src/tcp.h index 9b12b53..9b282ef 100644 --- a/src/tcp.h +++ b/src/tcp.h @@ -30,10 +30,14 @@ typedef struct t_tcp_ { typedef t_tcp *p_tcp; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int tcp_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* TCP_H */ diff --git a/src/timeout.c b/src/timeout.c index 0e3ee27..2bdc069 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -26,10 +26,6 @@ #define MAX(x, y) ((x) > (y) ? x : y) #endif -#ifndef _WIN32 -#pragma GCC visibility push(hidden) -#endif - /*=========================================================================*\ * Internal function prototypes \*=========================================================================*/ @@ -228,7 +224,3 @@ int timeout_lua_sleep(lua_State *L) return 0; } #endif - -#ifndef _WIN32 -#pragma GCC visibility pop -#endif diff --git a/src/timeout.h b/src/timeout.h index df05eaf..9e5250d 100644 --- a/src/timeout.h +++ b/src/timeout.h @@ -14,7 +14,9 @@ typedef struct t_timeout_ { } t_timeout; typedef t_timeout *p_timeout; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif void timeout_init(p_timeout tm, double block, double total); double timeout_get(p_timeout tm); @@ -29,7 +31,9 @@ int timeout_open(lua_State *L); int timeout_meth_settimeout(lua_State *L, p_timeout tm); int timeout_meth_gettimeout(lua_State *L, p_timeout tm); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #define timeout_iszero(tm) ((tm)->block == 0.0) diff --git a/src/udp.h b/src/udp.h index 9e80ccd..07d5247 100644 --- a/src/udp.h +++ b/src/udp.h @@ -26,10 +26,14 @@ typedef struct t_udp_ { } t_udp; typedef t_udp *p_udp; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int udp_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* UDP_H */ diff --git a/src/unixdgram.h b/src/unixdgram.h index 433fe25..a1a0166 100644 --- a/src/unixdgram.h +++ b/src/unixdgram.h @@ -15,10 +15,14 @@ #include "unix.h" +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int unixdgram_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* UNIXDGRAM_H */ diff --git a/src/unixstream.h b/src/unixstream.h index 8ffba8f..7916aff 100644 --- a/src/unixstream.h +++ b/src/unixstream.h @@ -16,10 +16,14 @@ \*=========================================================================*/ #include "unix.h" +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int unixstream_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* UNIXSTREAM_H */ diff --git a/src/wsocket.c b/src/wsocket.c index 1da984c..20da330 100755 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -12,10 +12,6 @@ #include "socket.h" #include "pierror.h" -#ifndef _WIN32 -#pragma GCC visibility push(hidden) -#endif - /* WinSock doesn't have a strerror... */ static const char *wstrerror(int err); @@ -436,7 +432,3 @@ const char *socket_gaistrerror(int err) { default: return gai_strerror(err); } } - -#ifndef _WIN32 -#pragma GCC visibility pop -#endif From 9acb6dc81ab09aa0784f216c96ac4c3a5d50f61e Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Sun, 21 Apr 2019 09:31:08 -0600 Subject: [PATCH 125/194] move SCM rockspec to rockspec folder; rename consistent with luarocks repository --- luasocket-scm-0.rockspec => rockspec/luasocket-scm-1.rockspec | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename luasocket-scm-0.rockspec => rockspec/luasocket-scm-1.rockspec (100%) diff --git a/luasocket-scm-0.rockspec b/rockspec/luasocket-scm-1.rockspec similarity index 100% rename from luasocket-scm-0.rockspec rename to rockspec/luasocket-scm-1.rockspec From ab3b0ef5c945b6736aa0fb42317db3b5b5773dec Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Sun, 21 Apr 2019 09:41:17 -0600 Subject: [PATCH 126/194] rockspec/luasocket-scm-2.rockspec --- rockspec/{luasocket-scm-1.rockspec => luasocket-scm-2.rockspec} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename rockspec/{luasocket-scm-1.rockspec => luasocket-scm-2.rockspec} (99%) diff --git a/rockspec/luasocket-scm-1.rockspec b/rockspec/luasocket-scm-2.rockspec similarity index 99% rename from rockspec/luasocket-scm-1.rockspec rename to rockspec/luasocket-scm-2.rockspec index b4bf377..9a71b07 100644 --- a/rockspec/luasocket-scm-1.rockspec +++ b/rockspec/luasocket-scm-2.rockspec @@ -1,5 +1,5 @@ package = "LuaSocket" -version = "scm-0" +version = "scm-2" source = { url = "git://github.com/diegonehab/luasocket.git" , branch="master" From 78a1657c7db5510ba66f8d4491f1e8e7370c5943 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Fri, 27 Mar 2020 18:41:57 -0600 Subject: [PATCH 127/194] src/makefile: remove -DLUASOCKET_INET_PTON as current mingw builds don't want it --- src/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 84e5336e8b9f364e675c3a55a8bb04c1fddb68bc Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Fri, 27 Mar 2020 16:55:04 -0600 Subject: [PATCH 128/194] test/tcp-getoptions: bugfix: missing "socket =" in require"socket" --- test/tcp-getoptions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tcp-getoptions b/test/tcp-getoptions index 777ccc3..d98b189 100755 --- a/test/tcp-getoptions +++ b/test/tcp-getoptions @@ -1,6 +1,6 @@ #!/usr/bin/env lua -require"socket" +local socket = require"socket" port = 8765 From c8b4fdf85829d98e185256fba10d50f5b35735a8 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Sat, 28 Mar 2020 15:14:18 -0600 Subject: [PATCH 129/194] test/getoptions: guard calls with pcall(); check result of getoption"linger" --- test/tcp-getoptions | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/tcp-getoptions b/test/tcp-getoptions index d98b189..fbcc884 100755 --- a/test/tcp-getoptions +++ b/test/tcp-getoptions @@ -4,18 +4,32 @@ local socket = require"socket" port = 8765 +function pcalltest(msg, o, opt) + local a = { pcall(o.getoption, o, opt) } + if a[1] then + print(msg, opt, unpack(a)) + else + print(msg, opt, 'fail: ' .. a[2]) + end +end + function options(o) print("options for", o) for _, opt in ipairs{ "keepalive", "reuseaddr", "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do - print("getoption", opt, o:getoption(opt)) + pcalltest("getoption", o, opt) end - print("getoption", "linger", - "on", o:getoption("linger").on, - "timeout", o:getoption("linger").timeout) + r = o:getoption'linger' + if r then + print("getoption", "linger", + "on", r.on, + "timeout", r.timeout) + else + print("getoption", "linger", "no result") + end end local m = socket.tcp() From a7baf8dc25f5824a7b6f3a051e639c78a3a9cff7 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Sat, 28 Mar 2020 15:20:24 -0600 Subject: [PATCH 130/194] test/udp-zero-length-send: add missing "socket ="; use shebang "#!/usr/bin/env lua" --- test/udp-zero-length-send | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/udp-zero-length-send b/test/udp-zero-length-send index a594944..9038c99 100755 --- a/test/udp-zero-length-send +++ b/test/udp-zero-length-send @@ -1,4 +1,4 @@ -#!/usr/bin/lua +#!/usr/bin/env lua --[[ Show that luasocket returns an error message on zero-length UDP sends, @@ -12,7 +12,7 @@ listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes ]] -require"socket" +socket = require"socket" s = assert(socket.udp()) r = assert(socket.udp()) From 743a5f1bcf92e72df8b0ab36c3dee1f53e7d71c5 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Sat, 28 Mar 2020 15:23:51 -0600 Subject: [PATCH 131/194] test/udp-zero-length-send-recv: add missing "socket ="; use shebang "#!/usr/bin/env lua" --- test/udp-zero-length-send-recv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/udp-zero-length-send-recv b/test/udp-zero-length-send-recv index 541efd4..064ca52 100755 --- a/test/udp-zero-length-send-recv +++ b/test/udp-zero-length-send-recv @@ -1,4 +1,4 @@ -#!/usr/bin/lua +#!/usr/bin/env lua --[[ Show that luasocket returns an error message on zero-length UDP sends, @@ -12,7 +12,7 @@ listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes ]] -require"socket" +socket = require"socket" s = assert(socket.udp()) r = assert(socket.udp()) From 5b18e475f38fcf28429b1cc4b17baee3b9793a62 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Sat, 28 Mar 2020 15:28:26 -0600 Subject: [PATCH 132/194] test/find-connect-limit: add missing "socket =" --- test/find-connect-limit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/find-connect-limit b/test/find-connect-limit index ad0c3f5..199e515 100755 --- a/test/find-connect-limit +++ b/test/find-connect-limit @@ -10,7 +10,7 @@ ulimit -n You'll probably need to be root to do this. ]] -require "socket" +socket = require "socket" host = arg[1] or "google.com" port = arg[2] or 80 From d9cc531e3bc62cfe7965c8cb3df7b1d510f3f4a2 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Fri, 18 Mar 2022 02:23:09 -0700 Subject: [PATCH 133/194] Fixe an issue with aux buffer init overwriting optional parameters in receive() (#334) Fixes use on Lua >= 5.4.3 --- src/buffer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/buffer.c b/src/buffer.c index ac5c531..7148be3 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -103,11 +103,14 @@ int buffer_meth_send(lua_State *L, p_buffer buf) { * object:receive() interface \*-------------------------------------------------------------------------*/ int buffer_meth_receive(lua_State *L, p_buffer buf) { - int err = IO_DONE, top = lua_gettop(L); + int err = IO_DONE, top; luaL_Buffer b; size_t size; const char *part = luaL_optlstring(L, 3, "", &size); timeout_markstart(buf->tm); + /* make sure we don't confuse buffer stuff with arguments */ + lua_settop(L, 3); + top = lua_gettop(L); /* initialize buffer with optional extra prefix * (useful for concatenating previous partial results) */ luaL_buffinit(L, &b); From 6952262e6a1315b14935ddd0ea511c202c0154ba Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 18 Mar 2022 17:54:11 +0300 Subject: [PATCH 134/194] style: Use C-style comment syntax throughout (#309) Co-authored-by: Denise Cullassnekuff <19711487+BlackCutpoint@users.noreply.github.com> --- src/mime.c | 8 ++++---- src/options.c | 45 +++++++++++++++++++++++---------------------- src/unixdgram.c | 2 +- src/wsocket.c | 20 ++++++++++---------- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/mime.c b/src/mime.c index 6c210e4..05602f5 100755 --- a/src/mime.c +++ b/src/mime.c @@ -27,12 +27,12 @@ static int mime_global_eol(lua_State *L); static int mime_global_dot(lua_State *L); static size_t dot(int c, size_t state, luaL_Buffer *buffer); -//static void b64setup(UC *base); +/*static void b64setup(UC *base);*/ static size_t b64encode(UC c, UC *input, size_t size, luaL_Buffer *buffer); static size_t b64pad(const UC *input, size_t size, luaL_Buffer *buffer); static size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer); -//static void qpsetup(UC *class, UC *unbase); +/*static void qpsetup(UC *class, UC *unbase);*/ static void qpquote(UC c, luaL_Buffer *buffer); static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer); static size_t qpencode(UC c, UC *input, size_t size, @@ -176,8 +176,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; } diff --git a/src/options.c b/src/options.c index 06ab58d..2b53c67 100644 --- a/src/options.c +++ b/src/options.c @@ -54,7 +54,7 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) return opt->func(L, ps); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ /* enables reuse of local address */ int opt_set_reuseaddr(lua_State *L, p_socket ps) { @@ -66,7 +66,7 @@ int opt_get_reuseaddr(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ /* enables reuse of local port */ int opt_set_reuseport(lua_State *L, p_socket ps) { @@ -78,7 +78,7 @@ int opt_get_reuseport(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ /* disables the Nagle algorithm */ int opt_set_tcp_nodelay(lua_State *L, p_socket ps) { @@ -90,7 +90,7 @@ int opt_get_tcp_nodelay(lua_State *L, p_socket ps) return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ #ifdef TCP_KEEPIDLE int opt_get_tcp_keepidle(lua_State *L, p_socket ps) @@ -105,7 +105,7 @@ int opt_set_tcp_keepidle(lua_State *L, p_socket ps) #endif -// ------------------------------------------------------- +/*------------------------------------------------------*/ #ifdef TCP_KEEPCNT int opt_get_tcp_keepcnt(lua_State *L, p_socket ps) @@ -120,7 +120,7 @@ int opt_set_tcp_keepcnt(lua_State *L, p_socket ps) #endif -// ------------------------------------------------------- +/*------------------------------------------------------*/ #ifdef TCP_KEEPINTVL int opt_get_tcp_keepintvl(lua_State *L, p_socket ps) @@ -135,7 +135,7 @@ int opt_set_tcp_keepintvl(lua_State *L, p_socket ps) #endif -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_keepalive(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); @@ -146,7 +146,7 @@ int opt_get_keepalive(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_dontroute(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE); @@ -157,7 +157,7 @@ int opt_get_dontroute(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_DONTROUTE); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_broadcast(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_BROADCAST); @@ -168,7 +168,7 @@ int opt_get_broadcast(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_BROADCAST); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_recv_buf_size(lua_State *L, p_socket ps) { return opt_setint(L, ps, SOL_SOCKET, SO_RCVBUF); @@ -179,7 +179,7 @@ int opt_get_recv_buf_size(lua_State *L, p_socket ps) return opt_getint(L, ps, SOL_SOCKET, SO_RCVBUF); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_get_send_buf_size(lua_State *L, p_socket ps) { return opt_getint(L, ps, SOL_SOCKET, SO_SNDBUF); @@ -190,7 +190,7 @@ int opt_set_send_buf_size(lua_State *L, p_socket ps) return opt_setint(L, ps, SOL_SOCKET, SO_SNDBUF); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); @@ -201,7 +201,7 @@ int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps) return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS); @@ -212,7 +212,7 @@ int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps) return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip_multicast_loop(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP); @@ -223,7 +223,7 @@ int opt_get_ip_multicast_loop(lua_State *L, p_socket ps) return opt_getboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP); @@ -234,7 +234,7 @@ int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps) return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_linger(lua_State *L, p_socket ps) { struct linger li; /* obj, name, table */ @@ -267,13 +267,13 @@ int opt_get_linger(lua_State *L, p_socket ps) return 1; } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IP, IP_MULTICAST_TTL); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip_multicast_if(lua_State *L, p_socket ps) { const char *address = luaL_checkstring(L, 3); /* obj, name, ip */ @@ -298,7 +298,7 @@ int opt_get_ip_multicast_if(lua_State *L, p_socket ps) return 1; } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip_add_membership(lua_State *L, p_socket ps) { return opt_setmembership(L, ps, IPPROTO_IP, IP_ADD_MEMBERSHIP); @@ -309,7 +309,7 @@ int opt_set_ip_drop_membersip(lua_State *L, p_socket ps) return opt_setmembership(L, ps, IPPROTO_IP, IP_DROP_MEMBERSHIP); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip6_add_membership(lua_State *L, p_socket ps) { return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP); @@ -319,7 +319,8 @@ int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps) { return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP); } -// ------------------------------------------------------- + +/*------------------------------------------------------*/ int opt_get_ip6_v6only(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); @@ -330,7 +331,7 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps) return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_get_error(lua_State *L, p_socket ps) { int val = 0; diff --git a/src/unixdgram.c b/src/unixdgram.c index 3ac3c5e..69093d7 100644 --- a/src/unixdgram.c +++ b/src/unixdgram.c @@ -16,7 +16,7 @@ #define UNIXDGRAM_DATAGRAMSIZE 8192 -// provide a SUN_LEN macro if sys/un.h doesn't (e.g. Android) +/* provide a SUN_LEN macro if sys/un.h doesn't (e.g. Android) */ #ifndef SUN_LEN #define SUN_LEN(ptr) \ ((size_t) (((struct sockaddr_un *) 0)->sun_path) \ diff --git a/src/wsocket.c b/src/wsocket.c index 20da330..7cd4115 100755 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -360,7 +360,7 @@ const char *socket_ioerror(p_socket ps, int err) { static const char *wstrerror(int err) { switch (err) { case WSAEINTR: return "Interrupted function call"; - case WSAEACCES: return PIE_ACCESS; // "Permission denied"; + case WSAEACCES: return PIE_ACCESS; /* "Permission denied"; */ case WSAEFAULT: return "Bad address"; case WSAEINVAL: return "Invalid argument"; case WSAEMFILE: return "Too many open files"; @@ -373,23 +373,23 @@ static const char *wstrerror(int err) { case WSAEPROTOTYPE: return "Protocol wrong type for socket"; case WSAENOPROTOOPT: return "Bad protocol option"; case WSAEPROTONOSUPPORT: return "Protocol not supported"; - case WSAESOCKTNOSUPPORT: return PIE_SOCKTYPE; // "Socket type not supported"; + case WSAESOCKTNOSUPPORT: return PIE_SOCKTYPE; /* "Socket type not supported"; */ case WSAEOPNOTSUPP: return "Operation not supported"; case WSAEPFNOSUPPORT: return "Protocol family not supported"; - case WSAEAFNOSUPPORT: return PIE_FAMILY; // "Address family not supported by protocol family"; - case WSAEADDRINUSE: return PIE_ADDRINUSE; // "Address already in use"; + case WSAEAFNOSUPPORT: return PIE_FAMILY; /* "Address family not supported by protocol family"; */ + case WSAEADDRINUSE: return PIE_ADDRINUSE; /* "Address already in use"; */ case WSAEADDRNOTAVAIL: return "Cannot assign requested address"; case WSAENETDOWN: return "Network is down"; case WSAENETUNREACH: return "Network is unreachable"; case WSAENETRESET: return "Network dropped connection on reset"; case WSAECONNABORTED: return "Software caused connection abort"; - case WSAECONNRESET: return PIE_CONNRESET; // "Connection reset by peer"; + case WSAECONNRESET: return PIE_CONNRESET; /* "Connection reset by peer"; */ case WSAENOBUFS: return "No buffer space available"; - case WSAEISCONN: return PIE_ISCONN; // "Socket is already connected"; + case WSAEISCONN: return PIE_ISCONN; /* "Socket is already connected"; */ case WSAENOTCONN: return "Socket is not connected"; case WSAESHUTDOWN: return "Cannot send after socket shutdown"; - case WSAETIMEDOUT: return PIE_TIMEDOUT; // "Connection timed out"; - case WSAECONNREFUSED: return PIE_CONNREFUSED; // "Connection refused"; + case WSAETIMEDOUT: return PIE_TIMEDOUT; /* "Connection timed out"; */ + case WSAECONNREFUSED: return PIE_CONNREFUSED; /* "Connection refused"; */ case WSAEHOSTDOWN: return "Host is down"; case WSAEHOSTUNREACH: return "No route to host"; case WSAEPROCLIM: return "Too many processes"; @@ -398,9 +398,9 @@ static const char *wstrerror(int err) { case WSANOTINITIALISED: return "Successful WSAStartup not yet performed"; case WSAEDISCON: return "Graceful shutdown in progress"; - case WSAHOST_NOT_FOUND: return PIE_HOST_NOT_FOUND; // "Host not found"; + case WSAHOST_NOT_FOUND: return PIE_HOST_NOT_FOUND; /* "Host not found"; */ case WSATRY_AGAIN: return "Nonauthoritative host not found"; - case WSANO_RECOVERY: return PIE_FAIL; // "Nonrecoverable name lookup error"; + case WSANO_RECOVERY: return PIE_FAIL; /* "Nonrecoverable name lookup error"; */ case WSANO_DATA: return "Valid name, no data record of requested type"; default: return "Unknown error"; } From 52b22da7e3361b6927ef7516851239808d54c673 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 18 Mar 2022 12:12:39 +0100 Subject: [PATCH 135/194] chore: Add editorconfig setup file --- .editorconfig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..edf8aa1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,23 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +[*.{lua,rockspec}] +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab +indent_size = 4 + +[*.html] +indent_style = space +indent_size = 4 + +[*.{c,h}] +indent_style = space +indent_size = 4 From f6509d4fd5dfc0363aada9b1653934356e9abd3f Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 18 Mar 2022 12:12:39 +0100 Subject: [PATCH 136/194] chore: Add luacheck linter project configuration --- .luacheckrc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .luacheckrc diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..fcec7d5 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,31 @@ +unused_args = false +redefined = false +max_line_length = false + +not_globals = { + "string.len", + "table.getn", +} + +include_files = { + "**/*.lua", + "**/*.rockspec", + ".busted", + ".luacheckrc", +} + +exclude_files = { + "etc/*.lua", + "etc/**/*.lua", + "test/*.lua", + "test/**/*.lua", + "samples/*.lua", + "samples/**/*.lua", + "gem/*.lua", + "gem/**/*.lua", + -- GH Actions Lua Environment + ".lua", + ".luarocks", + ".install", +} + From 480c05257211b3e566f33fdf8cf051233e2dab30 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 18 Mar 2022 12:12:39 +0100 Subject: [PATCH 137/194] ci: Add workflow to run luacheck linter --- .github/workflows/luacheck.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/luacheck.yml diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml new file mode 100644 index 0000000..13993cc --- /dev/null +++ b/.github/workflows/luacheck.yml @@ -0,0 +1,26 @@ +name: Luacheck + +on: [push, pull_request] + +jobs: + luacheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Lua + uses: leafo/gh-actions-lua@v8 + with: + luaVersion: 5.4 + + - name: Setup Lua Rocks + uses: leafo/gh-actions-luarocks@v4 + + - name: Setup dependencies + run: luarocks install luacheck + + - name: Run Code Linter + run: | + luacheck . From 601ad8d59f11d7180015d0ecfb9d0a8d67f6f5c1 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 18 Mar 2022 12:12:39 +0100 Subject: [PATCH 138/194] refactor: Address issues raised by linter --- etc/cookie.lua | 22 +++---- etc/get.lua | 2 +- gem/ex11.lua | 4 +- gem/ex3.lua | 2 +- gem/ex4.lua | 2 +- samples/cddb.lua | 2 +- src/ftp.lua | 14 ++--- src/http.lua | 11 ++-- src/ltn12.lua | 3 +- src/mbox.lua | 13 +++-- src/mime.lua | 12 +--- src/url.lua | 6 +- test/ltn12test.lua | 24 ++++---- test/mimetest.lua | 46 +++++++-------- test/smtptest.lua | 20 +++---- test/test_socket_error.lua | 2 +- test/testmesg.lua | 14 ++--- test/testsupport.lua | 2 +- test/urltest.lua | 114 ++++++++++++++++++------------------- test/utestclnt.lua | 68 +++++++++++----------- test/utestsrvr.lua | 2 +- 21 files changed, 187 insertions(+), 198 deletions(-) diff --git a/etc/cookie.lua b/etc/cookie.lua index 4adb403..fec10a1 100644 --- a/etc/cookie.lua +++ b/etc/cookie.lua @@ -5,7 +5,7 @@ local ltn12 = require"ltn12" local token_class = '[^%c%s%(%)%<%>%@%,%;%:%\\%"%/%[%]%?%=%{%}]' -local function unquote(t, quoted) +local function unquote(t, quoted) local n = string.match(t, "%$(%d+)$") if n then n = tonumber(n) end if quoted[n] then return quoted[n] @@ -14,19 +14,19 @@ end local function parse_set_cookie(c, quoted, cookie_table) c = c .. ";$last=last;" - local _, __, n, v, i = string.find(c, "(" .. token_class .. + local _, _, n, v, i = string.find(c, "(" .. token_class .. "+)%s*=%s*(.-)%s*;%s*()") local cookie = { - name = n, - value = unquote(v, quoted), + name = n, + value = unquote(v, quoted), attributes = {} } while 1 do - _, __, n, v, i = string.find(c, "(" .. token_class .. + _, _, n, v, i = string.find(c, "(" .. token_class .. "+)%s*=?%s*(.-)%s*;%s*()", i) if not n or n == "$last" then break end cookie.attributes[#cookie.attributes+1] = { - name = n, + name = n, value = unquote(v, quoted) } end @@ -46,8 +46,8 @@ local function split_set_cookie(s, cookie_table) -- split into individual cookies i = 1 while 1 do - local _, __, cookie, next_token - _, __, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" .. + local _, _, cookie, next_token + _, _, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" .. token_class .. "+)%s*=", i) if not next_token then break end parse_set_cookie(cookie, quoted, cookie_table) @@ -62,12 +62,12 @@ local function quote(s) end local _empty = {} -local function build_cookies(cookies) +local function build_cookies(cookies) s = "" for i,v in ipairs(cookies or _empty) do if v.name then s = s .. v.name - if v.value and v.value ~= "" then + if v.value and v.value ~= "" then s = s .. '=' .. quote(v.value) end end @@ -83,6 +83,6 @@ local function build_cookies(cookies) end if i < #cookies then s = s .. ", " end end - return s + return s end diff --git a/etc/get.lua b/etc/get.lua index 9edc235..d53c465 100644 --- a/etc/get.lua +++ b/etc/get.lua @@ -71,7 +71,7 @@ function stats(size) local current = socket.gettime() if chunk then -- total bytes received - got = got + string.len(chunk) + got = got + string.len(chunk) -- not enough time for estimate if current - last > 1 then io.stderr:write("\r", gauge(got, current - start, size)) diff --git a/gem/ex11.lua b/gem/ex11.lua index 1cbf01f..79c99af 100644 --- a/gem/ex11.lua +++ b/gem/ex11.lua @@ -1,7 +1,7 @@ local input = source.chain( - source.file(io.open("input.bin", "rb")), + source.file(io.open("input.bin", "rb")), encode("base64")) local output = sink.chain( - wrap(76), + wrap(76), sink.file(io.open("output.b64", "w"))) pump.all(input, output) diff --git a/gem/ex3.lua b/gem/ex3.lua index a43fefa..60b4423 100644 --- a/gem/ex3.lua +++ b/gem/ex3.lua @@ -7,7 +7,7 @@ local function chainpair(f1, f2) end function filter.chain(...) - local f = select(1, ...) + local f = select(1, ...) for i = 2, select('#', ...) do f = chainpair(f, select(i, ...)) end diff --git a/gem/ex4.lua b/gem/ex4.lua index c670e0e..c48b77e 100644 --- a/gem/ex4.lua +++ b/gem/ex4.lua @@ -1,4 +1,4 @@ -local qp = filter.chain(normalize(CRLF), encode("quoted-printable"), +local qp = filter.chain(normalize(CRLF), encode("quoted-printable"), wrap("quoted-printable")) local input = source.chain(source.file(io.stdin), qp) local output = sink.file(io.stdout) diff --git a/samples/cddb.lua b/samples/cddb.lua index 49a1871..59d5a44 100644 --- a/samples/cddb.lua +++ b/samples/cddb.lua @@ -26,7 +26,7 @@ function parse(body) data[key] = value end end - return data, code, message + return data, code, message end local host = socket.dns.gethostname() diff --git a/src/ftp.lua b/src/ftp.lua index bd528ca..0ebc508 100644 --- a/src/ftp.lua +++ b/src/ftp.lua @@ -56,7 +56,7 @@ end function metat.__index:login(user, password) self.try(self.tp:command("user", user or _M.USER)) - local code, reply = self.try(self.tp:check{"2..", 331}) + local code, _ = self.try(self.tp:check{"2..", 331}) if code == 331 then self.try(self.tp:command("pass", password or _M.PASSWORD)) self.try(self.tp:check("2..")) @@ -66,7 +66,7 @@ end function metat.__index:pasv() self.try(self.tp:command("pasv")) - local code, reply = self.try(self.tp:check("2..")) + local _, reply = self.try(self.tp:check("2..")) local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)" local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern)) self.try(a and b and c and d and p1 and p2, reply) @@ -83,9 +83,9 @@ end function metat.__index:epsv() self.try(self.tp:command("epsv")) - local code, reply = self.try(self.tp:check("229")) + local _, reply = self.try(self.tp:check("229")) local pattern = "%((.)(.-)%1(.-)%1(.-)%1%)" - local d, prt, address, port = string.match(reply, pattern) + local _, _, _, port = string.match(reply, pattern) self.try(port, "invalid epsv response") self.pasvt = { address = self.tp:getpeername(), @@ -102,7 +102,7 @@ end function metat.__index:port(address, port) self.pasvt = nil if not address then - address, port = self.try(self.tp:getsockname()) + address = self.try(self.tp:getsockname()) self.server = self.try(socket.bind(address, 0)) address, port = self.try(self.server:getsockname()) self.try(self.server:settimeout(_M.TIMEOUT)) @@ -118,7 +118,7 @@ end function metat.__index:eprt(family, address, port) self.pasvt = nil if not address then - address, port = self.try(self.tp:getsockname()) + address = self.try(self.tp:getsockname()) self.server = self.try(socket.bind(address, 0)) address, port = self.try(self.server:getsockname()) self.try(self.server:settimeout(_M.TIMEOUT)) @@ -142,7 +142,7 @@ function metat.__index:send(sendt) local command = sendt.command or "stor" -- send the transfer command and check the reply self.try(self.tp:command(command, argument)) - local code, reply = self.try(self.tp:check{"2..", "1.."}) + local code, _ = self.try(self.tp:check{"2..", "1.."}) -- if there is not a pasvt table, then there is a server -- and we already sent a PORT command if not self.pasvt then self:portconnect() end diff --git a/src/http.lua b/src/http.lua index 6a3416e..e3a1742 100644 --- a/src/http.lua +++ b/src/http.lua @@ -41,9 +41,6 @@ local SCHEMES = { https.tcp, 'LuaSocket: Function tcp() not available from LuaSec') return tcp(t) end }} --- default scheme and port for document retrieval -local SCHEME = 'http' -local PORT = SCHEMES[SCHEME].port ----------------------------------------------------------------------------- -- Reads MIME headers from a connection, unfolding where needed ----------------------------------------------------------------------------- @@ -92,7 +89,7 @@ socket.sourcet["http-chunked"] = function(sock, headers) -- was it the last chunk? if size > 0 then -- if not, get chunk and skip terminating CRLF - local chunk, err, part = sock:receive(size) + local chunk, err, _ = sock:receive(size) if chunk then sock:receive() end return chunk, err else @@ -166,8 +163,8 @@ function metat.__index:receivestatusline() if status ~= "HTTP/" then if ec == "timeout" then return 408 - end - return nil, status + end + return nil, status end -- otherwise proceed reading a status line status = self.try(self.c:receive("*l", status)) @@ -366,7 +363,7 @@ end local headers -- ignore any 100-continue messages while code == 100 do - headers = h:receiveheaders() + h:receiveheaders() code, status = h:receivestatusline() end headers = h:receiveheaders() diff --git a/src/ltn12.lua b/src/ltn12.lua index afa735d..f1e05e1 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua @@ -13,7 +13,7 @@ local unpack = unpack or table.unpack local base = _G local _M = {} if module then -- heuristic for exporting a global package table - ltn12 = _M + ltn12 = _M -- luacheck: ignore end local filter,source,sink,pump = {},{},{},{} @@ -23,7 +23,6 @@ _M.sink = sink _M.pump = pump local unpack = unpack or table.unpack -local select = base.select -- 2048 seems to be better in windows... _M.BLOCKSIZE = 2048 diff --git a/src/mbox.lua b/src/mbox.lua index ed9e781..12823b0 100644 --- a/src/mbox.lua +++ b/src/mbox.lua @@ -1,8 +1,8 @@ local _M = {} if module then - mbox = _M -end + mbox = _M -- luacheck: ignore +end function _M.split_message(message_s) local message = {} @@ -29,7 +29,7 @@ end function _M.parse_header(header_s) header_s = string.gsub(header_s, "\n[ ]+", " ") header_s = string.gsub(header_s, "\n+", "") - local _, __, name, value = string.find(header_s, "([^%s:]-):%s*(.*)") + local _, _, name, value = string.find(header_s, "([^%s:]-):%s*(.*)") return name, value end @@ -49,9 +49,9 @@ function _M.parse_headers(headers_s) end function _M.parse_from(from) - local _, __, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>") + local _, _, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>") if not address then - _, __, address = string.find(from, "%s*(.+)%s*") + _, _, address = string.find(from, "%s*(.+)%s*") end name = name or "" address = address or "" @@ -63,7 +63,8 @@ end function _M.split_mbox(mbox_s) local mbox = {} mbox_s = string.gsub(mbox_s, "\r\n", "\n") .."\n\nFrom \n" - local nj, i, j = 1, 1, 1 + local nj, i + local j = 1 while 1 do i, nj = string.find(mbox_s, "\n\nFrom .-\n", j) if not i then break end diff --git a/src/mime.lua b/src/mime.lua index d3abac5..93539de 100644 --- a/src/mime.lua +++ b/src/mime.lua @@ -10,7 +10,6 @@ local base = _G local ltn12 = require("ltn12") local mime = require("mime.core") -local string = require("string") local _M = mime -- encode, decode and wrap algorithm tables @@ -18,7 +17,7 @@ local encodet, decodet, wrapt = {},{},{} _M.encodet = encodet _M.decodet = decodet -_M.wrapt = wrapt +_M.wrapt = wrapt -- creates a function that chooses a filter by name from a given table local function choose(table) @@ -27,7 +26,7 @@ local function choose(table) name, opt1, opt2 = "default", name, opt1 end local f = table[name or "nil"] - if not f then + if not f then base.error("unknown key (" .. base.tostring(name) .. ")", 3) else return f(opt1, opt2) end end @@ -52,13 +51,6 @@ decodet['quoted-printable'] = function() return ltn12.filter.cycle(_M.unqp, "") end -local function format(chunk) - if chunk then - if chunk == "" then return "''" - else return string.len(chunk) end - else return "nil" end -end - -- define the line-wrap filters wrapt['text'] = function(length) length = length or 76 diff --git a/src/url.lua b/src/url.lua index 0a3a80a..8e0dc5c 100644 --- a/src/url.lua +++ b/src/url.lua @@ -179,9 +179,9 @@ function _M.parse(url, default) function(u) parsed.userinfo = u; return "" end) authority = string.gsub(authority, ":([^:%]]*)$", function(p) parsed.port = p; return "" end) - if authority ~= "" then + if authority ~= "" then -- IPv6? - parsed.host = string.match(authority, "^%[(.+)%]$") or authority + parsed.host = string.match(authority, "^%[(.+)%]$") or authority end local userinfo = parsed.userinfo if not userinfo then return parsed end @@ -264,7 +264,7 @@ function _M.absolute(base_url, relative_url) relative_parsed.query = base_parsed.query end end - else + else relative_parsed.path = absolute_path(base_parsed.path or "", relative_parsed.path) end diff --git a/test/ltn12test.lua b/test/ltn12test.lua index e7d368d..0cafbc9 100644 --- a/test/ltn12test.lua +++ b/test/ltn12test.lua @@ -38,7 +38,7 @@ local function named(f, name) end -------------------------------- -local function split(size) +local function split(size) local buffer = "" local last_out = "" local last_in = "" @@ -50,12 +50,12 @@ local function split(size) return last_out end return function(chunk, done) - if done then - return not last_in and not last_out + if done then + return not last_in and not last_out end -- check if argument is consistent with state if not chunk then - if last_in and last_in ~= "" and last_out ~= "" then + if last_in and last_in ~= "" and last_out ~= "" then error("nil chunk following data chunk", 2) end if not last_out then error("extra nil chunk", 2) end @@ -67,8 +67,8 @@ local function split(size) return output(chunk) else if not last_in then error("data chunk following nil chunk", 2) end - if last_in ~= "" and last_out ~= "" then - error("data chunk following data chunk", 2) + if last_in ~= "" and last_out ~= "" then + error("data chunk following data chunk", 2) end buffer = chunk return output(chunk) @@ -85,7 +85,7 @@ local function format(chunk) end -------------------------------- -local function merge(size) +local function merge(size) local buffer = "" local last_out = "" local last_in = "" @@ -102,12 +102,12 @@ local function merge(size) return last_out end return function(chunk, done) - if done then - return not last_in and not last_out + if done then + return not last_in and not last_out end -- check if argument is consistent with state if not chunk then - if last_in and last_in ~= "" and last_out ~= "" then + if last_in and last_in ~= "" and last_out ~= "" then error("nil chunk following data chunk", 2) end if not last_out then error("extra nil chunk", 2) end @@ -119,8 +119,8 @@ local function merge(size) return output(chunk) else if not last_in then error("data chunk following nil chunk", 2) end - if last_in ~= "" and last_out ~= "" then - error("data chunk following data chunk", 2) + if last_in ~= "" and last_out ~= "" then + error("data chunk following data chunk", 2) end buffer = buffer .. chunk return output(chunk) diff --git a/test/mimetest.lua b/test/mimetest.lua index f5b3747..a3c89ac 100644 --- a/test/mimetest.lua +++ b/test/mimetest.lua @@ -15,27 +15,27 @@ local eb64test = "b64test.bin2" local db64test = "b64test.bin3" --- from Machado de Assis, "A Mão e a Rosa" +-- from Machado de Assis, "A M�o e a Rosa" local mao = [[ - Cursavam estes dois moços a academia de S. Paulo, estando - Luís Alves no quarto ano e Estêvão no terceiro. - Conheceram-se na academia, e ficaram amigos íntimos, tanto - quanto podiam sê-lo dois espíritos diferentes, ou talvez por - isso mesmo que o eram. Estêvão, dotado de extrema - sensibilidade, e não menor fraqueza de ânimo, afetuoso e - bom, não daquela bondade varonil, que é apanágio de uma alma - forte, mas dessa outra bondade mole e de cera, que vai à - mercê de todas as circunstâncias, tinha, além de tudo isso, - o infortúnio de trazer ainda sobre o nariz os óculos - cor-de-rosa de suas virginais ilusões. Luís Alves via bem - com os olhos da cara. Não era mau rapaz, mas tinha o seu - grão de egoísmo, e se não era incapaz de afeições, sabia - regê-las, moderá-las, e sobretudo guiá-las ao seu próprio + Cursavam estes dois mo�os a academia de S. Paulo, estando + Lu�s Alves no quarto ano e Est�v�o no terceiro. + Conheceram-se na academia, e ficaram amigos �ntimos, tanto + quanto podiam s�-lo dois esp�ritos diferentes, ou talvez por + isso mesmo que o eram. Est�v�o, dotado de extrema + sensibilidade, e n�o menor fraqueza de �nimo, afetuoso e + bom, n�o daquela bondade varonil, que � apan�gio de uma alma + forte, mas dessa outra bondade mole e de cera, que vai � + merc� de todas as circunst�ncias, tinha, al�m de tudo isso, + o infort�nio de trazer ainda sobre o nariz os �culos + cor-de-rosa de suas virginais ilus�es. Lu�s Alves via bem + com os olhos da cara. N�o era mau rapaz, mas tinha o seu + gr�o de ego�smo, e se n�o era incapaz de afei��es, sabia + reg�-las, moder�-las, e sobretudo gui�-las ao seu pr�prio interesse. Entre estes dois homens travara-se amizade - íntima, nascida para um na simpatia, para outro no costume. + �ntima, nascida para um na simpatia, para outro no costume. Eram eles os naturais confidentes um do outro, com a - diferença que Luís Alves dava menos do que recebia, e, ainda - assim, nem tudo o que dava exprimia grande confiança. + diferen�a que Lu�s Alves dava menos do que recebia, e, ainda + assim, nem tudo o que dava exprimia grande confian�a. ]] local function random(handle, io_err) @@ -44,8 +44,8 @@ local function random(handle, io_err) if not handle then error("source is empty!", 2) end local len = math.random(0, 1024) local chunk = handle:read(len) - if not chunk then - handle:close() + if not chunk then + handle:close() handle = nil end return chunk @@ -62,7 +62,7 @@ local what = nil local function transform(input, output, filter) local source = random(io.open(input, "rb")) local sink = ltn12.sink.file(io.open(output, "wb")) - if what then + if what then sink = ltn12.sink.chain(filter, sink) else source = ltn12.source.chain(source, filter) @@ -147,7 +147,7 @@ local function create_qptest() f:write(' ',string.char(32)) end f:write("\r\n") - + f:close() end @@ -157,7 +157,7 @@ local function cleanup_qptest() os.remove(dqptest) end --- create test file +-- create test file local function create_b64test() local f = assert(io.open(b64test, "wb")) local t = {} diff --git a/test/smtptest.lua b/test/smtptest.lua index b5380ff..9d06054 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua @@ -27,8 +27,8 @@ local total = function() end local similar = function(s1, s2) - return - string.lower(string.gsub(s1, "%s", "")) == + return + string.lower(string.gsub(s1, "%s", "")) == string.lower(string.gsub(s2, "%s", "")) end @@ -40,9 +40,9 @@ end local readfile = function(name) local f = io.open(name, "r") - if not f then + if not f then fail("unable to open file!") - return nil + return nil end local s = f:read("*a") f:close() @@ -52,7 +52,7 @@ end local empty = function() for i,v in ipairs(files) do local f = io.open(v, "w") - if not f then + if not f then fail("unable to open file!") end f:close() @@ -116,8 +116,8 @@ local wait = function(sentinel, n) while 1 do local mbox = parse(get()) if n == #mbox then break end - if socket.time() - sentinel.time > 50 then - to = 1 + if socket.time() - sentinel.time > 50 then + to = 1 break end socket.sleep(1) @@ -132,7 +132,7 @@ local stuffed_body = [[ This message body needs to be stuffed because it has a dot . -by itself on a line. +by itself on a line. Otherwise the mailer would think that the dot . @@ -219,7 +219,7 @@ else print("ok") end io.write("testing invalid from: ") local ret, err = socket.smtp.mail{ - from = ' " " (( _ * ', + from = ' " " (( _ * ', rcpt = rcpt, } if ret or not err then fail("wrong error message") @@ -227,7 +227,7 @@ else print(err) end io.write("testing no rcpt: ") local ret, err = socket.smtp.mail{ - from = from, + from = from, } if ret or not err then fail("wrong error message") else print(err) end diff --git a/test/test_socket_error.lua b/test/test_socket_error.lua index bda6408..1b4b601 100644 --- a/test/test_socket_error.lua +++ b/test/test_socket_error.lua @@ -19,7 +19,7 @@ for i = 1, 10 do assert(ss == sock) else assert('timeout' == err, 'unexpected error :' .. tostring(err)) - end + end err = sock:getoption("error") -- i get 'connection refused' on WinXP if err then print("Passed! Error is '" .. err .. "'.") diff --git a/test/testmesg.lua b/test/testmesg.lua index 135a008..8c086d5 100644 --- a/test/testmesg.lua +++ b/test/testmesg.lua @@ -34,11 +34,11 @@ r, e = smtp.send{ print(r, e) --- creates a source to send a message with two parts. The first part is +-- creates a source to send a message with two parts. The first part is -- plain text, the second part is a PNG image, encoded as base64. source = smtp.message{ headers = { - -- Remember that headers are *ignored* by smtp.send. + -- Remember that headers are *ignored* by smtp.send. from = "Sicrano ", to = "Fulano ", subject = "Here is a message with attachments" @@ -49,18 +49,18 @@ source = smtp.message{ "Preamble might show up even in a MIME enabled client.", -- first part: No headers means plain text, us-ascii. -- The mime.eol low-level filter normalizes end-of-line markers. - [1] = { + [1] = { body = mime.eol(0, [[ - Lines in a message body should always end with CRLF. + Lines in a message body should always end with CRLF. The smtp module will *NOT* perform translation. It will perform necessary stuffing, though. ]]) }, - -- second part: Headers describe content the to be an image, + -- second part: Headers describe content the to be an image, -- sent under the base64 transfer content encoding. - -- Notice that nothing happens until the message is sent. Small + -- Notice that nothing happens until the message is sent. Small -- chunks are loaded into memory and translation happens on the fly. - [2] = { + [2] = { headers = { ["ConTenT-tYpE"] = 'image/png; name="luasocket.png"', ["content-disposition"] = 'attachment; filename="luasocket.png"', diff --git a/test/testsupport.lua b/test/testsupport.lua index b986088..4360b6b 100644 --- a/test/testsupport.lua +++ b/test/testsupport.lua @@ -7,7 +7,7 @@ function readfile(name) end function similar(s1, s2) - return string.lower(string.gsub(s1 or "", "%s", "")) == + return string.lower(string.gsub(s1 or "", "%s", "")) == string.lower(string.gsub(s2 or "", "%s", "")) end diff --git a/test/urltest.lua b/test/urltest.lua index ae8ba75..9a3c470 100644 --- a/test/urltest.lua +++ b/test/urltest.lua @@ -60,8 +60,8 @@ end local check_absolute_url = function(base, relative, absolute) local res = socket.url.absolute(base, relative) - if res ~= absolute then - io.write("absolute: In test for base='", base, "', rel='", relative, "' expected '", + if res ~= absolute then + io.write("absolute: In test for base='", base, "', rel='", relative, "' expected '", absolute, "' but got '", res, "'\n") os.exit() end @@ -73,7 +73,7 @@ local check_parse_url = function(gaba) local parsed = socket.url.parse(url) for i, v in pairs(gaba) do if v ~= parsed[i] then - io.write("parse: In test for '", url, "' expected ", i, " = '", + io.write("parse: In test for '", url, "' expected ", i, " = '", v, "' but got '", tostring(parsed[i]), "'\n") for i,v in pairs(parsed) do print(i,v) end os.exit() @@ -81,7 +81,7 @@ local check_parse_url = function(gaba) end for i, v in pairs(parsed) do if v ~= gaba[i] then - io.write("parse: In test for '", url, "' expected ", i, " = '", + io.write("parse: In test for '", url, "' expected ", i, " = '", tostring(gaba[i]), "' but got '", v, "'\n") for i,v in pairs(parsed) do print(i,v) end os.exit() @@ -92,8 +92,8 @@ end print("testing URL parsing") check_parse_url{ url = "scheme://user:pass$%?#wd@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "user:pass$%?#wd@host:port", + scheme = "scheme", + authority = "user:pass$%?#wd@host:port", host = "host", port = "port", userinfo = "user:pass$%?#wd", @@ -106,8 +106,8 @@ check_parse_url{ } check_parse_url{ url = "scheme://user:pass?#wd@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "user:pass?#wd@host:port", + scheme = "scheme", + authority = "user:pass?#wd@host:port", host = "host", port = "port", userinfo = "user:pass?#wd", @@ -120,8 +120,8 @@ check_parse_url{ } check_parse_url{ url = "scheme://user:pass-wd@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "user:pass-wd@host:port", + scheme = "scheme", + authority = "user:pass-wd@host:port", host = "host", port = "port", userinfo = "user:pass-wd", @@ -134,8 +134,8 @@ check_parse_url{ } check_parse_url{ url = "scheme://user:pass#wd@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "user:pass#wd@host:port", + scheme = "scheme", + authority = "user:pass#wd@host:port", host = "host", port = "port", userinfo = "user:pass#wd", @@ -148,8 +148,8 @@ check_parse_url{ } check_parse_url{ url = "scheme://user:pass#wd@host:port/path;params?query", - scheme = "scheme", - authority = "user:pass#wd@host:port", + scheme = "scheme", + authority = "user:pass#wd@host:port", host = "host", port = "port", userinfo = "user:pass#wd", @@ -161,8 +161,8 @@ check_parse_url{ } check_parse_url{ url = "scheme://userinfo@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -175,8 +175,8 @@ check_parse_url{ check_parse_url{ url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "user:password@host:port", + scheme = "scheme", + authority = "user:password@host:port", host = "host", port = "port", userinfo = "user:password", @@ -190,8 +190,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/path;params?query#", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -204,8 +204,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/path;params?#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -218,8 +218,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/path;params#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -231,8 +231,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/path;?query#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -245,8 +245,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/path?query#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -258,8 +258,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/;params?query#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -272,8 +272,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -282,7 +282,7 @@ check_parse_url{ check_parse_url{ url = "//userinfo@host:port/path;params?query#fragment", - authority = "userinfo@host:port", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -295,7 +295,7 @@ check_parse_url{ check_parse_url{ url = "//userinfo@host:port/path", - authority = "userinfo@host:port", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -305,7 +305,7 @@ check_parse_url{ check_parse_url{ url = "//userinfo@host/path", - authority = "userinfo@host", + authority = "userinfo@host", host = "host", userinfo = "userinfo", user = "userinfo", @@ -314,7 +314,7 @@ check_parse_url{ check_parse_url{ url = "//user:password@host/path", - authority = "user:password@host", + authority = "user:password@host", host = "host", userinfo = "user:password", password = "password", @@ -324,7 +324,7 @@ check_parse_url{ check_parse_url{ url = "//user:@host/path", - authority = "user:@host", + authority = "user:@host", host = "host", userinfo = "user:", password = "", @@ -334,7 +334,7 @@ check_parse_url{ check_parse_url{ url = "//user@host:port/path", - authority = "user@host:port", + authority = "user@host:port", host = "host", userinfo = "user", user = "user", @@ -344,7 +344,7 @@ check_parse_url{ check_parse_url{ url = "//host:port/path", - authority = "host:port", + authority = "host:port", port = "port", host = "host", path = "/path", @@ -352,14 +352,14 @@ check_parse_url{ check_parse_url{ url = "//host/path", - authority = "host", + authority = "host", host = "host", path = "/path", } check_parse_url{ url = "//host", - authority = "host", + authority = "host", host = "host", } @@ -433,7 +433,7 @@ check_parse_url{ check_parse_url{ url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment", - authority = "userinfo@[::FFFF:129.144.52.38]:port", + authority = "userinfo@[::FFFF:129.144.52.38]:port", host = "::FFFF:129.144.52.38", port = "port", userinfo = "userinfo", @@ -447,7 +447,7 @@ check_parse_url{ check_parse_url{ url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment", scheme = "scheme", - authority = "user:password@[::192.9.5.5]:port", + authority = "user:password@[::192.9.5.5]:port", host = "::192.9.5.5", port = "port", userinfo = "user:password", @@ -462,7 +462,7 @@ check_parse_url{ print("testing URL building") check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", user = "user", @@ -499,7 +499,7 @@ check_build_url{ check_build_url { url = "scheme://user:password@host/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", user = "user", password = "password", @@ -511,7 +511,7 @@ check_build_url { check_build_url { url = "scheme://user@host/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", user = "user", path = "/path", @@ -522,7 +522,7 @@ check_build_url { check_build_url { url = "scheme://host/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", params = "params", @@ -532,7 +532,7 @@ check_build_url { check_build_url { url = "scheme://host/path;params#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", params = "params", @@ -541,7 +541,7 @@ check_build_url { check_build_url { url = "scheme://host/path#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", fragment = "fragment" @@ -549,7 +549,7 @@ check_build_url { check_build_url { url = "scheme://host/path", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", } @@ -567,7 +567,7 @@ check_build_url { check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", user = "user", @@ -581,7 +581,7 @@ check_build_url { check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", user = "user", @@ -596,7 +596,7 @@ check_build_url { check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", userinfo = "user:password", @@ -609,7 +609,7 @@ check_build_url { check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", authority = "user:password@host:port", path = "/path", params = "params", @@ -683,7 +683,7 @@ check_absolute_url("//a/b/c/d;p?q#f", "d/e/f", "//a/b/c/d/e/f") check_absolute_url("/a/b/c/d;p?q#f", "d/e/f", "/a/b/c/d/e/f") check_absolute_url("a/b/c/d", "d/e/f", "a/b/c/d/e/f") check_absolute_url("a/b/c/d/../", "d/e/f", "a/b/c/d/e/f") -check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html", +check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html", "http://velox.telemar.com.br/dashboard/index.html") check_absolute_url("http://example.com/", "../.badhost.com/", "http://example.com/.badhost.com/") check_absolute_url("http://example.com/", "...badhost.com/", "http://example.com/...badhost.com/") @@ -700,11 +700,11 @@ check_absolute_url("http://example.com/a/b/c/d/", "../x/a/../y/z/../../../../q", print("testing path parsing and composition") check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 }) check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 }) -check_parse_path("eu/tu/ele/nos/vos/eles/", +check_parse_path("eu/tu/ele/nos/vos/eles/", { "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1}) check_parse_path("/", { is_absolute = 1, is_directory = 1}) check_parse_path("", { }) -check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/", +check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/", { "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1}) check_parse_path("eu/tu", { "eu", "tu" }) diff --git a/test/utestclnt.lua b/test/utestclnt.lua index 34a0718..7f10643 100644 --- a/test/utestclnt.lua +++ b/test/utestclnt.lua @@ -54,30 +54,30 @@ function check_timeout(tm, sl, elapsed, err, opp, mode, alldone) if not err then warn("must be buffered") elseif err == "timeout" then pass("proper timeout") else fail("unexpected error '%s'", err) end - else - if err ~= "timeout" then fail("should have timed out") + else + if err ~= "timeout" then fail("should have timed out") else pass("proper timeout") end end else if mode == "total" then - if elapsed > tm then + if elapsed > tm then if err ~= "timeout" then fail("should have timed out") else pass("proper timeout") end elseif elapsed < tm then - if err then fail(err) + if err then fail(err) else pass("ok") end - else - if alldone then - if err then fail("unexpected error '%s'", err) + else + if alldone then + if err then fail("unexpected error '%s'", err) else pass("ok") end else - if err ~= "timeout" then fail(err) + if err ~= "timeout" then fail(err) else pass("proper timeoutk") end end end - else - if err then fail(err) - else pass("ok") end + else + if err then fail(err) + else pass("ok") end end end end @@ -104,7 +104,7 @@ function reconnect() print("done " .. i) ]] data, err = uconnect(host, port) - if not data then fail(err) + if not data then fail(err) else pass("connected!") end end @@ -116,8 +116,8 @@ else pass("connected!") end ------------------------------------------------------------------------ function test_methods(sock, methods) for _, v in pairs(methods) do - if type(sock[v]) ~= "function" then - fail(sock.class .. " method '" .. v .. "' not registered") + if type(sock[v]) ~= "function" then + fail(sock.class .. " method '" .. v .. "' not registered") end end pass(sock.class .. " methods are ok") @@ -132,7 +132,7 @@ function test_mixed(len) local p3 = "raw " .. string.rep("z", inter) .. "bytes" local p4 = "end" .. string.rep("w", inter) .. "bytes" local bp1, bp2, bp3, bp4 -remote (string.format("str = data:receive(%d)", +remote (string.format("str = data:receive(%d)", string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4))) sent, err = data:send(p1..p2..p3..p4) if err then fail(err) end @@ -172,7 +172,7 @@ function test_rawline(len) reconnect() local str, str10, back, err str = string.rep(string.char(47), math.mod(len, 10)) - str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), + str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), math.floor(len/10)) str = str .. str10 remote "str = data:receive()" @@ -221,7 +221,7 @@ function test_totaltimeoutreceive(len, tm, sl) data:settimeout(tm, "total") local t = socket.gettime() str, err, partial, elapsed = data:receive(2*len) - check_timeout(tm, sl, elapsed, err, "receive", "total", + check_timeout(tm, sl, elapsed, err, "receive", "total", string.len(str or partial) == 2*len) end @@ -241,7 +241,7 @@ function test_totaltimeoutsend(len, tm, sl) data:settimeout(tm, "total") str = string.rep("a", 2*len) total, err, partial, elapsed = data:send(str) - check_timeout(tm, sl, elapsed, err, "send", "total", + check_timeout(tm, sl, elapsed, err, "send", "total", total == 2*len) end @@ -261,7 +261,7 @@ function test_blockingtimeoutreceive(len, tm, sl) ]], 2*tm, len, sl, sl)) data:settimeout(tm) str, err, partial, elapsed = data:receive(2*len) - check_timeout(tm, sl, elapsed, err, "receive", "blocking", + check_timeout(tm, sl, elapsed, err, "receive", "blocking", string.len(str or partial) == 2*len) end @@ -294,10 +294,10 @@ function empty_connect() data = server:accept() ]] data, err = socket.connect("", port) - if not data then + if not data then pass("ok") data = socket.connect(host, port) - else + else pass("gethostbyname returns localhost on empty string...") end end @@ -331,7 +331,7 @@ function test_closed() data:close() data = nil ]], str)) - -- try to get a line + -- try to get a line back, err, partial = data:receive() if not err then fail("should have gotten 'closed'.") elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") @@ -344,25 +344,25 @@ function test_closed() data = nil ]] total, err, partial = data:send(string.rep("ugauga", 100000)) - if not err then + if not err then pass("failed: output buffer is at least %d bytes long!", total) - elseif err ~= "closed" then + elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") - else - pass("graceful 'closed' received after %d bytes were sent", partial) + else + pass("graceful 'closed' received after %d bytes were sent", partial) end end ------------------------------------------------------------------------ function test_selectbugs() local r, s, e = socket.select(nil, nil, 0.1) - assert(type(r) == "table" and type(s) == "table" and + assert(type(r) == "table" and type(s) == "table" and (e == "timeout" or e == "error")) pass("both nil: ok") local udp = socket.udp() udp:close() r, s, e = socket.select({ udp }, { udp }, 0.1) - assert(type(r) == "table" and type(s) == "table" and + assert(type(r) == "table" and type(s) == "table" and (e == "timeout" or e == "error")) pass("closed sockets: ok") e = pcall(socket.select, "wrong", 1, 0.1) @@ -380,7 +380,7 @@ function accept_timeout() local t = socket.gettime() s:settimeout(1) local c, e = s:accept() - assert(not c, "should not accept") + assert(not c, "should not accept") assert(e == "timeout", string.format("wrong error message (%s)", e)) t = socket.gettime() - t assert(t < 2, string.format("took to long to give up (%gs)", t)) @@ -398,9 +398,9 @@ function connect_timeout() local t = socket.gettime() local r, e = c:connect("127.0.0.2", 80) assert(not r, "should not connect") - assert(socket.gettime() - t < 2, "took too long to give up.") + assert(socket.gettime() - t < 2, "took too long to give up.") c:close() - print("ok") + print("ok") end ------------------------------------------------------------------------ @@ -463,9 +463,9 @@ function getstats_test() data:receive(c) t = t + c local r, s, a = data:getstats() - assert(r == t, "received count failed" .. tostring(r) + assert(r == t, "received count failed" .. tostring(r) .. "/" .. tostring(t)) - assert(s == t, "sent count failed" .. tostring(s) + assert(s == t, "sent count failed" .. tostring(s) .. "/" .. tostring(t)) end print("ok") @@ -473,7 +473,7 @@ end ------------------------------------------------------------------------ -function test_nonblocking(size) +function test_nonblocking(size) reconnect() print("Testing " .. 2*size .. " bytes") remote(string.format([[ diff --git a/test/utestsrvr.lua b/test/utestsrvr.lua index a96b570..b6e4246 100644 --- a/test/utestsrvr.lua +++ b/test/utestsrvr.lua @@ -9,7 +9,7 @@ ack = "\n"; while 1 do print("server: waiting for client connection..."); control = assert(server:accept()); - while 1 do + while 1 do command = assert(control:receive()); assert(control:send(ack)); ((loadstring or load)(command))(); From 989a5b11310c1c6da900c2f997712405a7986d09 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 17:28:25 +0300 Subject: [PATCH 139/194] chore: Include luacheck config in editorconfig setup --- .editorconfig | 2 +- .luacheckrc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.editorconfig b/.editorconfig index edf8aa1..56ad87d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,7 +6,7 @@ insert_final_newline = true trim_trailing_whitespace = true charset = utf-8 -[*.{lua,rockspec}] +[{*.lua,*.rockspec,.luacheckrc}] indent_style = space indent_size = 4 diff --git a/.luacheckrc b/.luacheckrc index fcec7d5..8b25dd7 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -8,10 +8,10 @@ not_globals = { } include_files = { - "**/*.lua", - "**/*.rockspec", - ".busted", - ".luacheckrc", + "**/*.lua", + "**/*.rockspec", + ".busted", + ".luacheckrc", } exclude_files = { From 8390d07774a1ba1a597d809a1a2562d88ecce19d Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 17:34:28 +0300 Subject: [PATCH 140/194] chore: Bump Lua version used in linter --- .github/workflows/luacheck.yml | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml index 13993cc..597cd64 100644 --- a/.github/workflows/luacheck.yml +++ b/.github/workflows/luacheck.yml @@ -3,24 +3,17 @@ name: Luacheck on: [push, pull_request] jobs: - luacheck: - runs-on: ubuntu-latest + luacheck: + runs-on: ubuntu-20.04 steps: - name: Checkout - uses: actions/checkout@v2 - - - name: Setup Lua - uses: leafo/gh-actions-lua@v8 - with: - luaVersion: 5.4 - - - name: Setup Lua Rocks + uses: actions/checkout@v3 + - name: Setup ‘lua’ + uses: leafo/gh-actions-lua@v9 + - name: Setup ‘luarocks’ uses: leafo/gh-actions-luarocks@v4 - - - name: Setup dependencies + - name: Setup ‘luacheck’ run: luarocks install luacheck - - - name: Run Code Linter - run: | - luacheck . + - name: Run ‘luacheck’ linter + run: luacheck . From d0f2d132bf4b02ff342b3d87479ec0cf46f7c059 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 17:55:12 +0300 Subject: [PATCH 141/194] chore: Move SCM rockspec to root and bump rockrel to 3 --- .../luasocket-scm-2.rockspec => luasocket-scm-3.rockspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename rockspec/luasocket-scm-2.rockspec => luasocket-scm-3.rockspec (95%) diff --git a/rockspec/luasocket-scm-2.rockspec b/luasocket-scm-3.rockspec similarity index 95% rename from rockspec/luasocket-scm-2.rockspec rename to luasocket-scm-3.rockspec index 9a71b07..4e1669c 100644 --- a/rockspec/luasocket-scm-2.rockspec +++ b/luasocket-scm-3.rockspec @@ -1,8 +1,8 @@ package = "LuaSocket" -version = "scm-2" +version = "scm-3" source = { - url = "git://github.com/diegonehab/luasocket.git" - , branch="master" + url = "git+https://github.com/lunarmodules/luasocket.git", + branch = "master" } description = { summary = "Network support for the Lua language", @@ -12,7 +12,7 @@ description = { modules that add support for functionality commonly needed by applications that deal with the Internet. ]], - homepage = "http://luaforge.net/projects/luasocket/", + homepage = "https://github.com/lunarmodules/luasocket", license = "MIT" } dependencies = { From 36428e07cd164c83f71469d1bb84992bd026cbb3 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 17:55:12 +0300 Subject: [PATCH 142/194] chore: Rename rockspec dir to be plural --- {rockspec => rockspecs}/luasocket-3.0rc2-1.rockspec | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {rockspec => rockspecs}/luasocket-3.0rc2-1.rockspec (100%) diff --git a/rockspec/luasocket-3.0rc2-1.rockspec b/rockspecs/luasocket-3.0rc2-1.rockspec similarity index 100% rename from rockspec/luasocket-3.0rc2-1.rockspec rename to rockspecs/luasocket-3.0rc2-1.rockspec From 335f647075fb5e0423039e9a335bbf032e8a8334 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 18:20:05 +0300 Subject: [PATCH 143/194] chore: Add current most recent rockspec as published --- rockspecs/luasocket-3.0rc1-2.rockspec | 108 ++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 rockspecs/luasocket-3.0rc1-2.rockspec diff --git a/rockspecs/luasocket-3.0rc1-2.rockspec b/rockspecs/luasocket-3.0rc1-2.rockspec new file mode 100644 index 0000000..3cb6524 --- /dev/null +++ b/rockspecs/luasocket-3.0rc1-2.rockspec @@ -0,0 +1,108 @@ +package = "LuaSocket" +version = "3.0rc1-2" +source = { + url = "https://github.com/diegonehab/luasocket/archive/v3.0-rc1.zip", + dir = "luasocket-3.0-rc1", +} +description = { + summary = "Network support for the Lua language", + detailed = [[ + LuaSocket is a Lua extension library that is composed by two parts: a C core + that provides support for the TCP and UDP transport layers, and a set of Lua + modules that add support for functionality commonly needed by applications + that deal with the Internet. + ]], + homepage = "http://luaforge.net/projects/luasocket/", + license = "MIT" +} +dependencies = { + "lua >= 5.1" +} + +local function make_plat(plat) + local defines = { + unix = { + "LUA_COMPAT_APIINTCASTS", + "LUASOCKET_DEBUG", + "LUASOCKET_API=__attribute__((visibility(\"default\")))", + "UNIX_API=__attribute__((visibility(\"default\")))", + "MIME_API=__attribute__((visibility(\"default\")))" + }, + macosx = { + "LUA_COMPAT_APIINTCASTS", + "LUASOCKET_DEBUG", + "UNIX_HAS_SUN_LEN", + "LUASOCKET_API=__attribute__((visibility(\"default\")))", + "UNIX_API=__attribute__((visibility(\"default\")))", + "MIME_API=__attribute__((visibility(\"default\")))" + }, + win32 = { + "LUA_COMPAT_APIINTCASTS", + "LUASOCKET_DEBUG", + "NDEBUG", + "LUASOCKET_API=__declspec(dllexport)", + "MIME_API=__declspec(dllexport)" + }, + mingw32 = { + "LUA_COMPAT_APIINTCASTS", + "LUASOCKET_DEBUG", + "LUASOCKET_INET_PTON", + "WINVER=0x0501", + "LUASOCKET_API=__declspec(dllexport)", + "MIME_API=__declspec(dllexport)" + } + } + local modules = { + ["socket.core"] = { + sources = { "src/luasocket.c", "src/timeout.c", "src/buffer.c", "src/io.c", "src/auxiliar.c", + "src/options.c", "src/inet.c", "src/except.c", "src/select.c", "src/tcp.c", "src/udp.c" }, + defines = defines[plat], + incdir = "src" + }, + ["mime.core"] = { + sources = { "src/mime.c" }, + defines = defines[plat], + incdir = "src" + }, + ["socket.http"] = "src/http.lua", + ["socket.url"] = "src/url.lua", + ["socket.tp"] = "src/tp.lua", + ["socket.ftp"] = "src/ftp.lua", + ["socket.headers"] = "src/headers.lua", + ["socket.smtp"] = "src/smtp.lua", + ltn12 = "src/ltn12.lua", + socket = "src/socket.lua", + mime = "src/mime.lua" + } + if plat == "unix" or plat == "macosx" then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" + modules["socket.unix"] = { + sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", + "src/usocket.c", "src/unix.c" }, + defines = defines[plat], + incdir = "/src" + } + modules["socket.serial"] = { + sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", + "src/io.c", "src/usocket.c", "src/serial.c" }, + defines = defines[plat], + incdir = "/src" + } + end + if plat == "win32" or plat == "mingw32" then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" + modules["socket.core"].libraries = { "ws2_32" } + end + return { modules = modules } +end + +build = { + type = "builtin", + platforms = { + unix = make_plat("unix"), + macosx = make_plat("macosx"), + win32 = make_plat("win32"), + mingw32 = make_plat("mingw32") + }, + copy_directories = { "doc", "samples", "etc", "test" } +} From 91aa6522a0a4d5e24af86524fa68350de40a2667 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 18:20:52 +0300 Subject: [PATCH 144/194] chore: Drop rockspec for never-published RC2 release --- rockspecs/luasocket-3.0rc2-1.rockspec | 134 -------------------------- 1 file changed, 134 deletions(-) delete mode 100644 rockspecs/luasocket-3.0rc2-1.rockspec diff --git a/rockspecs/luasocket-3.0rc2-1.rockspec b/rockspecs/luasocket-3.0rc2-1.rockspec deleted file mode 100644 index dfe5275..0000000 --- a/rockspecs/luasocket-3.0rc2-1.rockspec +++ /dev/null @@ -1,134 +0,0 @@ -package = "LuaSocket" -version = "3.0rc2-1" -source = { - url = "git://github.com/diegonehab/luasocket.git", - tag = "v3.0-rc2", -} -description = { - summary = "Network support for the Lua language", - detailed = [[ - LuaSocket is a Lua extension library that is composed by two parts: a C core - that provides support for the TCP and UDP transport layers, and a set of Lua - modules that add support for functionality commonly needed by applications - that deal with the Internet. - ]], - homepage = "http://luaforge.net/projects/luasocket/", - license = "MIT" -} -dependencies = { - "lua >= 5.1" -} - -local function make_plat(plat) - local defines = { - unix = { - "LUASOCKET_DEBUG" - }, - macosx = { - "LUASOCKET_DEBUG", - "UNIX_HAS_SUN_LEN" - }, - win32 = { - "LUASOCKET_DEBUG", - "NDEBUG" - }, - mingw32 = { - "LUASOCKET_DEBUG", - "LUASOCKET_INET_PTON", - "WINVER=0x0501" - } - } - local modules = { - ["socket.core"] = { - sources = { - "src/luasocket.c" - , "src/timeout.c" - , "src/buffer.c" - , "src/io.c" - , "src/auxiliar.c" - , "src/options.c" - , "src/inet.c" - , "src/except.c" - , "src/select.c" - , "src/tcp.c" - , "src/udp.c" - , "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["mime.core"] = { - sources = { "src/mime.c", "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["socket.http"] = "src/http.lua", - ["socket.url"] = "src/url.lua", - ["socket.tp"] = "src/tp.lua", - ["socket.ftp"] = "src/ftp.lua", - ["socket.headers"] = "src/headers.lua", - ["socket.smtp"] = "src/smtp.lua", - ltn12 = "src/ltn12.lua", - socket = "src/socket.lua", - mime = "src/mime.lua" - } - if plat == "unix" - or plat == "macosx" - or plat == "haiku" - then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" - if plat == "haiku" then - modules["socket.core"].libraries = {"network"} - end - modules["socket.unix"] = { - sources = { - "src/buffer.c" - , "src/compat.c" - , "src/auxiliar.c" - , "src/options.c" - , "src/timeout.c" - , "src/io.c" - , "src/usocket.c" - , "src/unix.c" - , "src/unixdgram.c" - , "src/unixstream.c" }, - defines = defines[plat], - incdir = "/src" - } - modules["socket.serial"] = { - sources = { - "src/buffer.c" - , "src/compat.c" - , "src/auxiliar.c" - , "src/options.c" - , "src/timeout.c" - , "src/io.c" - , "src/usocket.c" - , "src/serial.c" }, - defines = defines[plat], - incdir = "/src" - } - end - if plat == "win32" - or plat == "mingw32" - then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" - modules["socket.core"].libraries = { "ws2_32" } - end - return { modules = modules } -end - -build = { - type = "builtin", - platforms = { - unix = make_plat("unix"), - macosx = make_plat("macosx"), - haiku = make_plat("haiku"), - win32 = make_plat("win32"), - mingw32 = make_plat("mingw32") - }, - copy_directories = { - "doc" - , "samples" - , "etc" - , "test" } -} From 844165ff89c0ec7bb50ac65ce010200dba1c8d89 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 18:11:43 +0300 Subject: [PATCH 145/194] ci: Drop obsolete Travis configs --- .travis.yml | 54 ----------------------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fce8a96..0000000 --- a/.travis.yml +++ /dev/null @@ -1,54 +0,0 @@ -language: erlang - -env: - global: - - LUAROCKS_BASE=luarocks-2.0.13 - matrix: - - LUA=lua5.1 LUA_DEV=liblua5.1-dev LUA_VER=5.1 LUA_SFX=5.1 LUA_INCDIR=/usr/include/lua5.1 - - LUA=lua5.2 LUA_DEV=liblua5.2-dev LUA_VER=5.2 LUA_SFX=5.2 LUA_INCDIR=/usr/include/lua5.2 - - LUA=luajit LUA_DEV=libluajit-5.1-dev LUA_VER=5.1 LUA_SFX=jit LUA_INCDIR=/usr/include/luajit-2.0 - -branches: - only: - - master - -before_install: - - if [ $LUA = "luajit" ]; then - sudo add-apt-repository ppa:mwild1/ppa -y && sudo apt-get update -y; - fi - - sudo apt-get install $LUA - - sudo apt-get install $LUA_DEV - - lua$LUA_SFX -v - # Install a recent luarocks release - - wget http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz - - tar zxvpf $LUAROCKS_BASE.tar.gz - - cd $LUAROCKS_BASE - - ./configure - --lua-version=$LUA_VER --lua-suffix=$LUA_SFX --with-lua-include="$LUA_INCDIR" - - sudo make - - sudo make install - - cd $TRAVIS_BUILD_DIR - - -install: - - export DEBUG=DEBUG - - sudo -E luarocks make luasocket-scm-0.rockspec - -script: - - cd test - - lua$LUA_SFX hello.lua - - lua$LUA_SFX testsrvr.lua > /dev/null & - - lua$LUA_SFX testclnt.lua - - lua$LUA_SFX stufftest.lua - - lua$LUA_SFX excepttest.lua - - lua$LUA_SFX test_bind.lua - - lua$LUA_SFX test_getaddrinfo.lua - - lua$LUA_SFX ltn12test.lua - - lua$LUA_SFX mimetest.lua - - lua$LUA_SFX urltest.lua - - lua$LUA_SFX test_socket_error.lua - -notifications: - email: - on_success: change - on_failure: always From 2cc6f8a55c45ec9b5ad165c150259060d4d70a82 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 20:55:11 +0300 Subject: [PATCH 146/194] ci: Add workflow to confirm build completes --- .github/workflows/build.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8265bb1 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,24 @@ +name: Check build + +on: [ push, pull_request ] + +jobs: + build: + name: Check build + strategy: + fail-fast: false + matrix: + luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty"] + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup ‘lua’ + uses: leafo/gh-actions-lua@v9 + with: + luaVersion: ${{ matrix.luaVersion }} + - name: Setup ‘luarocks’ + uses: leafo/gh-actions-luarocks@v4 + - name: Make with Luarocks + run: | + luarocks make --pack-binary-rock -- luasocket-scm-3.rockspec From 46ecb7e2dc3dd92931c6d9d99fdc9260e83077ff Mon Sep 17 00:00:00 2001 From: david <57832272+jyoui@users.noreply.github.com> Date: Tue, 1 Feb 2022 15:40:35 +0900 Subject: [PATCH 147/194] src/ltn12.lua: remove duplicated codes --- src/ltn12.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ltn12.lua b/src/ltn12.lua index f1e05e1..4cb17f5 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua @@ -11,6 +11,8 @@ local string = require("string") local table = require("table") local unpack = unpack or table.unpack local base = _G +local select = select + local _M = {} if module then -- heuristic for exporting a global package table ltn12 = _M -- luacheck: ignore @@ -22,8 +24,6 @@ _M.source = source _M.sink = sink _M.pump = pump -local unpack = unpack or table.unpack - -- 2048 seems to be better in windows... _M.BLOCKSIZE = 2048 _M._VERSION = "LTN12 1.0.3" @@ -45,7 +45,7 @@ end -- (thanks to Wim Couwenberg) function filter.chain(...) local arg = {...} - local n = base.select('#',...) + local n = select('#',...) local top, index = 1, 1 local retry = "" return function(chunk) From e3c17b002ae4747c033c374d39538d4e242dbb22 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 11 Mar 2019 02:07:45 -0600 Subject: [PATCH 148/194] Add src\compat.c to mime.vcxproj and socket.vcxproj --- mime.vcxproj | 1 + socket.vcxproj | 1 + 2 files changed, 2 insertions(+) diff --git a/mime.vcxproj b/mime.vcxproj index 43acee9..575f985 100755 --- a/mime.vcxproj +++ b/mime.vcxproj @@ -20,6 +20,7 @@ + {128E8BD0-174A-48F0-8771-92B1E8D18713} diff --git a/socket.vcxproj b/socket.vcxproj index 305c094..51ebc68 100755 --- a/socket.vcxproj +++ b/socket.vcxproj @@ -21,6 +21,7 @@ + From 2a76cb906cb955a83ed76b8e47cc76c77ce8e15f Mon Sep 17 00:00:00 2001 From: Julian Squires Date: Fri, 16 Oct 2020 12:18:46 -0230 Subject: [PATCH 149/194] http.lua: set transfer-encoding if source and no content-length If a source is specified without a content-length header, LuaSocket sends the data in the chunked transfer coding; however, it doesn't set the transfer-encoding header. While I recognize that the user can set this manually, this is a gotcha that has caught me multiple times. RFC7230, section 3.3.3 (https://tools.ietf.org/html/rfc7230#section-3.3.3) is clear about this; if neither content-length nor transfer-encoding chunked are specified, the request message body length is zero. While some servers may ignore this, I have encountered several that follow the RFC in this regard, most recently golang's net/http. --- src/http.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/http.lua b/src/http.lua index e3a1742..1330355 100644 --- a/src/http.lua +++ b/src/http.lua @@ -283,6 +283,13 @@ local function adjustrequest(reqt) nreqt.uri = reqt.uri or adjusturi(nreqt) -- adjust headers in request nreqt.headers = adjustheaders(nreqt) + if nreqt.source + and not nreqt.headers["content-length"] + and not nreqt.headers["transfer-encoding"] + then + nreqt.headers["transfer-encoding"] = "chunked" + end + -- ajust host and port if there is a proxy nreqt.host, nreqt.port = adjustproxy(nreqt) return nreqt From fdd741da5cd0515e69572e564f2d57f336d2466b Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 20:58:52 +0300 Subject: [PATCH 150/194] Ci: Run regression tests after successful build --- .github/workflows/build.yml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8265bb1..64393cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,10 @@ -name: Check build +name: Test build on: [ push, pull_request ] jobs: build: - name: Check build + name: Test build on Linux strategy: fail-fast: false matrix: @@ -19,6 +19,23 @@ jobs: luaVersion: ${{ matrix.luaVersion }} - name: Setup ‘luarocks’ uses: leafo/gh-actions-luarocks@v4 - - name: Make with Luarocks + - name: Make and install locally run: | - luarocks make --pack-binary-rock -- luasocket-scm-3.rockspec + export DEBUG=DEBUG + luarocks --local make -- luasocket-scm-3.rockspec + - name: Run regression tests + run: | + eval $(luarocks --local path) + cd test + lua hello.lua + lua testsrvr.lua > /dev/null & + lua testclnt.lua + lua stufftest.lua + lua excepttest.lua + lua test_bind.lua + lua test_getaddrinfo.lua + lua ltn12test.lua + lua mimetest.lua + lua urltest.lua + lua test_socket_error.lua + kill %1 From 9787c17e589dc1b12c1f96e6bb391a7ff3dd5065 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 21:18:54 +0300 Subject: [PATCH 151/194] ci: Expand test matrix to cover Windows and macOS --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 64393cc..518de63 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,8 @@ jobs: fail-fast: false matrix: luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty"] - runs-on: ubuntu-20.04 + platform: [ "ubuntu-20.04", "windows-2022", "macos-11" ] + runs-on: ${{ matrix.platform }} steps: - name: Checkout uses: actions/checkout@v3 From 52c72694c2989c38fc9df915dcb34995d1e37404 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 21:23:58 +0300 Subject: [PATCH 152/194] ci: Disable unsupported Windows and avoid duplicate runs --- .github/workflows/build.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 518de63..d22e67f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,10 @@ name: Test build -on: [ push, pull_request ] +on: + push: + branches: + - master + pull_request: jobs: build: @@ -9,7 +13,7 @@ jobs: fail-fast: false matrix: luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty"] - platform: [ "ubuntu-20.04", "windows-2022", "macos-11" ] + platform: [ "ubuntu-20.04", "macos-11" ] # "windows-2022" not supported by gh-actions-lua runs-on: ${{ matrix.platform }} steps: - name: Checkout From f9e1d03f3c6c9fc59dd3b91716debc23aebf947f Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 22:42:25 +0300 Subject: [PATCH 153/194] ci: Don't bother doing user-local install in ephemeral runner --- .github/workflows/build.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d22e67f..17cad49 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,13 +24,12 @@ jobs: luaVersion: ${{ matrix.luaVersion }} - name: Setup ‘luarocks’ uses: leafo/gh-actions-luarocks@v4 - - name: Make and install locally + - name: Make and install run: | export DEBUG=DEBUG - luarocks --local make -- luasocket-scm-3.rockspec + luarocks make -- luasocket-scm-3.rockspec - name: Run regression tests run: | - eval $(luarocks --local path) cd test lua hello.lua lua testsrvr.lua > /dev/null & From f97dc8489d58aef2d038288f9a8bc69f907e17bb Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 22 Mar 2022 19:21:58 +0100 Subject: [PATCH 154/194] fix(docs) fix html linter issues in the docs (#358) --- doc/dns.html | 78 +++++------ doc/ftp.html | 122 ++++++++--------- doc/http.html | 142 ++++++++++---------- doc/index.html | 140 +++++++++---------- doc/ltn12.html | 200 ++++++++++++++-------------- doc/mime.html | 302 ++++++++++++++++++++--------------------- doc/reference.html | 22 +-- doc/smtp.html | 191 +++++++++++++------------- doc/socket.html | 256 +++++++++++++++++------------------ doc/tcp.html | 325 +++++++++++++++++++++++---------------------- doc/udp.html | 94 ++++++------- 11 files changed, 938 insertions(+), 934 deletions(-) diff --git a/doc/dns.html b/doc/dns.html index c4a0472..56ce3ba 100644 --- a/doc/dns.html +++ b/doc/dns.html @@ -1,4 +1,4 @@ - @@ -13,22 +13,22 @@ -
    +

    - -
    -LuaSocket +
    +LuaSocket
    Network support for the Lua language +
    Network support for the Lua language
    -

    +

    home · download · installation · introduction · -reference +reference


    @@ -36,14 +36,14 @@ -

    DNS

    +

    DNS

    -IPv4 name resolution functions -dns.toip +IPv4 name resolution functions +dns.toip and -dns.tohostname -return all information obtained from +dns.tohostname +return all information obtained from the resolver in a table of the form:

    @@ -60,10 +60,10 @@ Note that the alias list can be empty.

    -The more general name resolution function -dns.getaddrinfo, which +The more general name resolution function +dns.getaddrinfo, which supports both IPv6 and IPv4, -returns all information obtained from +returns all information obtained from the resolver in a table of the form:

    @@ -88,82 +88,82 @@ addresses, and "inet6" for IPv6 addresses. -

    +

    socket.dns.getaddrinfo(address)

    -

    -Converts from host name to address. +

    +Converts from host name to address.

    -

    -Address can be an IPv4 or IPv6 address or host name. +

    +Address can be an IPv4 or IPv6 address or host name.

    -

    +

    The function returns a table with all information returned by the resolver. In case of error, the function returns nil -followed by an error message. +followed by an error message.

    -

    +

    socket.dns.gethostname()

    -

    -Returns the standard host name for the machine as a string. +

    +Returns the standard host name for the machine as a string.

    -

    +

    socket.dns.tohostname(address)

    -

    +

    Converts from IPv4 address to host name.

    -

    -Address can be an IP address or host name. +

    +Address can be an IP address or host name.

    -

    +

    The function returns a string with the canonic host name of the given address, followed by a table with all information returned by the resolver. In case of error, the function returns nil -followed by an error message. +followed by an error message.

    -

    +

    socket.dns.toip(address)

    -

    +

    Converts from host name to IPv4 address.

    -

    -Address can be an IP address or host name. +

    +Address can be an IP address or host name.

    -

    +

    Returns a string with the first IP address found for address, followed by a table with all information returned by the resolver. In case of error, the function returns nil followed by an error -message. +message.

    -
  • + -

    -The LuaSocket send function does not care or interpret the -headers you send, but it gives you full control over what is sent and +

    +The LuaSocket send function does not care or interpret the +headers you send, but it gives you full control over what is sent and to whom it is sent:

    • If someone is to receive the message, the e-mail address has to be in the recipient list. This is the only parameter that controls who -gets a copy of the message; -
    • If there are multiple recipients, none of them will automatically +gets a copy of the message;
    • +
    • If there are multiple recipients, none of them will automatically know that someone else got that message. That is, the default behavior is -similar to the Bcc field of popular e-mail clients; +similar to the Bcc field of popular e-mail clients;
    • It is up to you to add the To header with the list of primary -recipients so that other recipients can see it; -
    • It is also up to you to add the Cc header with the -list of additional recipients so that everyone else sees it; -
    • Adding a header Bcc is nonsense, unless it is +recipients so that other recipients can see it;
    • +
    • It is also up to you to add the Cc header with the +list of additional recipients so that everyone else sees it;
    • +
    • Adding a header Bcc is nonsense, unless it is empty. Otherwise, everyone receiving the message will see it and that is -exactly what you don't want to happen! +exactly what you don't want to happen!
    -

    -I hope this clarifies the issue. Otherwise, please refer to +

    +I hope this clarifies the issue. Otherwise, please refer to RFC 2821 and RFC 2822.

    -
    +
     -- load the smtp support
     local smtp = require("socket.smtp")
     
     -- Connects to server "localhost" and sends a message to users
    --- "fulano@example.com",  "beltrano@example.com", 
    +-- "fulano@example.com",  "beltrano@example.com",
     -- and "sicrano@example.com".
     -- Note that "fulano" is the primary recipient, "beltrano" receives a
     -- carbon copy and neither of them knows that "sicrano" received a blind
    @@ -388,17 +389,17 @@ mesgt = {
     
     r, e = smtp.send{
       from = from,
    -  rcpt = rcpt, 
    +  rcpt = rcpt,
       source = smtp.message(mesgt)
     }
     
    -