How getting immediate alert when TCP connection is closed ?
Posted: Thu Jan 25, 2018 2:22 pm
The ESP32 runs as a listening TCP server. Each received 256 Byte packet is sent via the UART with 9600 Baud. Everything works nicely.
Because the UART speed it slow the ESP32 queues further incoming TCP data until its rcv-buffer is filled, only then the TCP-sender slows down.
If now the TCP connection gets prematurely closed, recv() still continues getting data from the queue until the rcv-buffer gets empty. Only then recv() returns -1 telling that the connection is closed. This is way too late.
Apparenty the close-info is also stored in the rcv-buffer.
I need an immediate way to find out if a connection got terminated, without waiting until recv() has read out the entire rcv-buffer. I checked errno, but that only reflects the rcv-buffer content, not the current socket state.
Is there any way to check the current socket state, or get a disconnected event?
Because the UART speed it slow the ESP32 queues further incoming TCP data until its rcv-buffer is filled, only then the TCP-sender slows down.
If now the TCP connection gets prematurely closed, recv() still continues getting data from the queue until the rcv-buffer gets empty. Only then recv() returns -1 telling that the connection is closed. This is way too late.
Apparenty the close-info is also stored in the rcv-buffer.
I need an immediate way to find out if a connection got terminated, without waiting until recv() has read out the entire rcv-buffer. I checked errno, but that only reflects the rcv-buffer content, not the current socket state.
Is there any way to check the current socket state, or get a disconnected event?