feat(tcp): Add support for TCP Defer Accept

This makes it so that a listening socket does not become readable for
accept() until a connection has been fully established *and* started
sending something, thus the program doesn't have to wait for the first
data. This only makes sense for client-speaks-first protocols.

Co-authored-by: Caleb Maclennan <caleb@alerque.com>
This commit is contained in:
Kim Alvefur 2022-07-27 08:40:18 +02:00 committed by GitHub
parent 0c7df119c2
commit d1ad8160cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 0 deletions

View File

@ -485,6 +485,8 @@ disables the Nagle's algorithm for the connection;</li>
<li> '<tt>tcp-keepintvl</tt>': value for <tt>TCP_KEEPINTVL</tt> Linux only!!</li> <li> '<tt>tcp-keepintvl</tt>': value for <tt>TCP_KEEPINTVL</tt> Linux only!!</li>
<li> '<tt>tcp-defer-accept</tt>': value for <tt>TCP_DEFER_ACCEPT</tt> Linux only!!</li>
<li> '<tt>tcp-fastopen</tt>': value for <tt>TCP_FASTOPEN</tt> Linux only!!</li> <li> '<tt>tcp-fastopen</tt>': value for <tt>TCP_FASTOPEN</tt> Linux only!!</li>
<li> '<tt>tcp-fastopen-connect</tt>': value for <tt>TCP_FASTOPEN_CONNECT</tt> Linux only!!</li> <li> '<tt>tcp-fastopen-connect</tt>': value for <tt>TCP_FASTOPEN_CONNECT</tt> Linux only!!</li>

View File

@ -206,6 +206,15 @@ int opt_set_tcp_fastopen_connect(lua_State *L, p_socket ps)
} }
#endif #endif
/*------------------------------------------------------*/
#ifdef TCP_DEFER_ACCEPT
int opt_set_tcp_defer_accept(lua_State *L, p_socket ps)
{
return opt_setint(L, ps, IPPROTO_TCP, TCP_DEFER_ACCEPT);
}
#endif
/*------------------------------------------------------*/ /*------------------------------------------------------*/
int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps)
{ {

View File

@ -49,6 +49,10 @@ int opt_set_tcp_keepintvl(lua_State *L, p_socket ps);
int opt_get_tcp_keepintvl(lua_State *L, p_socket ps); int opt_get_tcp_keepintvl(lua_State *L, p_socket ps);
#endif #endif
#ifdef TCP_DEFER_ACCEPT
int opt_set_tcp_defer_accept(lua_State *L, p_socket ps);
#endif
int opt_set_keepalive(lua_State *L, p_socket ps); int opt_set_keepalive(lua_State *L, p_socket ps);
int opt_get_keepalive(lua_State *L, p_socket ps); int opt_get_keepalive(lua_State *L, p_socket ps);

View File

@ -109,6 +109,9 @@ static t_opt optset[] = {
{"linger", opt_set_linger}, {"linger", opt_set_linger},
{"recv-buffer-size", opt_set_recv_buf_size}, {"recv-buffer-size", opt_set_recv_buf_size},
{"send-buffer-size", opt_set_send_buf_size}, {"send-buffer-size", opt_set_send_buf_size},
#ifdef TCP_DEFER_ACCEPT
{"tcp-defer-accept", opt_set_tcp_defer_accept},
#endif
#ifdef TCP_FASTOPEN #ifdef TCP_FASTOPEN
{"tcp-fastopen", opt_set_tcp_fastopen}, {"tcp-fastopen", opt_set_tcp_fastopen},
#endif #endif