Description
In esp-idf 4.2
(https://github.com/espressif/esp-idf/tree/v4.2), I have some troubles when I send data to a wifi client in UDP: espressif/esp-idf#6852
If the client is disconnected, sendto
always (or almost) return ENOMEM
.
In esp-idf 4.2
, the version of esp32-wifi-lib
is: https://github.com/espressif/esp32-wifi-lib/tree/8075af8. I found that the ENOMEM
is the error returned by esp_wifi_internal_tx_by_ref
(ESP_ERR_NO_MEM
).
- Why return
ESP_ERR_NO_MEM
when a client is disconnected ?
I understand that, even in UDP, as the physical layer is Wi-Fi, an ACK is required (https://en.wikipedia.org/wiki/Distributed_coordination_function). So why return a no memory error
and not just a timeout or another error like that ?
- When we need to send a lot of data, we continue to try to send data while
sendto
returnENOMEM
. Like in your example: https://github.com/espressif/esp-idf/blob/v4.2/examples/wifi/iperf/components/iperf/iperf.c#L290 .
As ENOMEM
is always returned when the device is disconnected, it adds a lot of delay if we process like that.
(And if we don't process like that, the throughput isn't respected and we can't send all our data in time...).
- What's is your advice to detect properly a disconnection ?
My example code is available in the esp-idf ticket: espressif/esp-idf#6852