AfRApay/AfRApay.MateCard/src/wifiFix.cpp

29 lines
683 B
C++
Raw Normal View History

2023-02-06 02:23:00 +01:00
#include <WiFi.h>
#include <lwip/sockets.h>
2023-02-08 02:25:12 +01:00
#include "wifiFix.h"
2023-02-06 02:23:00 +01:00
#define WIFI_CLIENT_FLUSH_BUFFER_SIZE (1024)
void WiFiClientFixed::flush() {
2023-02-08 16:42:47 +01:00
int res;
2023-02-10 03:09:50 +01:00
size_t a = available();
2023-02-08 16:42:47 +01:00
if (!a) {
return;//nothing to flush
}
2023-04-20 16:26:43 +02:00
auto* buf = (uint8_t *) malloc(WIFI_CLIENT_FLUSH_BUFFER_SIZE);
2023-02-08 16:42:47 +01:00
if (!buf) {
return;//memory error
}
while (a) {
// override broken WiFiClient flush method, ref https://github.com/espressif/arduino-esp32/issues/6129#issuecomment-1237417915
2023-02-08 23:51:03 +01:00
res = read(buf, min(a, (size_t)WIFI_CLIENT_FLUSH_BUFFER_SIZE));
2023-02-08 16:42:47 +01:00
if (res < 0) {
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
stop();
break;
}
a -= res;
}
free(buf);
}