Skip to content

Commit 31325f4

Browse files
authored
Revert "Revert 8541 wifi client fix (#267)"
This reverts commit 419e0ac.
1 parent 415063b commit 31325f4

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

.github/ISSUE_TEMPLATE/Issue-report.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ body:
4141
options:
4242
- latest master (checkout manually)
4343
- latest development Release Candidate (RC-X)
44-
- v2.0.13
45-
- v2.0.12
4644
- v2.0.11
4745
- v2.0.10
4846
- v2.0.9

libraries/WiFi/src/WiFiClient.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ class WiFiClientRxBuffer {
158158
size_t available(){
159159
return _fill - _pos + r_available();
160160
}
161+
162+
void flush(){
163+
if(r_available()){
164+
fillBuffer();
165+
}
166+
_pos = _fill;
167+
}
161168
};
162169

163170
class WiFiClientSocketHandle {
@@ -529,26 +536,7 @@ int WiFiClient::available()
529536
// Though flushing means to send all pending data,
530537
// seems that in Arduino it also means to clear RX
531538
void WiFiClient::flush() {
532-
int res;
533-
size_t a = available(), toRead = 0;
534-
if(!a){
535-
return;//nothing to flush
536-
}
537-
uint8_t * buf = (uint8_t *)malloc(WIFI_CLIENT_FLUSH_BUFFER_SIZE);
538-
if(!buf){
539-
return;//memory error
540-
}
541-
while(a){
542-
toRead = (a>WIFI_CLIENT_FLUSH_BUFFER_SIZE)?WIFI_CLIENT_FLUSH_BUFFER_SIZE:a;
543-
res = recv(fd(), buf, toRead, MSG_DONTWAIT);
544-
if(res < 0) {
545-
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
546-
stop();
547-
break;
548-
}
549-
a -= res;
550-
}
551-
free(buf);
539+
_rxBuffer->flush();
552540
}
553541

554542
uint8_t WiFiClient::connected()

0 commit comments

Comments
 (0)