mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-15 00:02:49 +03:00
* fix #1002 ::Flush() wait for empty send buffer * WiFiClient::Flush() guarantees that the data has been delivered option 1 of https://github.com/esp8266/Arduino/pull/3967#discussion_r156901071 10ms max wait according to loaded tcp echo/reply scheme
This commit is contained in:
@ -259,7 +259,7 @@ size_t WiFiClient::peekBytes(uint8_t *buffer, size_t length) {
|
||||
void WiFiClient::flush()
|
||||
{
|
||||
if (_client)
|
||||
_client->flush();
|
||||
_client->wait_until_sent();
|
||||
}
|
||||
|
||||
void WiFiClient::stop()
|
||||
|
@ -243,8 +243,7 @@ int WiFiUDP::peek()
|
||||
|
||||
void WiFiUDP::flush()
|
||||
{
|
||||
if (_ctx)
|
||||
_ctx->flush();
|
||||
endPacket();
|
||||
}
|
||||
|
||||
IPAddress WiFiUDP::remoteIP()
|
||||
|
@ -107,7 +107,7 @@ public:
|
||||
if(this != 0) {
|
||||
DEBUGV(":ur %d\r\n", _refcnt);
|
||||
if(--_refcnt == 0) {
|
||||
flush();
|
||||
discard_received();
|
||||
close();
|
||||
if(_discard_cb) {
|
||||
_discard_cb(_discard_cb_arg, this);
|
||||
@ -277,7 +277,7 @@ public:
|
||||
return copy_size;
|
||||
}
|
||||
|
||||
void flush()
|
||||
void discard_received()
|
||||
{
|
||||
if(!_rx_buf) {
|
||||
return;
|
||||
@ -290,6 +290,22 @@ public:
|
||||
_rx_buf_offset = 0;
|
||||
}
|
||||
|
||||
void wait_until_sent()
|
||||
{
|
||||
// fix option 1 in
|
||||
// https://github.com/esp8266/Arduino/pull/3967#pullrequestreview-83451496
|
||||
// TODO: option 2
|
||||
|
||||
#define WAIT_TRIES_MS 10 // at most 10ms
|
||||
|
||||
int tries = 1+ WAIT_TRIES_MS;
|
||||
|
||||
while (state() == ESTABLISHED && tcp_sndbuf(_pcb) != TCP_SND_BUF && --tries) {
|
||||
_write_some();
|
||||
delay(1); // esp_ schedule+yield
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t state() const
|
||||
{
|
||||
if(!_pcb) {
|
||||
|
Reference in New Issue
Block a user