Browse Source

Fixed OpenSSL recv loop quitting too early

Paul-Louis Ageneau 4 years ago
parent
commit
458decb12d
2 changed files with 8 additions and 3 deletions
  1. 6 0
      include/rtc/queue.hpp
  2. 2 3
      src/dtlstransport.cpp

+ 6 - 0
include/rtc/queue.hpp

@@ -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();

+ 2 - 3
src/dtlstransport.cpp

@@ -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();