From db8cfa1ee77a551323eddad5a6c5a5b3416e11e4 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Sat, 27 Apr 2024 00:53:20 +0200 Subject: [PATCH] Add setKeepAlive() --- src/AsyncTCP.cpp | 12 ++++++++++++ src/AsyncTCP.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index 9a4cdf0..0f4a707 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -1118,6 +1118,18 @@ bool AsyncClient::getNoDelay(){ return tcp_nagle_disabled(_pcb); } +void AsyncClient::setKeepAlive(uint32_t ms, uint8_t cnt){ + if(ms!=0) { + _pcb->so_options |= SOF_KEEPALIVE; //Turn on TCP Keepalive for the given pcb + // Set the time between keepalive messages in milli-seconds + _pcb->keep_idle = ms; + _pcb->keep_intvl = ms; + _pcb->keep_cnt = cnt; //The number of unanswered probes required to force closure of the socket + } else { + _pcb->so_options &= ~SOF_KEEPALIVE; //Turn off TCP Keepalive for the given pcb + } +} + uint16_t AsyncClient::getMss(){ if(!_pcb) { return 0; diff --git a/src/AsyncTCP.h b/src/AsyncTCP.h index 7dbcf1c..2110edc 100644 --- a/src/AsyncTCP.h +++ b/src/AsyncTCP.h @@ -135,6 +135,8 @@ class AsyncClient { void setNoDelay(bool nodelay); bool getNoDelay(); + void setKeepAlive(uint32_t ms, uint8_t cnt); + uint32_t getRemoteAddress(); uint16_t getRemotePort(); uint32_t getLocalAddress();