Browse Source

Reordered SctpTransport::shutdown() and mLower->onRecv(nullptr)

Paul-Louis Ageneau 5 years ago
parent
commit
eb09cadded
2 changed files with 13 additions and 3 deletions
  1. 5 0
      src/sctptransport.cpp
  2. 8 3
      src/transport.hpp

+ 5 - 0
src/sctptransport.cpp

@@ -194,6 +194,11 @@ SctpTransport::~SctpTransport() {
 }
 }
 
 
 bool SctpTransport::stop() {
 bool SctpTransport::stop() {
+	// Transport::stop() will unregister incoming() from the lower layer, therefore we need to make
+	// sure the thread from lower layers is not blocked in incoming() by the WrittenOnce condition.
+	mWrittenOnce = true;
+	mWrittenCondition.notify_all();
+
 	if (!Transport::stop())
 	if (!Transport::stop())
 		return false;
 		return false;
 
 

+ 8 - 3
src/transport.hpp

@@ -41,12 +41,17 @@ public:
 
 
 	virtual ~Transport() {
 	virtual ~Transport() {
 		stop();
 		stop();
-		if (mLower)
-			mLower->onRecv(nullptr); // doing it on stop could cause a deadlock
 	}
 	}
 
 
 	virtual bool stop() {
 	virtual bool stop() {
-		return !mShutdown.exchange(true);
+		if (mShutdown.exchange(true))
+			return false;
+
+		// We don't want incoming() to be called by the lower layer anymore
+		if (mLower)
+			mLower->onRecv(nullptr);
+
+		return true;
 	}
 	}
 
 
 	void registerIncoming() {
 	void registerIncoming() {