Skip to content

Commit

Permalink
Prevent nesting stop() and update for memory deallocation.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Aug 11, 2023
1 parent 9dd273d commit 2559132
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
39 changes: 12 additions & 27 deletions src/client/BSSL_TCP_Client.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -55,9 +55,9 @@
#if defined(USE_LIB_SSL_ENGINE) || defined(USE_EMBED_SSL_ENGINE)

#include "BSSL_TCP_Client.h"
//#include <lwip/sockets.h>
//#include <lwip/netdb.h>
//#include <errno.h>
// #include <lwip/sockets.h>
// #include <lwip/netdb.h>
// #include <errno.h>

#undef connect
#undef write
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
}

Expand All @@ -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)
Expand All @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/client/BSSL_TCP_Client.h
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 2559132

Please sign in to comment.