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 filesBrowse files
authored
Merge pull request espressif#8541 from PilnyTomas/WiFiClient_fix
Reimplemented flush in WiFiClient
2 parents e0657db + 1a5b367 commit 505797c
Copy full SHA for 505797c

File tree

Expand file treeCollapse file tree

1 file changed

+8
-20
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-20
lines changed

‎libraries/WiFi/src/WiFiClient.cpp

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiClient.cpp
+8-20Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.