tcp keepalive: user TCP_USER_TIMEOUT on linux if extant

https://github.com/warmcat/libwebsockets/issues/1223
This commit is contained in:
Andy Green 2018-04-18 18:45:27 +08:00
parent b9b100bdfd
commit a9390874c7
3 changed files with 15 additions and 0 deletions

View file

@ -1365,6 +1365,11 @@ endif()
CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE\n#include <unistd.h>\nint main(void) {int fd[2];\n return pipe2(fd, 0);\n}\n" LWS_HAVE_PIPE2)
# tcp keepalive needs this on linux to work practically... but it only exists
# after kernel 2.6.37
CHECK_C_SOURCE_COMPILES("#include <linux/tcp.h>\nint main(void) { return TCP_USER_TIMEOUT; }\n" LWS_HAVE_TCP_USER_TIMEOUT)
set(CMAKE_REQUIRED_LIBRARIES ${temp})
# Generate the lws_config.h that includes all the public compilation settings.
configure_file(

View file

@ -81,6 +81,8 @@
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine LWS_HAVE_UNISTD_H
#cmakedefine LWS_HAVE_TCP_USER_TIMEOUT
/* Define to 1 if you have the `vfork' function. */
#cmakedefine LWS_HAVE_VFORK

View file

@ -348,6 +348,14 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd)
*/
#else
/* set the keepalive conditions we want on it too */
#if defined(LWS_HAVE_TCP_USER_TIMEOUT)
optval = 1000 * (vhost->ka_time +
(vhost->ka_interval * vhost->ka_probes));
if (setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT,
(const void *)&optval, optlen) < 0)
return 1;
#endif
optval = vhost->ka_time;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE,
(const void *)&optval, optlen) < 0)