Commit e79fa3867f061c1103b3d8bf040663a2c6aecbbe

Authored by Patric Stout
1 parent 0e4d5005

fix(connection): clear the send-queue on socket-error

Otherwise, on reconnect a whole bunch of older samples are sent
out.
src/Connection.cpp
... ... @@ -107,6 +107,12 @@ void TrueMQTT::Client::Impl::Connection::runRead()
107 107 case State::SOCKET_ERROR:
108 108 m_state = State::BACKOFF;
109 109 m_impl.connectionStateChange(false);
  110 +
  111 + // Clear send-queue, as we can't send anything anymore.
  112 + {
  113 + std::scoped_lock lock(m_send_queue_mutex);
  114 + m_send_queue.clear();
  115 + }
110 116 break;
111 117  
112 118 case State::STOP:
... ... @@ -166,7 +172,7 @@ void TrueMQTT::Client::Impl::Connection::runWrite()
166 172  
167 173 default:
168 174 // Sleep for a bit to avoid hogging the CPU.
169   - std::this_thread::sleep_for(std::chrono::milliseconds(1));
  175 + std::this_thread::sleep_for(std::chrono::milliseconds(100));
170 176 break;
171 177 }
172 178 }
... ...
src/Packet.cpp
... ... @@ -362,7 +362,7 @@ bool TrueMQTT::Client::Impl::Connection::sendConnect()
362 362 packet.write_string(m_impl.m_last_will_message);
363 363 }
364 364  
365   - return send(std::move(packet));
  365 + return send(std::move(packet), true);
366 366 }
367 367  
368 368 bool TrueMQTT::Client::Impl::Connection::sendPingRequest()
... ...