Skip to content
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

Enable keepalive on TCP connections #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2295,3 +2295,6 @@ Version 1.8.0p5, 12 May 1996
36789.foo
(an understandable typo for #6789.foo) stopped compiling when found in a
database made by a pre-1.8.0 server.

Version X, in progress
-- Enabled keepalive on TCP connections.
6 changes: 6 additions & 0 deletions net_bsd_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
{
int timeout = server_int_option("name_lookup_timeout", 5);
int fd;
int optval;
struct sockaddr_in address;
int addr_length = sizeof(address);
static Stream *s = 0;
Expand All @@ -163,6 +164,8 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
return PA_OTHER;
}
}
optval = 1;
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval));
*read_fd = *write_fd = fd;
stream_printf(s, "%s, port %d",
lookup_name_from_addr(&address, timeout),
Expand Down Expand Up @@ -210,6 +213,7 @@ proto_open_connection(Var arglist, int *read_fd, int *write_fd,
static Timer_ID id;
int s, result, length;
int timeout = server_int_option("name_lookup_timeout", 5);
int optval;
static struct sockaddr_in addr;
static Stream *st1 = 0, *st2 = 0;

Expand Down Expand Up @@ -259,6 +263,8 @@ proto_open_connection(Var arglist, int *read_fd, int *write_fd,
log_perror("Connecting in proto_open_connection");
return E_QUOTA;
}
optval = 1;
setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval));
length = sizeof(addr);
if (getsockname(s, (struct sockaddr *) &addr, &length) < 0) {
close(s);
Expand Down