-
Notifications
You must be signed in to change notification settings - Fork 1.9k
network: add support for tcp keepalive probes #3096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,15 @@ int flb_io_net_connect(struct flb_upstream_conn *u_conn, | |
| u_conn->fd, u->tcp_host, u->tcp_port); | ||
| } | ||
|
|
||
| /* set TCP keepalive and it's options */ | ||
| if (u->net.tcp_keepalive != FLB_FALSE) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please either use |
||
| ret = flb_net_socket_tcp_keepalive(fd, &u->net); | ||
| if (ret == -1) { | ||
| flb_socket_close(fd); | ||
| return -1; | ||
| } | ||
| } | ||
|
|
||
| #ifdef FLB_HAVE_TLS | ||
| /* Check if TLS was enabled, if so perform the handshake */ | ||
| if (u->flags & FLB_IO_TLS) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,10 @@ void flb_net_setup_init(struct flb_net_setup *net) | |
| net->keepalive_max_recycle = 0; | ||
| net->connect_timeout = 10; | ||
| net->source_address = NULL; | ||
| net->tcp_keepalive = FLB_FALSE; | ||
| net->tcp_keepalive_time = -1; | ||
| net->tcp_keepalive_interval = -1; | ||
| net->tcp_keepalive_probes = -1; | ||
| } | ||
|
|
||
| int flb_net_host_set(const char *plugin_name, struct flb_net_host *host, const char *address) | ||
|
|
@@ -186,6 +190,42 @@ int flb_net_socket_tcp_fastopen(flb_sockfd_t fd) | |
| return setsockopt(fd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)); | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| * Enable TCP keepalive | ||
| */ | ||
| int flb_net_socket_tcp_keepalive(flb_sockfd_t fd, struct flb_net_setup *net) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please replace the bitwise assignments of Please change the conditional in line 221 so it explicitly compares against zero (ie.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is important because apparently according to msdn, windows doesn't accept values larger than |
||
| { | ||
| int ret = 0; | ||
| int enabled = 1; | ||
| int time = net->tcp_keepalive_time; | ||
| int intvl = net->tcp_keepalive_interval; | ||
| int probes = net->tcp_keepalive_probes; | ||
|
|
||
| printf("keepalive = %d, %d %d\n", time, intvl, probes); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this line. |
||
|
|
||
| ret |= setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&enabled, sizeof(enabled)); | ||
leonardo-albertovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (time >= 0) { | ||
| ret |= setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, (const void*)&time, sizeof(time)); | ||
| } | ||
|
|
||
| if (intvl >= 0) { | ||
| ret |= setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, (const void*)&intvl, sizeof(intvl)); | ||
| } | ||
|
|
||
| if (probes >= 0) { | ||
| ret |= setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, (const void*)&probes, sizeof(probes)); | ||
| } | ||
|
|
||
| if (ret) { | ||
| flb_error("[net] failed to configure TCP keepalive for connection #%i", fd); | ||
| return -1; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| flb_sockfd_t flb_net_socket_create(int family, int nonblock) | ||
| { | ||
| flb_sockfd_t fd; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property needs to be an
int