Enable socket keepalives.
This commit is contained in:
@@ -5,7 +5,7 @@ LIBS ?= -ljansson -lprotobuf-c
|
|||||||
|
|
||||||
OBJ_NETWORK = incoming.o outgoing.o receive.o send.o
|
OBJ_NETWORK = incoming.o outgoing.o receive.o send.o
|
||||||
OBJ_PROTOCOL = airspy_adsb.o beast.o json.o proto.o raw.o stats.o
|
OBJ_PROTOCOL = airspy_adsb.o beast.o json.o proto.o raw.o stats.o
|
||||||
OBJ_UTIL = buf.o hex.o opts.o packet.o peer.o rand.o resolve.o server.o uuid.o wakeup.o
|
OBJ_UTIL = buf.o hex.o opts.o packet.o peer.o rand.o resolve.o server.o socket.o uuid.o wakeup.o
|
||||||
OBJ_PROTO = adsb.pb-c.o
|
OBJ_PROTO = adsb.pb-c.o
|
||||||
|
|
||||||
all: adsbus
|
all: adsbus
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "peer.h"
|
#include "peer.h"
|
||||||
#include "resolve.h"
|
#include "resolve.h"
|
||||||
|
#include "socket.h"
|
||||||
#include "wakeup.h"
|
#include "wakeup.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
|
|
||||||
@@ -65,6 +66,8 @@ static void incoming_handler(struct peer *peer) {
|
|||||||
local_hbuf, local_sbuf,
|
local_hbuf, local_sbuf,
|
||||||
peer_hbuf, peer_sbuf);
|
peer_hbuf, peer_sbuf);
|
||||||
|
|
||||||
|
socket_init(fd);
|
||||||
|
|
||||||
incoming->handler(fd, incoming->passthrough, NULL);
|
incoming->handler(fd, incoming->passthrough, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "peer.h"
|
#include "peer.h"
|
||||||
#include "resolve.h"
|
#include "resolve.h"
|
||||||
|
#include "socket.h"
|
||||||
#include "wakeup.h"
|
#include "wakeup.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
|
|
||||||
@@ -89,6 +90,7 @@ static void outgoing_connect_result(struct outgoing *outgoing, int result) {
|
|||||||
case 0:
|
case 0:
|
||||||
fprintf(stderr, "O %s: Connected to %s/%s\n", outgoing->id, hbuf, sbuf);
|
fprintf(stderr, "O %s: Connected to %s/%s\n", outgoing->id, hbuf, sbuf);
|
||||||
freeaddrinfo(outgoing->addrs);
|
freeaddrinfo(outgoing->addrs);
|
||||||
|
socket_init(outgoing->peer.fd);
|
||||||
outgoing->attempt = 0;
|
outgoing->attempt = 0;
|
||||||
int fd = outgoing->peer.fd;
|
int fd = outgoing->peer.fd;
|
||||||
outgoing->peer.fd = -1;
|
outgoing->peer.fd = -1;
|
||||||
|
|||||||
24
adsbus/socket.c
Normal file
24
adsbus/socket.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
|
void socket_init(int fd) {
|
||||||
|
int optval = 1;
|
||||||
|
int err = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval));
|
||||||
|
if (err == -1 && errno == ENOTSOCK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assert(!err);
|
||||||
|
|
||||||
|
optval = 30;
|
||||||
|
assert(!setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &optval, sizeof(optval)));
|
||||||
|
optval = 10;
|
||||||
|
assert(!setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &optval, sizeof(optval)));
|
||||||
|
optval = 3;
|
||||||
|
assert(!setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &optval, sizeof(optval)));
|
||||||
|
}
|
||||||
3
adsbus/socket.h
Normal file
3
adsbus/socket.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void socket_init(int);
|
||||||
Reference in New Issue
Block a user