Skip to content

Commit

Permalink
core: Add TCP_USER_TIMEOUT socket option on listening socket.
Browse files Browse the repository at this point in the history
Use tcp_send_timeout config option also on listening socket to timeout outbound messages sent on passive inbound connections.
  • Loading branch information
schoberw authored and miconda committed Aug 7, 2023
1 parent 6344554 commit d893f3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/tcp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3172,6 +3172,18 @@ int tcp_init(struct socket_info *sock_info)
}
#endif
init_sock_keepalive(sock_info->socket);
#ifdef HAVE_TCP_USER_TIMEOUT
if((optval = TICKS_TO_S(cfg_get(tcp, tcp_cfg, send_timeout)))) {
optval *= 1000;
if(setsockopt(sock_info->socket, IPPROTO_TCP, TCP_USER_TIMEOUT, &optval,
sizeof(optval))
< 0) {
LM_WARN("failed to set TCP_USER_TIMEOUT: %s\n", strerror(errno));
} else {
LM_INFO("Set TCP_USER_TIMEOUT=%d ms\n", optval);
}
}
#endif
if(bind(sock_info->socket, &addr->s, sockaddru_len(*addr)) == -1) {
LM_ERR("bind(%x, %p, %d) on %s:%d : %s\n", sock_info->socket, &addr->s,
(unsigned)sockaddru_len(*addr), sock_info->address_str.s,
Expand Down
7 changes: 7 additions & 0 deletions src/core/tcp_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
#endif /* __OS_ */
#endif /* NO_TCP_LINGER2 */

/* tcp user_timeout */
#ifndef NO_TCP_USER_TIMEOUT
#ifdef __OS_linux
#define HAVE_TCP_USER_TIMEOUT
#endif /* __OS_ */
#endif /* NO_TCP_LINGER2 */

/* keepalive */
#ifndef NO_TCP_KEEPALIVE
#define HAVE_SO_KEEPALIVE
Expand Down

0 comments on commit d893f3a

Please sign in to comment.