Skip to content

Commit 419e0ac

Browse files
Jason2866me-no-dev
andauthored
Revert 8541 wifi client fix (#267)
* Revert "Reimplemented flush in WiFiClient" --------- Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
1 parent 065d492 commit 419e0ac

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

.github/ISSUE_TEMPLATE/Issue-report.yml

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ body:
4141
options:
4242
- latest master (checkout manually)
4343
- latest development Release Candidate (RC-X)
44+
- v2.0.13
45+
- v2.0.12
4446
- v2.0.11
4547
- v2.0.10
4648
- v2.0.9

libraries/WiFi/src/WiFiClient.cpp

+20-8
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,6 @@ 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-
}
168161
};
169162

170163
class WiFiClientSocketHandle {
@@ -536,7 +529,26 @@ int WiFiClient::available()
536529
// Though flushing means to send all pending data,
537530
// seems that in Arduino it also means to clear RX
538531
void WiFiClient::flush() {
539-
_rxBuffer->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);
540552
}
541553

542554
uint8_t WiFiClient::connected()

0 commit comments

Comments
 (0)