forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WiFiClient: don’t destroy ClientContext on ::stop
Reported in esp8266#4078. WiFiClient::stopAll, called from a WiFi disconnected event handler, could be called while WiFiClient::connect was in progress. This issue was initially fixed in esp8266#4194, by testing `this` pointer for being non-null in ClientContext::connect. This change delegates deletion of ClientContext to WiFiClient destructor. WiFiClient::stop only calls ClientContext::stop, which closes/aborts the connection.
- Loading branch information
Showing
3 changed files
with
70 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <Arduino.h> | ||
#include <BSTest.h> | ||
#include <test_config.h> | ||
#include <ESP8266WiFi.h> | ||
#include <Ticker.h> | ||
|
||
extern "C" { | ||
#include "user_interface.h" | ||
} | ||
|
||
BS_ENV_DECLARE(); | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.setDebugOutput(true); | ||
WiFi.persistent(false); | ||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(STA_SSID, STA_PASS); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
} | ||
BS_RUN(Serial); | ||
} | ||
|
||
static void stopAll() | ||
{ | ||
WiFiClient::stopAll(); | ||
} | ||
|
||
static void disconnectWiFI() | ||
{ | ||
wifi_station_disconnect(); | ||
} | ||
|
||
/* Some IP address that we can try connecting to, and expect a timeout */ | ||
#define UNREACHABLE_IP "192.168.255.255" | ||
|
||
TEST_CASE("WiFiClient::stopAll during WiFiClient::connect", "[wificlient]") | ||
{ | ||
WiFiClient client; | ||
Ticker t; | ||
t.once_ms(500, &stopAll); | ||
REQUIRE(client.connect(UNREACHABLE_IP, 1024) == 0); | ||
} | ||
|
||
TEST_CASE("WiFi disconnect during WiFiClient::connect", "[wificlient]") | ||
{ | ||
WiFiClient client; | ||
Ticker t; | ||
t.once_ms(500, &disconnectWiFI); | ||
REQUIRE(client.connect(UNREACHABLE_IP, 1024) == 0); | ||
} | ||
|
||
void loop() | ||
{ | ||
} |