Skip to content

Commit

Permalink
Force socket closing upon connection error so next try can be perform…
Browse files Browse the repository at this point in the history
…ed without destructing the client.
  • Loading branch information
X-Ryl669 committed Aug 12, 2024
1 parent 986a7f8 commit a56244b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/src/Network/Clients/MQTTClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,10 @@ namespace Network { namespace Client {

// Check we can contact the server and connect to it (not initial write to the server is required here)
if (int ret = impl->connectWith(serverHost, port, useTLS))
{
impl->close();
return ret == -7 ? ErrorType::TimedOut : ErrorType::NetworkError;
}

// Create the header object now
impl->keepAlive = (keepAliveTimeInSec + (keepAliveTimeInSec / 2)) / 2; // Make it 75% of what's given so we always wake up before doom's clock
Expand All @@ -1212,7 +1215,10 @@ namespace Network { namespace Client {

// Ok, setting are done, let's build this packet now
if (ErrorType ret = prepareSAR(packet))
{
impl->close();
return ret;
}

// Then extract the packet type
Protocol::MQTT::V5::ControlPacketType type = impl->getLastPacketType();
Expand Down

0 comments on commit a56244b

Please sign in to comment.