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

@@ -1,6 +1,7 @@
#include "GwTcpClient.h"
#include <functional>
#include <ESPmDNS.h>
#include "GwSocketHelper.h"
class ResolveArgs{
public:
@@ -72,6 +73,12 @@ void GwTcpClient::startConnection()
LOG_DEBUG(GwLog::ERROR,"unable to create socket: %d", errno);
return;
}
if (! GwSocketHelper::setKeepAlive(sockfd,true)){
error="unable to set keepalive, nodelay on socket";
LOG_DEBUG(GwLog::ERROR,"%s",error.c_str());
close(sockfd);
return;
}
fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) | O_NONBLOCK );
int res = lwip_connect_r(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
if (res < 0 ) {