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

+ 4 - 5
src/impl/dtlstransport.cpp

@@ -489,15 +489,14 @@ bool DtlsTransport::send(message_ptr message) {
 
 	PLOG_VERBOSE << "Send size=" << message->size();
 
-	int ret;
 	{
 		std::lock_guard lock(mSslMutex);
 		mCurrentDscp = message->dscp;
-		ret = SSL_write(mSsl, message->data(), int(message->size()));
-	}
+		int ret = SSL_write(mSsl, message->data(), int(message->size()));
 
-	if (!openssl::check(mSsl, ret))
-		return false;
+		if (!openssl::check(mSsl, ret))
+			return false;
+	}
 
 	return mOutgoingResult;
 }

+ 4 - 7
src/impl/tlstransport.cpp

@@ -405,12 +405,10 @@ bool TlsTransport::send(message_ptr message) {
 
 	std::lock_guard lock(mSslMutex);
 	int ret = SSL_write(mSsl, message->data(), int(message->size()));
-	bool result = flushOutput();
-
 	if (!openssl::check(mSsl, ret))
 		throw std::runtime_error("TLS send failed");
 
-	return result;
+	return flushOutput();
 }
 
 void TlsTransport::incoming(message_ptr message) {
@@ -443,11 +441,10 @@ void TlsTransport::runRecvLoop() {
 				{
 					std::lock_guard lock(mSslMutex);
 					int ret = SSL_do_handshake(mSsl);
-					flushOutput();
-
 					if (!openssl::check(mSsl, ret, "Handshake failed"))
 						break;
 
+					flushOutput();
 					finished = (SSL_is_init_finished(mSsl) != 0);
 				}
 
@@ -463,10 +460,10 @@ void TlsTransport::runRecvLoop() {
 				{
 					std::lock_guard lock(mSslMutex);
 					ret = SSL_read(mSsl, buffer, bufferSize);
-					flushOutput(); // SSL_read() can also cause write operations
-
 					if (!openssl::check(mSsl, ret))
 						break;
+
+					flushOutput(); // SSL_read() can also cause write operations
 				}
 
 				if (ret > 0) {