From b6aa0845291a5f7038d0e2254b4ccd19231e40b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 4 Sep 2017 01:27:27 +0200 Subject: [PATCH] Fix telnet connection dropping --- code/espurna/telnet.ino | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/code/espurna/telnet.ino b/code/espurna/telnet.ino index c400852c..1e984613 100644 --- a/code/espurna/telnet.ino +++ b/code/espurna/telnet.ino @@ -21,8 +21,8 @@ AsyncClient * _telnetClients[TELNET_MAX_CLIENTS]; void _telnetDisconnect(unsigned char clientId) { _telnetClients[clientId]->free(); - delete(_telnetClients[clientId]); - _telnetClients[clientId] = 0; + _telnetClients[clientId] = NULL; + delete _telnetClients[clientId]; DEBUG_MSG_P(PSTR("[TELNET] Client #%d disconnected\n"), clientId); } @@ -57,14 +57,15 @@ void _telnetData(unsigned char clientId, void *data, size_t len) { void _telnetNewClient(AsyncClient *client) { - client->onDisconnect([](void *s, AsyncClient *c) { - delete(c); - }); - #if TELNET_ONLY_AP if (client->localIP() != WiFi.softAPIP()) { DEBUG_MSG_P(PSTR("[TELNET] Rejecting - Only local connections\n")); - client->stop(); + client->onDisconnect([](void *s, AsyncClient *c) { + c->free(); + delete c; + }); + client->close(true); + return; } #endif @@ -97,10 +98,15 @@ void _telnetNewClient(AsyncClient *client) { return; } + } DEBUG_MSG_P(PSTR("[TELNET] Rejecting - Too many connections\n")); - client->stop(); + client->onDisconnect([](void *s, AsyncClient *c) { + c->free(); + delete c; + }); + client->close(true); }