Browse Source

Call SSL_shutdown() on clean close only and synchronize it properly

Paul-Louis Ageneau 2 years ago
parent
commit
dba71f8060
2 changed files with 7 additions and 2 deletions
  1. 4 1
      src/impl/dtlstransport.cpp
  2. 3 1
      src/impl/tlstransport.cpp

+ 4 - 1
src/impl/dtlstransport.cpp

@@ -479,7 +479,6 @@ void DtlsTransport::stop() {
 	unregisterIncoming();
 	unregisterIncoming();
 	mIncomingQueue.stop();
 	mIncomingQueue.stop();
 	mRecvThread.join();
 	mRecvThread.join();
-	SSL_shutdown(mSsl);
 }
 }
 
 
 bool DtlsTransport::send(message_ptr message) {
 bool DtlsTransport::send(message_ptr message) {
@@ -624,6 +623,10 @@ void DtlsTransport::runRecvLoop() {
 
 
 			mIncomingQueue.wait(duration);
 			mIncomingQueue.wait(duration);
 		}
 		}
+
+		std::lock_guard lock(mSslMutex);
+		SSL_shutdown(mSsl);
+
 	} catch (const std::exception &e) {
 	} catch (const std::exception &e) {
 		PLOG_ERROR << "DTLS recv: " << e.what();
 		PLOG_ERROR << "DTLS recv: " << e.what();
 	}
 	}

+ 3 - 1
src/impl/tlstransport.cpp

@@ -391,7 +391,6 @@ void TlsTransport::stop() {
 	unregisterIncoming();
 	unregisterIncoming();
 	mIncomingQueue.stop();
 	mIncomingQueue.stop();
 	mRecvThread.join();
 	mRecvThread.join();
-	SSL_shutdown(mSsl);
 }
 }
 
 
 bool TlsTransport::send(message_ptr message) {
 bool TlsTransport::send(message_ptr message) {
@@ -483,6 +482,9 @@ void TlsTransport::runRecvLoop() {
 				recv(message); // Pass zero-sized messages through
 				recv(message); // Pass zero-sized messages through
 		}
 		}
 
 
+		std::lock_guard lock(mSslMutex);
+		SSL_shutdown(mSsl);
+
 	} catch (const std::exception &e) {
 	} catch (const std::exception &e) {
 		PLOG_ERROR << "TLS recv: " << e.what();
 		PLOG_ERROR << "TLS recv: " << e.what();
 	}
 	}