Skip to content

Commit

Permalink
Revert 8541 wifi client fix (#267)
Browse files Browse the repository at this point in the history
* Revert "Reimplemented flush in WiFiClient"

---------

Co-authored-by: Me No Dev <[email protected]>
  • Loading branch information
Jason2866 and me-no-dev authored Oct 2, 2023
1 parent 065d492 commit 419e0ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/Issue-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ body:
options:
- latest master (checkout manually)
- latest development Release Candidate (RC-X)
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
Expand Down
28 changes: 20 additions & 8 deletions libraries/WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,6 @@ class WiFiClientRxBuffer {
size_t available(){
return _fill - _pos + r_available();
}

void flush(){
if(r_available()){
fillBuffer();
}
_pos = _fill;
}
};

class WiFiClientSocketHandle {
Expand Down Expand Up @@ -536,7 +529,26 @@ int WiFiClient::available()
// Though flushing means to send all pending data,
// seems that in Arduino it also means to clear RX
void WiFiClient::flush() {
_rxBuffer->flush();
int res;
size_t a = available(), toRead = 0;
if(!a){
return;//nothing to flush
}
uint8_t * buf = (uint8_t *)malloc(WIFI_CLIENT_FLUSH_BUFFER_SIZE);
if(!buf){
return;//memory error
}
while(a){
toRead = (a>WIFI_CLIENT_FLUSH_BUFFER_SIZE)?WIFI_CLIENT_FLUSH_BUFFER_SIZE:a;
res = recv(fd(), buf, toRead, MSG_DONTWAIT);
if(res < 0) {
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
stop();
break;
}
a -= res;
}
free(buf);
}

uint8_t WiFiClient::connected()
Expand Down

0 comments on commit 419e0ac

Please sign in to comment.