From 8fe38882bd1ab452f9f5b3e5de6eba3a65d997e3 Mon Sep 17 00:00:00 2001 From: slaff Date: Tue, 14 Nov 2017 08:36:26 +0100 Subject: [PATCH] Allow immediate server deletion if there are no active connections. (#1285) --- Sming/SmingCore/Network/TcpServer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sming/SmingCore/Network/TcpServer.cpp b/Sming/SmingCore/Network/TcpServer.cpp index 32362f2d70..f8deae3ff0 100644 --- a/Sming/SmingCore/Network/TcpServer.cpp +++ b/Sming/SmingCore/Network/TcpServer.cpp @@ -50,6 +50,7 @@ TcpServer::TcpServer(TcpClientDataDelegate clientReceiveDataHandler) TcpServer::~TcpServer() { + debugf("Server is destroyed."); } TcpConnection* TcpServer::createClient(tcp_pcb *clientTcp) @@ -258,6 +259,11 @@ void TcpServer::shutdown() tcp = NULL; } + if(!connections.count()) { + delete this; + return; + } + for(int i=0; i < connections.count(); i++) { TcpConnection* connection = connections[i]; if(connection == NULL) { @@ -278,7 +284,6 @@ void TcpServer::onClientDestroy(TcpConnection& connection) } if(connections.count() == 0) { - debugf("Server is destroyed."); delete this; } }