@@ -153,6 +153,13 @@ class WiFiClientRxBuffer {
153
153
size_t available (){
154
154
return _fill - _pos + r_available ();
155
155
}
156
+
157
+ void flush (){
158
+ if (r_available ()){
159
+ fillBuffer ();
160
+ }
161
+ _pos = _fill;
162
+ }
156
163
};
157
164
158
165
class WiFiClientSocketHandle {
@@ -500,26 +507,27 @@ int WiFiClient::available()
500
507
// Though flushing means to send all pending data,
501
508
// seems that in Arduino it also means to clear RX
502
509
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 ();
523
531
}
524
532
525
533
uint8_t WiFiClient::connected ()
0 commit comments