Skip to content

Commit 02c158d

Browse files
committed
fix wificlient bug
espressif#6129
1 parent d793956 commit 02c158d

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

Diff for: libraries/WiFi/src/WiFiClient.cpp

+28-20
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 {
@@ -500,26 +507,27 @@ int WiFiClient::available()
500507
// Though flushing means to send all pending data,
501508
// seems that in Arduino it also means to clear RX
502509
void WiFiClient::flush() {
503-
int res;
504-
size_t a = available(), toRead = 0;
505-
if(!a){
506-
return;//nothing to flush
507-
}
508-
uint8_t * buf = (uint8_t *)malloc(WIFI_CLIENT_FLUSH_BUFFER_SIZE);
509-
if(!buf){
510-
return;//memory error
511-
}
512-
while(a){
513-
toRead = (a>WIFI_CLIENT_FLUSH_BUFFER_SIZE)?WIFI_CLIENT_FLUSH_BUFFER_SIZE:a;
514-
res = recv(fd(), buf, toRead, MSG_DONTWAIT);
515-
if(res < 0) {
516-
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
517-
stop();
518-
break;
519-
}
520-
a -= res;
521-
}
522-
free(buf);
510+
// int res;
511+
// size_t a = available(), toRead = 0;
512+
// if(!a){
513+
// return;//nothing to flush
514+
// }
515+
// uint8_t * buf = (uint8_t *)malloc(WIFI_CLIENT_FLUSH_BUFFER_SIZE);
516+
// if(!buf){
517+
// return;//memory error
518+
// }
519+
// while(a){
520+
// toRead = (a>WIFI_CLIENT_FLUSH_BUFFER_SIZE)?WIFI_CLIENT_FLUSH_BUFFER_SIZE:a;
521+
// res = recv(fd(), buf, toRead, MSG_DONTWAIT);
522+
// if(res < 0) {
523+
// log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
524+
// stop();
525+
// break;
526+
// }
527+
// a -= res;
528+
// }
529+
// free(buf);
530+
_rxBuffer->flush();
523531
}
524532

525533
uint8_t WiFiClient::connected()

0 commit comments

Comments
 (0)