From 6715ab274fe13b91d4ee4905d2fcce8a395304dd Mon Sep 17 00:00:00 2001 From: mikee47 Date: Fri, 29 Mar 2024 10:28:52 +0000 Subject: [PATCH] WebsocketConnection not getting destroyed HttpConnection is NOT auto-self-destruct so we need to change that during closure. --- .../src/Network/Http/Websocket/WebsocketConnection.cpp | 3 ++- Sming/Components/Network/src/Network/TcpConnection.h | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp b/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp index fb1945d87d..3ed043b313 100644 --- a/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp +++ b/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp @@ -291,7 +291,7 @@ void WebsocketConnection::broadcast(const char* message, size_t length, ws_frame void WebsocketConnection::close() { - debug_d("Terminating Websocket connection."); + debug_d("WS: Terminating connection %p", connection); websocketList.removeElement(this); if(state != eWSCS_Closed) { state = eWSCS_Closed; @@ -307,6 +307,7 @@ void WebsocketConnection::close() if(connection) { connection->setTimeOut(2); + connection->setAutoSelfDestruct(true); connection = nullptr; } } diff --git a/Sming/Components/Network/src/Network/TcpConnection.h b/Sming/Components/Network/src/Network/TcpConnection.h index d2f023df2f..3ea5367418 100644 --- a/Sming/Components/Network/src/Network/TcpConnection.h +++ b/Sming/Components/Network/src/Network/TcpConnection.h @@ -50,11 +50,15 @@ class TcpConnection : public IpConnection virtual ~TcpConnection(); -public: virtual bool connect(const String& server, int port, bool useSsl = false); virtual bool connect(IpAddress addr, uint16_t port, bool useSsl = false); virtual void close(); + void setAutoSelfDestruct(bool state) + { + autoSelfDestruct = state; + } + /** @brief Writes string data directly to the TCP buffer * @param data null terminated string * @param apiflags TCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE