diff options
| author | Kim Alvefur <zash@zash.se> | 2022-07-27 08:40:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-27 09:40:18 +0300 |
| commit | d1ad8160cba9e504c9d17665492044a93efdc3ab (patch) | |
| tree | f1fdc54ab108383324765104d08c35d09764839a | |
| parent | 0c7df119c2b71bed814db7b3da8fc379131433fe (diff) | |
| download | luasocket-d1ad8160cba9e504c9d17665492044a93efdc3ab.tar.gz luasocket-d1ad8160cba9e504c9d17665492044a93efdc3ab.tar.bz2 luasocket-d1ad8160cba9e504c9d17665492044a93efdc3ab.zip | |
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>
| -rw-r--r-- | docs/tcp.html | 2 | ||||
| -rw-r--r-- | src/options.c | 9 | ||||
| -rw-r--r-- | src/options.h | 4 | ||||
| -rw-r--r-- | src/tcp.c | 3 |
4 files changed, 18 insertions, 0 deletions
diff --git a/docs/tcp.html b/docs/tcp.html index f15196c..a26228d 100644 --- a/docs/tcp.html +++ b/docs/tcp.html | |||
| @@ -485,6 +485,8 @@ disables the Nagle's algorithm for the connection;</li> | |||
| 485 | 485 | ||
| 486 | <li> '<tt>tcp-keepintvl</tt>': value for <tt>TCP_KEEPINTVL</tt> Linux only!!</li> | 486 | <li> '<tt>tcp-keepintvl</tt>': value for <tt>TCP_KEEPINTVL</tt> Linux only!!</li> |
| 487 | 487 | ||
| 488 | <li> '<tt>tcp-defer-accept</tt>': value for <tt>TCP_DEFER_ACCEPT</tt> Linux only!!</li> | ||
| 489 | |||
| 488 | <li> '<tt>tcp-fastopen</tt>': value for <tt>TCP_FASTOPEN</tt> Linux only!!</li> | 490 | <li> '<tt>tcp-fastopen</tt>': value for <tt>TCP_FASTOPEN</tt> Linux only!!</li> |
| 489 | 491 | ||
| 490 | <li> '<tt>tcp-fastopen-connect</tt>': value for <tt>TCP_FASTOPEN_CONNECT</tt> Linux only!!</li> | 492 | <li> '<tt>tcp-fastopen-connect</tt>': value for <tt>TCP_FASTOPEN_CONNECT</tt> Linux only!!</li> |
diff --git a/src/options.c b/src/options.c index 51ea351..3280c51 100644 --- a/src/options.c +++ b/src/options.c | |||
| @@ -207,6 +207,15 @@ int opt_set_tcp_fastopen_connect(lua_State *L, p_socket ps) | |||
| 207 | #endif | 207 | #endif |
| 208 | 208 | ||
| 209 | /*------------------------------------------------------*/ | 209 | /*------------------------------------------------------*/ |
| 210 | |||
| 211 | #ifdef TCP_DEFER_ACCEPT | ||
| 212 | int opt_set_tcp_defer_accept(lua_State *L, p_socket ps) | ||
| 213 | { | ||
| 214 | return opt_setint(L, ps, IPPROTO_TCP, TCP_DEFER_ACCEPT); | ||
| 215 | } | ||
| 216 | #endif | ||
| 217 | |||
| 218 | /*------------------------------------------------------*/ | ||
| 210 | int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) | 219 | int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) |
| 211 | { | 220 | { |
| 212 | return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); | 221 | return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); |
diff --git a/src/options.h b/src/options.h index a4d5d75..456eeb5 100644 --- a/src/options.h +++ b/src/options.h | |||
| @@ -49,6 +49,10 @@ int opt_set_tcp_keepintvl(lua_State *L, p_socket ps); | |||
| 49 | int opt_get_tcp_keepintvl(lua_State *L, p_socket ps); | 49 | int opt_get_tcp_keepintvl(lua_State *L, p_socket ps); |
| 50 | #endif | 50 | #endif |
| 51 | 51 | ||
| 52 | #ifdef TCP_DEFER_ACCEPT | ||
| 53 | int opt_set_tcp_defer_accept(lua_State *L, p_socket ps); | ||
| 54 | #endif | ||
| 55 | |||
| 52 | int opt_set_keepalive(lua_State *L, p_socket ps); | 56 | int opt_set_keepalive(lua_State *L, p_socket ps); |
| 53 | int opt_get_keepalive(lua_State *L, p_socket ps); | 57 | int opt_get_keepalive(lua_State *L, p_socket ps); |
| 54 | 58 | ||
| @@ -109,6 +109,9 @@ static t_opt optset[] = { | |||
| 109 | {"linger", opt_set_linger}, | 109 | {"linger", opt_set_linger}, |
| 110 | {"recv-buffer-size", opt_set_recv_buf_size}, | 110 | {"recv-buffer-size", opt_set_recv_buf_size}, |
| 111 | {"send-buffer-size", opt_set_send_buf_size}, | 111 | {"send-buffer-size", opt_set_send_buf_size}, |
| 112 | #ifdef TCP_DEFER_ACCEPT | ||
| 113 | {"tcp-defer-accept", opt_set_tcp_defer_accept}, | ||
| 114 | #endif | ||
| 112 | #ifdef TCP_FASTOPEN | 115 | #ifdef TCP_FASTOPEN |
| 113 | {"tcp-fastopen", opt_set_tcp_fastopen}, | 116 | {"tcp-fastopen", opt_set_tcp_fastopen}, |
| 114 | #endif | 117 | #endif |
