[realtek-ambz] Fix (some) WiFi crashes

This commit is contained in:
Kuba Szczodrzyński
2022-04-27 23:41:41 +02:00
parent 3bfd204909
commit 6d47e3cb76
6 changed files with 17 additions and 9 deletions

View File

@@ -28,9 +28,7 @@ class IWiFiClient : public Client {
IWiFiClient(int sock) {}
~IWiFiClient() {
stop();
}
~IWiFiClient() {}
virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0;
virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0;
@@ -70,5 +68,4 @@ class IWiFiClient : public Client {
virtual uint16_t localPort(int sock) const = 0;
using Print::write;
using Client::stop;
};

View File

@@ -28,7 +28,12 @@
static void __empty() {
// Empty
}
void yield(void) __attribute__ ((weak, alias("__empty")));
#include "cmsis_os.h"
void yield(void) {
taskYIELD();
}
/**
* SysTick hook

View File

@@ -5,6 +5,8 @@ bool WiFiClass::softAP(const char *ssid, const char *passphrase, int channel, bo
if (!enableAP(true))
return false;
vTaskDelay(20);
if (!ssid || *ssid == 0x00 || strlen(ssid) > 32)
return false;

View File

@@ -2,7 +2,6 @@
#include "WiFiPriv.h"
WiFiClient::WiFiClient() {
DiagPrintf("WiFiClient()\r\n");
_sock = -1;
_connected = false;
_rxBuffer = NULL;
@@ -16,6 +15,10 @@ WiFiClient::WiFiClient(int sock) {
_timeout = WIFI_CLIENT_CONNECT_TIMEOUT;
}
WiFiClient::~WiFiClient() {
stop();
}
WiFiClient &WiFiClient::operator=(const IWiFiClient &other) {
stop();
WiFiClient *oth = (WiFiClient *)&other;
@@ -254,14 +257,14 @@ void WiFiClient::stop() {
lwip_close(_sock);
_sock = -1;
_connected = false;
free(_rxBuffer);
delete _rxBuffer;
_rxBuffer = NULL;
}
uint8_t WiFiClient::connected() {
if (_connected) {
uint8_t dummy;
if (lwip_recv(_sock, &dummy, 0, MSG_DONTWAIT) < 0) {
if (lwip_recv(_sock, &dummy, 0, MSG_DONTWAIT) <= 0) {
switch (errno) {
case EWOULDBLOCK:
case ENOENT: // caused by vfs

View File

@@ -12,6 +12,7 @@ class WiFiClient : public IWiFiClient {
public:
WiFiClient();
WiFiClient(int sock);
~WiFiClient();
int connect(IPAddress ip, uint16_t port);
int connect(const char *host, uint16_t port);

View File

@@ -51,7 +51,7 @@ WiFiClient WiFiServer::accept() {
return WiFiClient();
int sock;
if (_sockAccepted) {
if (_sockAccepted >= 0) {
sock = _sockAccepted;
_sockAccepted = -1;
} else {