Fixed OpenSSL recv loop quitting too early

This commit is contained in:
Paul-Louis Ageneau
2020-09-27 23:53:35 +02:00
parent 635c2e5513
commit 458decb12d
2 changed files with 8 additions and 3 deletions

View File

@ -38,6 +38,7 @@ public:
~Queue();
void stop();
bool running() const;
bool empty() const;
bool full() const;
size_t size() const; // elements
@ -80,6 +81,11 @@ template <typename T> void Queue<T>::stop() {
mPushCondition.notify_all();
}
template <typename T> bool Queue<T>::running() const {
std::lock_guard lock(mMutex);
return !mQueue.empty() || !mStopping;
}
template <typename T> bool Queue<T>::empty() const {
std::lock_guard lock(mMutex);
return mQueue.empty();

View File

@ -435,7 +435,7 @@ void DtlsTransport::runRecvLoop() {
const size_t bufferSize = maxMtu;
byte buffer[bufferSize];
while (true) {
while (mIncomingQueue.running()) {
// Process pending messages
while (auto next = mIncomingQueue.tryPop()) {
message_ptr message = std::move(*next);
@ -492,8 +492,7 @@ void DtlsTransport::runRecvLoop() {
}
}
if (!mIncomingQueue.wait(duration))
break; // queue is stopped
mIncomingQueue.wait(duration);
}
} catch (const std::exception &e) {
PLOG_ERROR << "DTLS recv: " << e.what();