From 2559132db7294cd616ea2e6c58ce6a81f7171302 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 11 Aug 2023 23:06:16 +0700 Subject: [PATCH] Prevent nesting stop() and update for memory deallocation. --- src/client/BSSL_TCP_Client.cpp | 39 +++++++++++----------------------- src/client/BSSL_TCP_Client.h | 4 ++-- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/client/BSSL_TCP_Client.cpp b/src/client/BSSL_TCP_Client.cpp index 34a1c2d..15338e2 100644 --- a/src/client/BSSL_TCP_Client.cpp +++ b/src/client/BSSL_TCP_Client.cpp @@ -1,7 +1,7 @@ /** - * BSSL_TCP_Client v2.0.8 for Arduino devices. + * BSSL_TCP_Client v2.0.9 for Arduino devices. * - * Created August 10, 2023 + * Created August 11, 2023 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt) @@ -55,9 +55,9 @@ #if defined(USE_LIB_SSL_ENGINE) || defined(USE_EMBED_SSL_ENGINE) #include "BSSL_TCP_Client.h" -//#include -//#include -//#include +// #include +// #include +// #include #undef connect #undef write @@ -99,7 +99,8 @@ int BSSL_TCP_Client::connect(IPAddress ip, uint16_t port, int32_t timeout) if (timeout > 0) { _timeout = timeout; - _basic_client->setTimeout(_timeout); + if (_basic_client) + _basic_client->setTimeout(_timeout); _ssl_client.setTimeout(_timeout); } @@ -120,7 +121,8 @@ int BSSL_TCP_Client::connect(const char *host, uint16_t port, int32_t timeout) if (timeout > 0) { _timeout = timeout; - _basic_client->setTimeout(_timeout); + if (_basic_client) + _basic_client->setTimeout(_timeout); _ssl_client.setTimeout(_timeout); } @@ -139,15 +141,10 @@ int BSSL_TCP_Client::available() int BSSL_TCP_Client::read() { - if (!_basic_client) - return 0; - uint8_t data = -1; int res = read(&data, 1); if (res < 0) - { return res; - } return data; } @@ -227,13 +224,7 @@ size_t BSSL_TCP_Client::write(Stream &stream) { return _ssl_client.write(stream) int BSSL_TCP_Client::peek() { - if (!_basic_client) - return 0; - - if (!_basic_client->connected()) - return 0; - - return _basic_client->peek(); + return _ssl_client.peek(); } void BSSL_TCP_Client::setInsecure() @@ -261,8 +252,6 @@ bool BSSL_TCP_Client::connectSSL(const String host, uint16_t port) { return conn void BSSL_TCP_Client::stop() { - if (!_basic_client) - return; _ssl_client.stop(); } @@ -283,11 +272,7 @@ void BSSL_TCP_Client::setHandshakeTimeout(unsigned long handshake_timeout) void BSSL_TCP_Client::flush() { - if (!_basic_client) - return; - - while (available() > 0) - read(); + _ssl_client.flush(); } void BSSL_TCP_Client::setBufferSizes(int recv, int xmit) @@ -297,7 +282,7 @@ void BSSL_TCP_Client::setBufferSizes(int recv, int xmit) int BSSL_TCP_Client::availableForWrite() { return _ssl_client.availableForWrite(); }; -void BSSL_TCP_Client::setSession(BearSSL_Session *session) {_ssl_client.setSession(session);}; +void BSSL_TCP_Client::setSession(BearSSL_Session *session) { _ssl_client.setSession(session); }; void BSSL_TCP_Client::setKnownKey(const PublicKey *pk, unsigned usages) { diff --git a/src/client/BSSL_TCP_Client.h b/src/client/BSSL_TCP_Client.h index 2aa4180..736e522 100644 --- a/src/client/BSSL_TCP_Client.h +++ b/src/client/BSSL_TCP_Client.h @@ -1,7 +1,7 @@ /** - * BSSL_TCP_Client v2.0.8 for Arduino devices. + * BSSL_TCP_Client v2.0.9 for Arduino devices. * - * Created August 10, 2023 + * Created August 11, 2023 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt)