mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Fix stopAllExcept with WiFiClientSecure (#8136)
Fixes #8079 Because WiFiClientSecure inherits WiFiClient, and WiFiClientSecureCtx also inherits WiFiClient, they both end up in the list of TCP connections that are used for WiFiClient::stopAllExcept(). This would cause the underlying SSL connection to be closed whenever you attempted to stopAllExcept(WiFiClientSecure) Fix by adding a "_owned"(by) pointer in the WiFiClient object which points to nullptr (default case) or to the associated lower-layer connection. When stopping all connections except one, only look at the lowermost connections.
This commit is contained in:
parent
2f37c967e1
commit
45e7976c50
@ -77,14 +77,14 @@ WiFiClient* SList<WiFiClient>::_s_first = 0;
|
|||||||
|
|
||||||
|
|
||||||
WiFiClient::WiFiClient()
|
WiFiClient::WiFiClient()
|
||||||
: _client(0)
|
: _client(0), _owned(0)
|
||||||
{
|
{
|
||||||
_timeout = 5000;
|
_timeout = 5000;
|
||||||
WiFiClient::_add(this);
|
WiFiClient::_add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFiClient::WiFiClient(ClientContext* client)
|
WiFiClient::WiFiClient(ClientContext* client)
|
||||||
: _client(client)
|
: _client(client), _owned(0)
|
||||||
{
|
{
|
||||||
_timeout = 5000;
|
_timeout = 5000;
|
||||||
_client->ref();
|
_client->ref();
|
||||||
@ -106,6 +106,7 @@ WiFiClient::WiFiClient(const WiFiClient& other)
|
|||||||
_client = other._client;
|
_client = other._client;
|
||||||
_timeout = other._timeout;
|
_timeout = other._timeout;
|
||||||
_localPort = other._localPort;
|
_localPort = other._localPort;
|
||||||
|
_owned = other._owned;
|
||||||
if (_client)
|
if (_client)
|
||||||
_client->ref();
|
_client->ref();
|
||||||
WiFiClient::_add(this);
|
WiFiClient::_add(this);
|
||||||
@ -118,6 +119,7 @@ WiFiClient& WiFiClient::operator=(const WiFiClient& other)
|
|||||||
_client = other._client;
|
_client = other._client;
|
||||||
_timeout = other._timeout;
|
_timeout = other._timeout;
|
||||||
_localPort = other._localPort;
|
_localPort = other._localPort;
|
||||||
|
_owned = other._owned;
|
||||||
if (_client)
|
if (_client)
|
||||||
_client->ref();
|
_client->ref();
|
||||||
return *this;
|
return *this;
|
||||||
@ -382,9 +384,18 @@ void WiFiClient::stopAll()
|
|||||||
|
|
||||||
void WiFiClient::stopAllExcept(WiFiClient* except)
|
void WiFiClient::stopAllExcept(WiFiClient* except)
|
||||||
{
|
{
|
||||||
|
// Stop all will look at the lowest-level wrapper connections only
|
||||||
|
while (except->_owned) {
|
||||||
|
except = except->_owned;
|
||||||
|
}
|
||||||
for (WiFiClient* it = _s_first; it; it = it->_next) {
|
for (WiFiClient* it = _s_first; it; it = it->_next) {
|
||||||
if (it != except) {
|
WiFiClient* conn = it;
|
||||||
it->stop();
|
// Find the lowest-level owner of the current list entry
|
||||||
|
while (conn->_owned) {
|
||||||
|
conn = conn->_owned;
|
||||||
|
}
|
||||||
|
if (conn != except) {
|
||||||
|
conn->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,7 @@ protected:
|
|||||||
void _err(int8_t err);
|
void _err(int8_t err);
|
||||||
|
|
||||||
ClientContext* _client;
|
ClientContext* _client;
|
||||||
|
WiFiClient* _owned;
|
||||||
static uint16_t _localPort;
|
static uint16_t _localPort;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -232,8 +232,8 @@ class WiFiClientSecure : public WiFiClient {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
WiFiClientSecure():_ctx(new WiFiClientSecureCtx()) { }
|
WiFiClientSecure():_ctx(new WiFiClientSecureCtx()) { _owned = _ctx.get(); }
|
||||||
WiFiClientSecure(const WiFiClientSecure &rhs): WiFiClient(), _ctx(rhs._ctx) { }
|
WiFiClientSecure(const WiFiClientSecure &rhs): WiFiClient(), _ctx(rhs._ctx) { if (_ctx) _owned = _ctx.get(); }
|
||||||
~WiFiClientSecure() override { _ctx = nullptr; }
|
~WiFiClientSecure() override { _ctx = nullptr; }
|
||||||
|
|
||||||
WiFiClientSecure& operator=(const WiFiClientSecure&) = default; // The shared-ptrs handle themselves automatically
|
WiFiClientSecure& operator=(const WiFiClientSecure&) = default; // The shared-ptrs handle themselves automatically
|
||||||
|
Loading…
x
Reference in New Issue
Block a user