Browse Source

Unregister transport recv callback on destruction instead of on stop

Paul-Louis Ageneau 5 years ago
parent
commit
d0f91d5cf4
1 changed files with 5 additions and 3 deletions
  1. 5 3
      src/transport.hpp

+ 5 - 3
src/transport.hpp

@@ -33,11 +33,13 @@ using namespace std::placeholders;
 class Transport {
 public:
 	Transport(std::shared_ptr<Transport> lower = nullptr) : mLower(std::move(lower)) {}
-	virtual ~Transport() { stop(); }
+	virtual ~Transport() {
+		stop();
+		if (mLower)
+			mLower->onRecv(nullptr); // doing it on stop could cause a deadlock
+	}
 
 	virtual bool stop() {
-		if (mLower)
-			mLower->onRecv(nullptr);
 		return !mShutdown.exchange(true);
 	}