Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Provided a destructor for lwipClient
Provided a destructor that takes care of deallocating the _tcp_client
only when allocated with mem_alloc() and not passed in the constructor
  • Loading branch information
andreagilardoni committed Sep 28, 2023
commit 4ba1866fcea1b30739df00b89e1c8beddc7ef222
19 changes: 16 additions & 3 deletions libraries/lwIpWrapper/src/lwipClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {

/* -------------------------------------------------------------------------- */
lwipClient::lwipClient()
: _tcp_client(NULL)
: _tcp_client(NULL), _provided_tcp_client(false)
{
}
/* -------------------------------------------------------------------------- */
Expand All @@ -17,15 +17,28 @@ lwipClient::lwipClient()
sketches but sock is ignored. */
/* -------------------------------------------------------------------------- */
lwipClient::lwipClient(uint8_t sock)
: _tcp_client(NULL)
: _tcp_client(NULL), _provided_tcp_client(false)

{
}
/* -------------------------------------------------------------------------- */

/* -------------------------------------------------------------------------- */
lwipClient::lwipClient(struct tcp_struct* tcpClient)
: _tcp_client(tcpClient), _provided_tcp_client(true)

{
_tcp_client = tcpClient;
}
/* -------------------------------------------------------------------------- */

/* -------------------------------------------------------------------------- */
lwipClient::~lwipClient()
{
stop();

if(!_provided_tcp_client) {
mem_free(_tcp_client);
}
}
/* -------------------------------------------------------------------------- */

Expand Down
3 changes: 3 additions & 0 deletions libraries/lwIpWrapper/src/lwipClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class lwipClient : public Client {
lwipClient();
lwipClient(uint8_t sock);
lwipClient(struct tcp_struct* tcpClient);
virtual ~lwipClient();

uint8_t status();
virtual int connect(IPAddress ip, uint16_t port);
Expand Down Expand Up @@ -68,6 +69,8 @@ class lwipClient : public Client {
private:
struct tcp_struct* _tcp_client;
uint16_t _timeout = 10000;

const bool _provided_tcp_client;
};

#endif