Remove SSL_accept locking for OpenSSL 1.0 and later.

This commit is contained in:
Christopher Kohlhoff 2016-08-29 09:51:55 +10:00
parent a9fa5bf248
commit 37d0d474f2
2 changed files with 8 additions and 0 deletions

View File

@ -115,9 +115,11 @@ private:
ASIO_DECL static int verify_callback_function( ASIO_DECL static int verify_callback_function(
int preverified, X509_STORE_CTX* ctx); int preverified, X509_STORE_CTX* ctx);
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
// The SSL_accept function may not be thread safe. This mutex is used to // The SSL_accept function may not be thread safe. This mutex is used to
// protect all calls to the SSL_accept function. // protect all calls to the SSL_accept function.
ASIO_DECL static asio::detail::static_mutex& accept_mutex(); ASIO_DECL static asio::detail::static_mutex& accept_mutex();
#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
// Perform one operation. Returns >= 0 on success or error, want_read if the // Perform one operation. Returns >= 0 on success or error, want_read if the
// operation needs more input, or want_write if it needs to write some output // operation needs more input, or want_write if it needs to write some output

View File

@ -40,7 +40,9 @@ engine::engine(SSL_CTX* context)
asio::detail::throw_error(ec, "engine"); asio::detail::throw_error(ec, "engine");
} }
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
accept_mutex().init(); accept_mutex().init();
#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
::SSL_set_mode(ssl_, SSL_MODE_ENABLE_PARTIAL_WRITE); ::SSL_set_mode(ssl_, SSL_MODE_ENABLE_PARTIAL_WRITE);
::SSL_set_mode(ssl_, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); ::SSL_set_mode(ssl_, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
@ -215,11 +217,13 @@ const asio::error_code& engine::map_error_code(
return ec; return ec;
} }
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
asio::detail::static_mutex& engine::accept_mutex() asio::detail::static_mutex& engine::accept_mutex()
{ {
static asio::detail::static_mutex mutex = ASIO_STATIC_MUTEX_INIT; static asio::detail::static_mutex mutex = ASIO_STATIC_MUTEX_INIT;
return mutex; return mutex;
} }
#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
engine::want engine::perform(int (engine::* op)(void*, std::size_t), engine::want engine::perform(int (engine::* op)(void*, std::size_t),
void* data, std::size_t length, asio::error_code& ec, void* data, std::size_t length, asio::error_code& ec,
@ -278,7 +282,9 @@ engine::want engine::perform(int (engine::* op)(void*, std::size_t),
int engine::do_accept(void*, std::size_t) int engine::do_accept(void*, std::size_t)
{ {
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
asio::detail::static_mutex::scoped_lock lock(accept_mutex()); asio::detail::static_mutex::scoped_lock lock(accept_mutex());
#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
return ::SSL_accept(ssl_); return ::SSL_accept(ssl_);
} }