Commit 5c834f640072f8ed9ea2311c0b8718ffdaf6a33e

Authored by Patric Stout
1 parent 0647a241

fix(connection): there is no back-off for resolving that fails

In results, it was trying to resolve very often.
src/Connection.cpp
... ... @@ -69,7 +69,10 @@ void TrueMQTT::Client::Impl::Connection::runRead()
69 69 switch (m_state)
70 70 {
71 71 case State::RESOLVING:
72   - resolve();
  72 + if (!resolve())
  73 + {
  74 + m_state = State::BACKOFF;
  75 + }
73 76 break;
74 77  
75 78 case State::CONNECTING:
... ... @@ -192,7 +195,7 @@ void TrueMQTT::Client::Impl::Connection::socketError()
192 195 }
193 196 }
194 197  
195   -void TrueMQTT::Client::Impl::Connection::resolve()
  198 +bool TrueMQTT::Client::Impl::Connection::resolve()
196 199 {
197 200 m_address_current = 0;
198 201 m_socket = INVALID_SOCKET;
... ... @@ -218,7 +221,7 @@ void TrueMQTT::Client::Impl::Connection::resolve()
218 221 if (error != 0)
219 222 {
220 223 m_impl.m_error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, std::string_view(gai_strerror(error)));
221   - return;
  224 + return false;
222 225 }
223 226  
224 227 // Split the list of addresses in two lists, one for IPv4 and one for
... ... @@ -274,7 +277,7 @@ void TrueMQTT::Client::Impl::Connection::resolve()
274 277 if (m_addresses.empty())
275 278 {
276 279 m_impl.m_error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, "");
277   - return;
  280 + return false;
278 281 }
279 282  
280 283 // Only change the state if no disconnect() has been requested in the mean time.
... ... @@ -282,6 +285,7 @@ void TrueMQTT::Client::Impl::Connection::resolve()
282 285 {
283 286 m_state = State::CONNECTING;
284 287 }
  288 + return true;
285 289 }
286 290  
287 291 bool TrueMQTT::Client::Impl::Connection::connectToAny()
... ...
src/Connection.h
... ... @@ -39,7 +39,7 @@ private:
39 39 // Implemented in Connection.cpp
40 40 void runRead();
41 41 void runWrite();
42   - void resolve();
  42 + bool resolve();
43 43 bool tryNextAddress();
44 44 void connect(addrinfo *address);
45 45 bool connectToAny();
... ...