diff options
| author | 2019-10-05 21:10:12 -0400 | |
|---|---|---|
| committer | 2019-10-05 21:10:12 -0400 | |
| commit | 78fb19eb26c8814cc83c649a252b7f47bdf649a0 (patch) | |
| tree | e8f38f35e404b37d4683604cb2a826ff3f4d2f1d /src/lib/net/SecureSocket.cpp | |
| parent | 226b07c35afedc28ad1a769d6bf539e6cab320d4 (diff) | |
| parent | dff8b887edf10407f22aaab9d147948cd5491f0a (diff) | |
Update upstream source from tag 'upstream/2.3.2+dfsg'
Update to upstream version '2.3.2+dfsg'
with Debian dir da6cb58f0203c792df99a475344204697ce64812
Diffstat (limited to 'src/lib/net/SecureSocket.cpp')
| -rw-r--r-- | src/lib/net/SecureSocket.cpp | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/src/lib/net/SecureSocket.cpp b/src/lib/net/SecureSocket.cpp index 360db31..99f626e 100644 --- a/src/lib/net/SecureSocket.cpp +++ b/src/lib/net/SecureSocket.cpp @@ -83,17 +83,9 @@ SecureSocket::~SecureSocket() // take socket from multiplexer ASAP otherwise the race condition // could cause events to get called on a dead object. TCPSocket // will do this, too, but the double-call is harmless - setJob(NULL); - if (m_ssl->m_ssl != NULL) { - SSL_shutdown(m_ssl->m_ssl); + removeJob(); + freeSSLResources(); - SSL_free(m_ssl->m_ssl); - m_ssl->m_ssl = NULL; - } - if (m_ssl->m_context != NULL) { - SSL_CTX_free(m_ssl->m_context); - m_ssl->m_context = NULL; - } // removing sleep() because I have no idea why you would want to do it // ... smells of trying to cover up a bug you don't understand //ARCH->sleep(1); @@ -104,10 +96,22 @@ void SecureSocket::close() { isFatal(true); + freeSSLResources(); + TCPSocket::close(); +} - SSL_shutdown(m_ssl->m_ssl); +void SecureSocket::freeSSLResources() +{ + if (m_ssl->m_ssl != NULL) { + SSL_shutdown(m_ssl->m_ssl); + SSL_free(m_ssl->m_ssl); + m_ssl->m_ssl = NULL; + } - TCPSocket::close(); + if (m_ssl->m_context != NULL) { + SSL_CTX_free(m_ssl->m_context); + m_ssl->m_context = NULL; + } } void @@ -121,13 +125,12 @@ SecureSocket::connect(const NetworkAddress& addr) TCPSocket::connect(addr); } -ISocketMultiplexerJob* -SecureSocket::newJob() +std::unique_ptr<ISocketMultiplexerJob> SecureSocket::newJob() { // after TCP connection is established, SecureSocket will pick up // connected event and do secureConnect if (m_connected && !m_secureReady) { - return NULL; + return {}; } return TCPSocket::newJob(); @@ -136,7 +139,7 @@ SecureSocket::newJob() void SecureSocket::secureConnect() { - setJob(new TSocketMultiplexerMethodJob<SecureSocket>( + setJob(std::make_unique<TSocketMultiplexerMethodJob<SecureSocket>>( this, &SecureSocket::serviceConnect, getSocket(), isReadable(), isWritable())); } @@ -144,7 +147,7 @@ SecureSocket::secureConnect() void SecureSocket::secureAccept() { - setJob(new TSocketMultiplexerMethodJob<SecureSocket>( + setJob(std::make_unique<TSocketMultiplexerMethodJob<SecureSocket>>( this, &SecureSocket::serviceAccept, getSocket(), isReadable(), isWritable())); } @@ -736,10 +739,11 @@ SecureSocket::verifyCertFingerprint() return isValid; } -ISocketMultiplexerJob* -SecureSocket::serviceConnect(ISocketMultiplexerJob* job, - bool, bool write, bool error) +MultiplexerJobStatus SecureSocket::serviceConnect(ISocketMultiplexerJob* job, + bool read, bool write, bool error) { + (void) read; + Lock lock(&getMutex()); int status = 0; @@ -751,25 +755,28 @@ SecureSocket::serviceConnect(ISocketMultiplexerJob* job, // If status < 0, error happened if (status < 0) { - return NULL; + return {false, {}}; } // If status > 0, success if (status > 0) { sendEvent(m_events->forIDataSocket().secureConnected()); - return newJob(); + return {true, newJob()}; } // Retry case - return new TSocketMultiplexerMethodJob<SecureSocket>( + return { + true, + std::make_unique<TSocketMultiplexerMethodJob<SecureSocket>>( this, &SecureSocket::serviceConnect, - getSocket(), isReadable(), isWritable()); + getSocket(), isReadable(), isWritable()) + }; } -ISocketMultiplexerJob* -SecureSocket::serviceAccept(ISocketMultiplexerJob* job, - bool, bool write, bool error) +MultiplexerJobStatus SecureSocket::serviceAccept(ISocketMultiplexerJob* job, + bool read, bool write, bool error) { + (void) read; Lock lock(&getMutex()); int status = 0; @@ -780,19 +787,19 @@ SecureSocket::serviceAccept(ISocketMultiplexerJob* job, #endif // If status < 0, error happened if (status < 0) { - return NULL; + return {false, {}}; } // If status > 0, success if (status > 0) { sendEvent(m_events->forClientListener().accepted()); - return newJob(); + return {true, newJob()}; } // Retry case - return new TSocketMultiplexerMethodJob<SecureSocket>( + return {true, std::make_unique<TSocketMultiplexerMethodJob<SecureSocket>>( this, &SecureSocket::serviceAccept, - getSocket(), isReadable(), isWritable()); + getSocket(), isReadable(), isWritable())}; } void |
