mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-06 05:21:22 +03:00
keepalive api (default 2h,75s,9 not enabled) (#3937)
This commit is contained in:
parent
fb7c519856
commit
9cfbbc7ad3
@ -344,3 +344,29 @@ void WiFiClient::stopAllExcept(WiFiClient* except)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WiFiClient::keepAlive (uint16_t idle_sec, uint16_t intv_sec, uint8_t count)
|
||||
{
|
||||
_client->keepAlive(idle_sec, intv_sec, count);
|
||||
}
|
||||
|
||||
bool WiFiClient::isKeepAliveEnabled () const
|
||||
{
|
||||
return _client->isKeepAliveEnabled();
|
||||
}
|
||||
|
||||
uint16_t WiFiClient::getKeepAliveIdle () const
|
||||
{
|
||||
return _client->getKeepAliveIdle();
|
||||
}
|
||||
|
||||
uint16_t WiFiClient::getKeepAliveInterval () const
|
||||
{
|
||||
return _client->getKeepAliveInterval();
|
||||
}
|
||||
|
||||
uint8_t WiFiClient::getKeepAliveCount () const
|
||||
{
|
||||
return _client->getKeepAliveCount();
|
||||
}
|
||||
|
@ -30,6 +30,10 @@
|
||||
|
||||
#define WIFICLIENT_MAX_PACKET_SIZE 1460
|
||||
|
||||
#define TCP_DEFAULT_KEEPALIVE_IDLE_SEC 7200 // 2 hours
|
||||
#define TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC 75 // 75 sec
|
||||
#define TCP_DEFAULT_KEEPALIVE_COUNT 9 // fault after 9 failures
|
||||
|
||||
class ClientContext;
|
||||
class WiFiServer;
|
||||
|
||||
@ -85,6 +89,13 @@ public:
|
||||
static void stopAll();
|
||||
static void stopAllExcept(WiFiClient * c);
|
||||
|
||||
void keepAlive (uint16_t idle_sec = TCP_DEFAULT_KEEPALIVE_IDLE_SEC, uint16_t intv_sec = TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC, uint8_t count = TCP_DEFAULT_KEEPALIVE_COUNT);
|
||||
bool isKeepAliveEnabled () const;
|
||||
uint16_t getKeepAliveIdle () const;
|
||||
uint16_t getKeepAliveInterval () const;
|
||||
uint8_t getKeepAliveCount () const;
|
||||
void disableKeepAlive () { keepAlive(0, 0, 0); }
|
||||
|
||||
protected:
|
||||
|
||||
static int8_t _s_connected(void* arg, void* tpcb, int8_t err);
|
||||
|
@ -43,6 +43,9 @@ public:
|
||||
tcp_sent(pcb, &_s_sent);
|
||||
tcp_err(pcb, &_s_error);
|
||||
tcp_poll(pcb, &_s_poll, 1);
|
||||
|
||||
// not enabled by default for 2.4.0
|
||||
//keepAlive();
|
||||
}
|
||||
|
||||
err_t abort()
|
||||
@ -341,6 +344,38 @@ public:
|
||||
return _write_from_source(new BufferedStreamDataSource<ProgmemStream>(stream, size));
|
||||
}
|
||||
|
||||
void keepAlive (uint16_t idle_sec = TCP_DEFAULT_KEEPALIVE_IDLE_SEC, uint16_t intv_sec = TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC, uint8_t count = TCP_DEFAULT_KEEPALIVE_COUNT)
|
||||
{
|
||||
if (idle_sec && intv_sec && count) {
|
||||
_pcb->so_options |= SOF_KEEPALIVE;
|
||||
_pcb->keep_idle = (uint32_t)1000 * idle_sec;
|
||||
_pcb->keep_intvl = (uint32_t)1000 * intv_sec;
|
||||
_pcb->keep_cnt = count;
|
||||
}
|
||||
else
|
||||
_pcb->so_options &= ~SOF_KEEPALIVE;
|
||||
}
|
||||
|
||||
bool isKeepAliveEnabled () const
|
||||
{
|
||||
return !!(_pcb->so_options & SOF_KEEPALIVE);
|
||||
}
|
||||
|
||||
uint16_t getKeepAliveIdle () const
|
||||
{
|
||||
return isKeepAliveEnabled()? (_pcb->keep_idle + 500) / 1000: 0;
|
||||
}
|
||||
|
||||
uint16_t getKeepAliveInterval () const
|
||||
{
|
||||
return isKeepAliveEnabled()? (_pcb->keep_intvl + 500) / 1000: 0;
|
||||
}
|
||||
|
||||
uint8_t getKeepAliveCount () const
|
||||
{
|
||||
return isKeepAliveEnabled()? _pcb->keep_cnt: 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
bool _is_timeout()
|
||||
|
Loading…
x
Reference in New Issue
Block a user