1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-16 07:23:07 +01:00

add keepalive to socket connections

This commit is contained in:
wellenvogel
2022-01-12 18:30:41 +01:00
parent 0a40ee7b1f
commit ff1c6432af
3 changed files with 34 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
#include <lwip/sockets.h>
#include "GwBuffer.h"
#include "GwSocketConnection.h"
#include "GwSocketHelper.h"
GwSocketServer::GwSocketServer(const GwConfigHandler *config, GwLog *logger, int minId)
{
@@ -62,11 +63,13 @@ int GwSocketServer::available()
if (client_sock >= 0)
{
int val = 1;
if (setsockopt(client_sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&val, sizeof(int)) == ESP_OK)
if (! GwSocketHelper::setKeepAlive(client_sock,true)){
LOG_DEBUG(GwLog::ERROR,"unable to set keepalive, nodelay on socket");
}
else
{
if (setsockopt(client_sock, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(int)) == ESP_OK)
fcntl(client_sock, F_SETFL, O_NONBLOCK);
return client_sock;
fcntl(client_sock, F_SETFL, O_NONBLOCK);
return client_sock;
}
close(client_sock);
}