From 70ec56a0b245c621ff8b699d96e357d50ae6a649 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Fri, 21 Jun 2019 15:10:40 +0200 Subject: [PATCH] - linux socket: set retransmission timeout to 10 s --- hal/socket/linux/socket_linux.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hal/socket/linux/socket_linux.c b/hal/socket/linux/socket_linux.c index 3dffb576..a89a018d 100644 --- a/hal/socket/linux/socket_linux.c +++ b/hal/socket/linux/socket_linux.c @@ -214,6 +214,14 @@ TcpServerSocket_create(const char* address, int port) int optionReuseAddr = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &optionReuseAddr, sizeof(int)); + int tcpUserTimeout = 10000; + int result = setsockopt(fd, SOL_TCP, TCP_USER_TIMEOUT, &tcpUserTimeout, sizeof(tcpUserTimeout)); + + if (result < 0) { + if (DEBUG_SOCKET) + printf("SOCKET: failed to set TCP_USER_TIMEOUT\n"); + } + if (bind(fd, (struct sockaddr *) &serverAddress, sizeof(serverAddress)) >= 0) { serverSocket = (ServerSocket) GLOBAL_MALLOC(sizeof(struct sServerSocket)); serverSocket->fd = fd; @@ -303,6 +311,14 @@ TcpSocket_create() self->fd = sock; self->connectTimeout = 5000; + + int tcpUserTimeout = 10000; + int result = setsockopt(sock, SOL_TCP, TCP_USER_TIMEOUT, &tcpUserTimeout, sizeof(tcpUserTimeout)); + + if (result < 0) { + if (DEBUG_SOCKET) + printf("SOCKET: failed to set TCP_USER_TIMEOUT\n"); + } } else { if (DEBUG_SOCKET)