Skip to content

WifiClient flush() should send all data instead of clearing input (as defined in Arduino specification) #9379

Closed
@imwhocodes

Description

@imwhocodes

Related area

WiFi / Ethernet

Hardware specification

All ESP32 versions

Is your feature request related to a problem?

Arduino describe Stream::flush() as "sending all outgoing outstanding data"
https://www.arduino.cc/reference/en/language/functions/communication/stream/streamflush/

Stream is the base interface class for all IO implementations (WiFi, HarwareSerial, USBCDC, SPI, Wire)

So also in Serial arduino interface behaviour is maintained:
https://www.arduino.cc/reference/en/language/functions/communication/serial/flush/

HardwareSerial here in Esp32 is conformant too:

void HardwareSerial::flush(void)
{
uartFlush(_uart);
}

void uartFlushTxOnly(uart_t* uart, bool txOnly)
{
if(uart == NULL) {
return;
}
UART_MUTEX_LOCK();
while(!uart_ll_is_tx_idle(UART_LL_GET_HW(uart->num)));
if ( !txOnly ) {
ESP_ERROR_CHECK(uart_flush_input(uart->num));
}
UART_MUTEX_UNLOCK();
}

But then WiFiClient::flush() is still maintaining old arduino behaviour of clearing RX input:

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

This is not compliant with the Stream interface

Describe the solution you'd like

WiFiClient::flush() to actually send al outstanding data to the client to the other end without clearing the input buffer

Describe alternatives you've considered

Overloading WiFiClient class with a custom flush function

Additional context

Yes is true that original WiFiClient::flush() from arduino define a different behaviour
https://www.arduino.cc/reference/en/libraries/wifi/client.flush/
But it is also true that that documentation is both obsolete and it don't even adhere to the Stream::flush() interface from which it inherit
https://www.arduino.cc/reference/en/language/functions/communication/stream/streamflush/

I have checked existing list of Feature requests and the Contribution Guide

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions