diff options
author | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-05-22 23:39:34 +0300 |
---|---|---|
committer | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-05-22 23:39:34 +0300 |
commit | f0625e10f0c9567468f376df622e72b23c69762f (patch) | |
tree | 5ee7bc15b6f0e753cadb55bcbe2f871705a85a30 /lib/net/common.c | |
parent | ea106f819487e363ad2eb422f23da9b7cdec9380 (diff) |
feat(net/lib): keep alive configured for client
Diffstat (limited to 'lib/net/common.c')
-rw-r--r-- | lib/net/common.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/net/common.c b/lib/net/common.c index 6ed19ad..084d48d 100644 --- a/lib/net/common.c +++ b/lib/net/common.c @@ -1,8 +1,8 @@ #include "./common.h" -const uint32_t TCPALIVE_IDLE_TIME = 30; -const uint32_t TCPALIVE_CHECK_INTVL = 10; -const uint32_t TCPALIVE_CHECK_CNT = 5; +const uint32_t TCPALIVE_IDLE_TIME = 3; +const uint32_t TCPALIVE_CHECK_INTVL = 1; +const uint32_t TCPALIVE_CHECK_CNT = 2; struct sockaddr_in* get_addr(const char* addr, const char* port) { struct addrinfo hints; @@ -44,6 +44,13 @@ int conn_configure_tcpalive(conn_t* conn) { return -1; } + struct timeval tv = { + .tv_sec = TCPALIVE_IDLE_TIME, + }; + if (setsockopt(conn->conn_socket_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) { + return -1; + } + setsockopt_arg = TCPALIVE_IDLE_TIME; if (setsockopt(conn->conn_socket_fd, IPPROTO_TCP, TCP_KEEPIDLE, &setsockopt_arg, sizeof(setsockopt_arg)) == -1) { return -1; |