esp-httpd
esp-httpd copied to clipboard
Make websocket close behave more like lwip-raw tcp
When LWIP RAW TCP connections are closed LWIP calls the data callback with a null pointer, so application code knows that socket is invalidated, and gets a chance to clear all references to it.
"If the remote host closes the connection, the callback function will be called with a NULL pbuf to indicate that fact." http://lwip.wikia.com/wiki/Raw/TCP
When a websocket connection is closed (either by the client or for conserving memory) there is no such warning. Any writes to a socket outside it's data callback, where it is guaranteed to be valid, may potentially write to a closed socket (or worse, freed).
This which limits application to a ping-pong polling scenario which, while it works lika a charm, is not exactly the spirit of websockets.