Skip to content

Commit 01755e1

Browse files
truemediansqueek502
authored andcommitted
Ensure consistent handling of _ex functions.
+ `udp_open_ex` has been merged into `udp_open` and handles the given flags when possible. + `tcp_keepalive_ex` has been merged into `tcp_keepalive` and handles the given flags when possible.
1 parent 8392ec0 commit 01755e1

File tree

7 files changed

+25
-179
lines changed

7 files changed

+25
-179
lines changed

deps/libuv

Submodule libuv updated 118 files

docs/docs.lua

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,24 +2210,9 @@ local doc = {
22102210
name = 'tcp_keepalive',
22112211
method_form = 'tcp:keepalive(enable, [delay])',
22122212
desc = [[
2213-
Enable / disable TCP keep-alive. `delay` is the initial delay in seconds,
2213+
Enable / disable TCP keep-alive. `delay` is the initial delay in seconds, `intvl` is the time in seconds between individual keep-alive probes, and `cnt` is the number of probes to send before assuming the connection is dead.
22142214
ignored when enable is `false`.
22152215
]],
2216-
params = {
2217-
{ name = 'tcp', type = 'uv_tcp_t' },
2218-
{ name = 'enable', type = 'boolean' },
2219-
{ name = 'delay', type = opt_int },
2220-
},
2221-
returns = success_ret,
2222-
},
2223-
{
2224-
name = 'tcp_keepalive_ex',
2225-
method_form = 'tcp:keepalive_ex(enable, [delay], [intvl], [cnt])',
2226-
desc = [[
2227-
Enable / disable TCP keep-alive with all socket options: TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT. `delay` is the value for TCP_KEEPIDLE, `intvl` is the value for TCP_KEEPINTVL, `cnt` is the value for TCP_KEEPCNT, ignored when `enable` is `false`.
2228-
2229-
With TCP keep-alive enabled, idle is the time (in seconds) the connection needs to remain idle before TCP starts sending keep-alive probes. intvl is the time (in seconds) between individual keep-alive probes. TCP will drop the connection after sending cnt probes without getting any replies from the peer, then the handle is destroyed with a UV_ETIMEDOUT error passed to the corresponding callback.
2230-
]],
22312216
params = {
22322217
{ name = 'tcp', type = 'uv_tcp_t' },
22332218
{ name = 'enable', type = 'boolean' },
@@ -2860,28 +2845,6 @@ local doc = {
28602845
Note: The passed file descriptor or SOCKET is not checked for its type, but
28612846
it's required that it represents a valid datagram socket.
28622847
]],
2863-
params = {
2864-
{ name = 'udp', type = 'uv_udp_t' },
2865-
{ name = 'fd', type = 'integer' },
2866-
},
2867-
returns = success_ret,
2868-
},
2869-
{
2870-
name = 'udp_open_ex',
2871-
method_form = 'udp:open_ex(fd, [flags])',
2872-
desc = [[
2873-
Opens an existing file descriptor or Windows SOCKET as a UDP handle.
2874-
2875-
Unix only: The only requirement of the sock argument is that it follows the
2876-
datagram contract (works in unconnected mode, supports sendmsg()/recvmsg(),
2877-
etc). In other words, other datagram-type sockets like raw sockets or netlink
2878-
sockets can also be passed to this function.
2879-
2880-
The file descriptor is set to non-blocking mode.
2881-
2882-
Note: The passed file descriptor or SOCKET is not checked for its type, but
2883-
it's required that it represents a valid datagram socket.
2884-
]],
28852848
params = {
28862849
{ name = 'udp', type = 'uv_udp_t' },
28872850
{ name = 'fd', type = 'integer' },

docs/docs.md

Lines changed: 4 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/meta.lua

Lines changed: 7 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/luv.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ static const luaL_Reg luv_functions[] = {
164164
{"tcp_open", luv_tcp_open},
165165
{"tcp_nodelay", luv_tcp_nodelay},
166166
{"tcp_keepalive", luv_tcp_keepalive},
167-
#if LUV_UV_VERSION_GEQ(1, 52, 0)
168-
{"tcp_keepalive_ex", luv_tcp_keepalive_ex},
169-
#endif
170167
{"tcp_simultaneous_accepts", luv_tcp_simultaneous_accepts},
171168
{"tcp_bind", luv_tcp_bind},
172169
{"tcp_getpeername", luv_tcp_getpeername},
@@ -218,9 +215,6 @@ static const luaL_Reg luv_functions[] = {
218215
{"udp_get_send_queue_size", luv_udp_get_send_queue_size},
219216
{"udp_get_send_queue_count", luv_udp_get_send_queue_count},
220217
{"udp_open", luv_udp_open},
221-
#if LUV_UV_VERSION_GEQ(1, 52, 0)
222-
{"udp_open_ex", luv_udp_open_ex},
223-
#endif
224218
{"udp_bind", luv_udp_bind},
225219
{"udp_getsockname", luv_udp_getsockname},
226220
{"udp_set_membership", luv_udp_set_membership},
@@ -562,9 +556,6 @@ static const luaL_Reg luv_tcp_methods[] = {
562556
{"open", luv_tcp_open},
563557
{"nodelay", luv_tcp_nodelay},
564558
{"keepalive", luv_tcp_keepalive},
565-
#if LUV_UV_VERSION_GEQ(1, 52, 0)
566-
{"keepalive_ex", luv_tcp_keepalive_ex},
567-
#endif
568559
{"simultaneous_accepts", luv_tcp_simultaneous_accepts},
569560
{"bind", luv_tcp_bind},
570561
{"getpeername", luv_tcp_getpeername},
@@ -599,9 +590,6 @@ static const luaL_Reg luv_udp_methods[] = {
599590
{"get_send_queue_size", luv_udp_get_send_queue_size},
600591
{"get_send_queue_count", luv_udp_get_send_queue_count},
601592
{"open", luv_udp_open},
602-
#if LUV_UV_VERSION_GEQ(1, 52, 0)
603-
{"open_ex", luv_udp_open_ex},
604-
#endif
605593
{"bind", luv_udp_bind},
606594
{"getsockname", luv_udp_getsockname},
607595
{"set_membership", luv_udp_set_membership},

src/tcp.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,23 @@ static int luv_tcp_keepalive(lua_State* L) {
8282
unsigned int delay = 0;
8383
luaL_checktype(L, 2, LUA_TBOOLEAN);
8484
enable = lua_toboolean(L, 2);
85-
if (enable) {
86-
delay = luaL_checkinteger(L, 3);
87-
}
88-
ret = uv_tcp_keepalive(handle, enable, delay);
89-
return luv_result(L, ret);
90-
}
91-
92-
#if LUV_UV_VERSION_GEQ(1, 52, 0)
93-
static int luv_tcp_keepalive_ex(lua_State* L) {
94-
uv_tcp_t* handle = luv_check_tcp(L, 1);
95-
int ret, enable;
96-
unsigned int delay = 0;
85+
#if LUV_UV_VERSION_GEQ(1, 52, 0)
9786
unsigned int intvl = 1; // defaults chosen in uv_tcp_keepalive on libuv 1.52.0
9887
unsigned int cnt = 10; // defaults chosen in uv_tcp_keepalive on libuv 1.52.0
99-
luaL_checktype(L, 2, LUA_TBOOLEAN);
100-
enable = lua_toboolean(L, 2);
10188
if (enable) {
10289
delay = luaL_checkinteger(L, 3);
10390
intvl = luaL_optinteger(L, 4, intvl);
10491
cnt = luaL_optinteger(L, 5, cnt);
10592
}
10693
ret = uv_tcp_keepalive_ex(handle, enable, delay, intvl, cnt);
94+
#else
95+
if (enable) {
96+
delay = luaL_checkinteger(L, 3);
97+
}
98+
ret = uv_tcp_keepalive(handle, enable, delay);
99+
#endif
107100
return luv_result(L, ret);
108101
}
109-
#endif
110102

111103
static int luv_tcp_simultaneous_accepts(lua_State* L) {
112104
uv_tcp_t* handle = luv_check_tcp(L, 1);

src/udp.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,9 @@ static int luv_udp_get_send_queue_count(lua_State* L) {
126126
static int luv_udp_open(lua_State* L) {
127127
uv_udp_t* handle = luv_check_udp(L, 1);
128128
uv_os_sock_t sock = luaL_checkinteger(L, 2);
129-
int ret = uv_udp_open(handle, sock);
130-
return luv_result(L, ret);
131-
}
132-
133-
#if LUV_UV_VERSION_GEQ(1, 52, 0)
134-
static int luv_udp_open_ex(lua_State* L) {
135-
uv_udp_t* handle = luv_check_udp(L, 1);
136-
uv_os_sock_t sock = luaL_checkinteger(L, 2);
129+
#if LUV_UV_VERSION_GEQ(1, 52, 0)
137130
unsigned int flags = 0;
131+
138132
if (!lua_isnoneornil(L, 3)) {
139133
if (lua_isinteger(L, 3)) {
140134
flags = (unsigned int)lua_tointeger(L, 3);
@@ -151,9 +145,11 @@ static int luv_udp_open_ex(lua_State* L) {
151145
}
152146

153147
int ret = uv_udp_open_ex(handle, sock, flags);
148+
#else
149+
int ret = uv_udp_open(handle, sock);
150+
#endif
154151
return luv_result(L, ret);
155152
}
156-
#endif
157153

158154
static int luv_udp_bind(lua_State* L) {
159155
uv_udp_t* handle = luv_check_udp(L, 1);

0 commit comments

Comments
 (0)