8000 Merge pull request #8541 from PilnyTomas/WiFiClient_fix · iconnor/arduino-esp32@505797c · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 505797c

Browse files
authored
Merge pull request espressif#8541 from PilnyTomas/WiFiClient_fix
Reimplemented flush in WiFiClient
2 parents e0657db + 1a5b367 commit 505797c

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

libraries/WiFi/src/WiFiClient.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ class WiFiClientRxBuffer {
153153
size_t available(){
154154
return _fill - _pos + r_available();
155155
}
156+
157+
void flush(){
158+
if(r_available()){
159+
fillBuffer();
160+
}
161+
_pos = _fill;
162+
}
156163
};
157164

158165
class WiFiClientSocketHandle {
@@ -501,26 +508,7 @@ int WiFiClient::available()
501508
// Though flushing means to send all pending data,
502509
// seems that in Arduino it also means to clear RX
503510
void WiFiClient::flush() {
504-
int res;
505-
size_t a = available(), toRead = 0;
506-
if(!a){
507-
return;//nothing to flush
508-
}
509-
uint8_t * buf = (uint8_t *)malloc(WIFI_CLIENT_FLUSH_BUFFER_SIZE);
510-
if(!buf){
511-
return;//memory error
512-
}
513-
while(a){
514-
toRead = (a>WIFI_CLIENT_FLUSH_BUFFER_SIZE)?WIFI_CLIENT_FLUSH_BUFFER_SIZE:a;
515-
res = recv(fd(), buf, toRead, MSG_DONTWAIT);
516-
if(res < 0) {
517-
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
518-
stop();
519-
break;
520-
}
521-
a -= res;
522-
}
523-
free(buf);
511+
_rxBuffer->flush();
524512
}
525513

526514
uint8_t WiFiClient::connected()

0 commit comments

Comments
 (0)
0