Merge pull request #8541 from PilnyTomas/WiFiClient_fix
Reimplemented flush in WiFiClient
This commit is contained in:
commit
505797ca50
1 changed files with 8 additions and 20 deletions
|
|
@ -153,6 +153,13 @@ public:
|
|||
size_t available(){
|
||||
return _fill - _pos + r_available();
|
||||
}
|
||||
|
||||
void flush(){
|
||||
if(r_available()){
|
||||
fillBuffer();
|
||||
}
|
||||
_pos = _fill;
|
||||
}
|
||||
};
|
||||
|
||||
class WiFiClientSocketHandle {
|
||||
|
|
@ -501,26 +508,7 @@ int WiFiClient::available()
|
|||
// Though flushing means to send all pending data,
|
||||
// seems that in Arduino it also means to clear RX
|
||||
void WiFiClient::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);
|
||||
_rxBuffer->flush();
|
||||
}
|
||||
|
||||
uint8_t WiFiClient::connected()
|
||||
|
|
|
|||
Loading…
Reference in a new issue