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 4c4a6b8

Browse filesBrowse files
committed
Reimplemented flush in WiFiClient
1 parent 099b432 commit 4c4a6b8
Copy full SHA for 4c4a6b8

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+9
-20
lines changed

‎libraries/WiFi/src/WiFiClient.cpp

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiClient.cpp
+9-20Lines changed: 9 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,8 @@ 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+
#ifdef ARDUINO_DEBUG_LEVEL
512+
_rxBuffer->flush();
524513
}
525514

526515
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.