mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
tcp keepalive: user TCP_USER_TIMEOUT on linux if extant
https://github.com/warmcat/libwebsockets/issues/1223
This commit is contained in:
parent
b9b100bdfd
commit
a9390874c7
3 changed files with 15 additions and 0 deletions
|
@ -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)
|
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})
|
set(CMAKE_REQUIRED_LIBRARIES ${temp})
|
||||||
# Generate the lws_config.h that includes all the public compilation settings.
|
# Generate the lws_config.h that includes all the public compilation settings.
|
||||||
configure_file(
|
configure_file(
|
||||||
|
|
|
@ -81,6 +81,8 @@
|
||||||
/* Define to 1 if you have the <unistd.h> header file. */
|
/* Define to 1 if you have the <unistd.h> header file. */
|
||||||
#cmakedefine LWS_HAVE_UNISTD_H
|
#cmakedefine LWS_HAVE_UNISTD_H
|
||||||
|
|
||||||
|
#cmakedefine LWS_HAVE_TCP_USER_TIMEOUT
|
||||||
|
|
||||||
/* Define to 1 if you have the `vfork' function. */
|
/* Define to 1 if you have the `vfork' function. */
|
||||||
#cmakedefine LWS_HAVE_VFORK
|
#cmakedefine LWS_HAVE_VFORK
|
||||||
|
|
||||||
|
|
|
@ -348,6 +348,14 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd)
|
||||||
*/
|
*/
|
||||||
#else
|
#else
|
||||||
/* set the keepalive conditions we want on it too */
|
/* 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;
|
optval = vhost->ka_time;
|
||||||
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE,
|
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||||
(const void *)&optval, optlen) < 0)
|
(const void *)&optval, optlen) < 0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue