From 97b6f592c3969a54d754b5e7fe69544fdfc1665e Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 28 Aug 2024 11:37:25 +0200 Subject: [PATCH] enforcing stop() when calling connect a second time --- libraries/SocketWrapper/src/MbedClient.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libraries/SocketWrapper/src/MbedClient.cpp b/libraries/SocketWrapper/src/MbedClient.cpp index ad74db1ca..f50ff18b7 100644 --- a/libraries/SocketWrapper/src/MbedClient.cpp +++ b/libraries/SocketWrapper/src/MbedClient.cpp @@ -80,14 +80,8 @@ void arduino::MbedClient::configureSocket(Socket *_s) { } int arduino::MbedClient::connect(SocketAddress socketAddress) { - - if (sock && reader_th) { - // trying to reuse a connection, let's call stop() to cleanup the state - char c; - if (sock->recv(&c, 1) < 0) { - stop(); - } - } + // if a connection is aready ongoing, a disconnection must be enforced before starting another one + stop(); if (sock == nullptr) { sock = new TCPSocket(); @@ -135,6 +129,9 @@ int arduino::MbedClient::connect(const char *host, uint16_t port) { } int arduino::MbedClient::connectSSL(SocketAddress socketAddress) { + // if a connection is aready ongoing, a disconnection must be enforced before starting another one + stop(); + if (sock == nullptr) { sock = new TLSSocket(); _own_socket = true;