diff --git a/src/Connection.cpp b/src/Connection.cpp index 60e862b..b9b8728 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -69,7 +69,10 @@ void TrueMQTT::Client::Impl::Connection::runRead() switch (m_state) { case State::RESOLVING: - resolve(); + if (!resolve()) + { + m_state = State::BACKOFF; + } break; case State::CONNECTING: @@ -192,7 +195,7 @@ void TrueMQTT::Client::Impl::Connection::socketError() } } -void TrueMQTT::Client::Impl::Connection::resolve() +bool TrueMQTT::Client::Impl::Connection::resolve() { m_address_current = 0; m_socket = INVALID_SOCKET; @@ -218,7 +221,7 @@ void TrueMQTT::Client::Impl::Connection::resolve() if (error != 0) { m_impl.m_error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, std::string_view(gai_strerror(error))); - return; + return false; } // Split the list of addresses in two lists, one for IPv4 and one for @@ -274,7 +277,7 @@ void TrueMQTT::Client::Impl::Connection::resolve() if (m_addresses.empty()) { m_impl.m_error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, ""); - return; + return false; } // Only change the state if no disconnect() has been requested in the mean time. @@ -282,6 +285,7 @@ void TrueMQTT::Client::Impl::Connection::resolve() { m_state = State::CONNECTING; } + return true; } bool TrueMQTT::Client::Impl::Connection::connectToAny() diff --git a/src/Connection.h b/src/Connection.h index 6b1a58c..7e647bb 100644 --- a/src/Connection.h +++ b/src/Connection.h @@ -39,7 +39,7 @@ private: // Implemented in Connection.cpp void runRead(); void runWrite(); - void resolve(); + bool resolve(); bool tryNextAddress(); void connect(addrinfo *address); bool connectToAny();