Skip to content

Commit

Permalink
Merge pull request #949 from andreagilardoni/client-fixes
Browse files Browse the repository at this point in the history
enforcing stop() when calling connect a second time
  • Loading branch information
pennam authored Oct 2, 2024
2 parents 06ed4f5 + 97b6f59 commit 22e6d91
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions libraries/SocketWrapper/src/MbedClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 22e6d91

Please sign in to comment.