diff options
| author | songyanchao <[email protected]> | 2023-07-04 11:00:14 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2023-07-04 11:00:14 +0000 |
| commit | 9bb6ccab4b048caf59cf7cc971edce2aa8938b2c (patch) | |
| tree | 152dad3fe9160c5770a5a54851113ea57159a2f7 | |
| parent | 812c14d0071f3acf2e6ac1fc44d0e889b53ac7c3 (diff) | |
🐞 fix(TSG-15643): ctrlmsg 添加 tcp keepalivev4.6.35-20230704
ctrlmsg 添加 tcp keepalive
| -rw-r--r-- | infra/src/ctrlmsg.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/infra/src/ctrlmsg.c b/infra/src/ctrlmsg.c index 6ad686c..a6f11f9 100644 --- a/infra/src/ctrlmsg.c +++ b/infra/src/ctrlmsg.c @@ -12,6 +12,7 @@ #include <arpa/inet.h> #include <sys/epoll.h> #include <sys/eventfd.h> +#include <netinet/tcp.h> #include <unistd.h> #include <assert.h> #include <fcntl.h> @@ -464,6 +465,41 @@ static int __server_mode_create(struct ctrlmsg_handler * handle, struct sockaddr goto out; } + int tcp_keepalive = 1; + if (setsockopt(listen_fd, SOL_SOCKET, SO_KEEPALIVE, (const void*)&tcp_keepalive, sizeof(int)) < 0) + { + MR_ERROR("Set crash event listen fd keepalive failed : %s", strerror(errno)); + goto out; + } + + int tcp_keepcnt = 4; + if (setsockopt(listen_fd, IPPROTO_TCP, TCP_KEEPCNT, (const void*)&tcp_keepcnt, sizeof(int)) < 0) + { + MR_ERROR("Set crash event listen fd keepcnt failed : %s", strerror(errno)); + goto out; + } + + int tcp_keepintvl = 1; + if (setsockopt(listen_fd, IPPROTO_TCP, TCP_KEEPINTVL, (const void*)&tcp_keepintvl, sizeof(int)) < 0) + { + MR_ERROR("Set crash event listen fd keepintvl failed : %s", strerror(errno)); + goto out; + } + + int tcp_keepidle = 5; + if (setsockopt(listen_fd, IPPROTO_TCP, TCP_KEEPIDLE, (const void*)&tcp_keepidle, sizeof(int)) < 0) + { + MR_ERROR("Set crash event listen fd keepidle failed : %s", strerror(errno)); + goto out; + } + + int tcp_user_timeout = 300; + if (setsockopt(listen_fd, IPPROTO_TCP, TCP_USER_TIMEOUT, (const void*)&tcp_user_timeout, sizeof(int)) < 0) + { + MR_ERROR("Set crash event listen fd user timeout failed : %s", strerror(errno)); + goto out; + } + ret = bind(listen_fd, (struct sockaddr *)&sockaddr_in, sizeof(struct sockaddr_in)); if (ret < 0) { @@ -642,4 +678,4 @@ void ctrlmsg_event_conn_close_register(struct ctrlmsg_handler * handler, cb_object->arg = arg; TAILQ_INSERT_TAIL(&handler->cb_conn_close_list, cb_object, next); return; -}
\ No newline at end of file +} |
