diff --git a/src/Connection.cpp b/src/Connection.cpp index 4abc4d2..875fb41 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -107,6 +107,12 @@ void TrueMQTT::Client::Impl::Connection::runRead() case State::SOCKET_ERROR: m_state = State::BACKOFF; m_impl.connectionStateChange(false); + + // Clear send-queue, as we can't send anything anymore. + { + std::scoped_lock lock(m_send_queue_mutex); + m_send_queue.clear(); + } break; case State::STOP: @@ -166,7 +172,7 @@ void TrueMQTT::Client::Impl::Connection::runWrite() default: // Sleep for a bit to avoid hogging the CPU. - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); break; } } diff --git a/src/Packet.cpp b/src/Packet.cpp index ed85892..683bb92 100644 --- a/src/Packet.cpp +++ b/src/Packet.cpp @@ -362,7 +362,7 @@ bool TrueMQTT::Client::Impl::Connection::sendConnect() packet.write_string(m_impl.m_last_will_message); } - return send(std::move(packet)); + return send(std::move(packet), true); } bool TrueMQTT::Client::Impl::Connection::sendPingRequest()