mirror of
https://github.com/darkk/redsocks.git
synced 2025-08-28 04:35:30 +00:00
Enable SO_KEEPALIVE for client and relay sockets.
This commit is contained in:
parent
1814548b1d
commit
0a1bcb5bb9
14
redsocks.c
14
redsocks.c
@ -501,6 +501,7 @@ fail:
|
||||
|
||||
void redsocks_connect_relay(redsocks_client *client)
|
||||
{
|
||||
int on = 1;
|
||||
int relay_fd = -1;
|
||||
int error;
|
||||
|
||||
@ -516,6 +517,12 @@ void redsocks_connect_relay(redsocks_client *client)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
error = setsockopt(relay_fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
|
||||
if (error) {
|
||||
redsocks_log_errno(client, LOG_WARNING, "setsockopt");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
error = connect(relay_fd, (struct sockaddr*)&client->instance->config.relayaddr, sizeof(client->instance->config.relayaddr));
|
||||
if (error && errno != EINPROGRESS) {
|
||||
redsocks_log_errno(client, LOG_NOTICE, "connect");
|
||||
@ -550,6 +557,7 @@ static void redsocks_accept_client(int fd, short what, void *_arg)
|
||||
struct sockaddr_in clientaddr;
|
||||
struct sockaddr_in destaddr;
|
||||
socklen_t addrlen = sizeof(clientaddr);
|
||||
int on = 1;
|
||||
int client_fd = -1;
|
||||
int error;
|
||||
|
||||
@ -565,6 +573,12 @@ static void redsocks_accept_client(int fd, short what, void *_arg)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
error = setsockopt(client_fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
|
||||
if (error) {
|
||||
log_errno(LOG_WARNING, "setsockopt");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// everything seems to be ok, let's allocate some memory
|
||||
client = calloc(1, sizeof(redsocks_client) + self->relay_ss->payload_len);
|
||||
if (!client) {
|
||||
|
Loading…
Reference in New Issue
Block a user