1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-10 04:22:05 +03:00

Better handling of wifi disconnect (#231)

When network interface is down, some nasty things happen, for instance tcp_connect returns without ever calling error callback.
This change adds some workarounds for that: before doing a tcp connect and DNS resolve we check if there is a route available.
Also added a listener for wifi events which stops (aborts) all the WiFiClients and WiFiUDPs when wifi is disconnected. This should
help libraries detect disconnect properly.
This commit is contained in:
Ivan Grokhotkov
2015-06-11 18:01:08 +03:00
parent 567d401ed3
commit e6e57a8b81
7 changed files with 118 additions and 12 deletions

View File

@ -40,14 +40,22 @@ extern "C"
#include "lwip/mem.h"
#include "include/UdpContext.h"
template<>
WiFiUDP* SList<WiFiUDP>::_s_first = 0;
/* Constructor */
WiFiUDP::WiFiUDP() : _ctx(0) {}
WiFiUDP::WiFiUDP() : _ctx(0)
{
WiFiUDP::_add(this);
}
WiFiUDP::WiFiUDP(const WiFiUDP& other)
{
_ctx = other._ctx;
if (_ctx)
_ctx->ref();
WiFiUDP::_add(this);
}
WiFiUDP& WiFiUDP::operator=(const WiFiUDP& rhs)
@ -60,6 +68,7 @@ WiFiUDP& WiFiUDP::operator=(const WiFiUDP& rhs)
WiFiUDP::~WiFiUDP()
{
WiFiUDP::_remove(this);
if (_ctx)
_ctx->unref();
}
@ -258,3 +267,11 @@ uint16_t WiFiUDP::localPort()
return _ctx->getLocalPort();
}
void WiFiUDP::stopAll()
{
for (WiFiUDP* it = _s_first; it; it = it->_next) {
it->stop();
}
}