Hold QSslContext in shared_ptr
... instead of QSharedPointer. QSharedPointer performs twice as many atomic operations per pointer copy as std::shared_ptr, and this is private API, we're not bound by BC constraints, so we can port to the more efficient version. Change-Id: I2e2a02493565a7ca51c86ec0ed66b6ce7c763e41 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
90d8eaad8f
commit
93fdd88a42
@ -1459,13 +1459,13 @@ void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config
|
||||
d->channels[i].setSslConfiguration(config);
|
||||
}
|
||||
|
||||
QSharedPointer<QSslContext> QHttpNetworkConnection::sslContext()
|
||||
std::shared_ptr<QSslContext> QHttpNetworkConnection::sslContext()
|
||||
{
|
||||
Q_D(QHttpNetworkConnection);
|
||||
return d->sslContext;
|
||||
}
|
||||
|
||||
void QHttpNetworkConnection::setSslContext(QSharedPointer<QSslContext> context)
|
||||
void QHttpNetworkConnection::setSslContext(std::shared_ptr<QSslContext> context)
|
||||
{
|
||||
Q_D(QHttpNetworkConnection);
|
||||
d->sslContext = std::move(context);
|
||||
|
@ -138,8 +138,8 @@ public:
|
||||
void setSslConfiguration(const QSslConfiguration &config);
|
||||
void ignoreSslErrors(int channel = -1);
|
||||
void ignoreSslErrors(const QList<QSslError> &errors, int channel = -1);
|
||||
QSharedPointer<QSslContext> sslContext();
|
||||
void setSslContext(QSharedPointer<QSslContext> context);
|
||||
std::shared_ptr<QSslContext> sslContext();
|
||||
void setSslContext(std::shared_ptr<QSslContext> context);
|
||||
#endif
|
||||
|
||||
void preConnectFinished();
|
||||
@ -275,7 +275,7 @@ public:
|
||||
QHttpNetworkConnection::ConnectionType connectionType;
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
QSharedPointer<QSslContext> sslContext;
|
||||
std::shared_ptr<QSslContext> sslContext;
|
||||
#endif
|
||||
|
||||
QHttp2Configuration http2Parameters;
|
||||
|
@ -2995,7 +2995,7 @@ QList<QByteArray> QSslSocketPrivate::unixRootCertDirectories()
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
void QSslSocketPrivate::checkSettingSslContext(QSslSocket* socket, QSharedPointer<QSslContext> tlsContext)
|
||||
void QSslSocketPrivate::checkSettingSslContext(QSslSocket* socket, std::shared_ptr<QSslContext> tlsContext)
|
||||
{
|
||||
if (!socket)
|
||||
return;
|
||||
@ -3007,7 +3007,7 @@ void QSslSocketPrivate::checkSettingSslContext(QSslSocket* socket, QSharedPointe
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
QSharedPointer<QSslContext> QSslSocketPrivate::sslContext(QSslSocket *socket)
|
||||
std::shared_ptr<QSslContext> QSslSocketPrivate::sslContext(QSslSocket *socket)
|
||||
{
|
||||
if (!socket)
|
||||
return {};
|
||||
|
@ -130,8 +130,8 @@ public:
|
||||
Q_NETWORK_EXPORT static void pauseSocketNotifiers(QSslSocket*);
|
||||
Q_NETWORK_EXPORT static void resumeSocketNotifiers(QSslSocket*);
|
||||
// ### The 2 methods below should be made member methods once the QSslContext class is made public
|
||||
static void checkSettingSslContext(QSslSocket*, QSharedPointer<QSslContext>);
|
||||
static QSharedPointer<QSslContext> sslContext(QSslSocket *socket);
|
||||
static void checkSettingSslContext(QSslSocket*, std::shared_ptr<QSslContext>);
|
||||
static std::shared_ptr<QSslContext> sslContext(QSslSocket *socket);
|
||||
Q_NETWORK_EXPORT bool isPaused() const;
|
||||
Q_NETWORK_EXPORT void setPaused(bool p);
|
||||
bool bind(const QHostAddress &address, quint16, QAbstractSocket::BindMode) override;
|
||||
|
@ -1864,7 +1864,7 @@ TlsCryptograph::~TlsCryptograph() = default;
|
||||
|
||||
\sa sslContext()
|
||||
*/
|
||||
void TlsCryptograph::checkSettingSslContext(QSharedPointer<QSslContext> tlsContext)
|
||||
void TlsCryptograph::checkSettingSslContext(std::shared_ptr<QSslContext> tlsContext)
|
||||
{
|
||||
Q_UNUSED(tlsContext);
|
||||
}
|
||||
@ -1877,7 +1877,7 @@ void TlsCryptograph::checkSettingSslContext(QSharedPointer<QSslContext> tlsConte
|
||||
|
||||
\sa checkSettingSslContext()
|
||||
*/
|
||||
QSharedPointer<QSslContext> TlsCryptograph::sslContext() const
|
||||
std::shared_ptr<QSslContext> TlsCryptograph::sslContext() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
@ -194,8 +194,8 @@ public:
|
||||
virtual ~TlsCryptograph();
|
||||
|
||||
virtual void init(QSslSocket *q, QSslSocketPrivate *d) = 0;
|
||||
virtual void checkSettingSslContext(QSharedPointer<QSslContext> tlsContext);
|
||||
virtual QSharedPointer<QSslContext> sslContext() const;
|
||||
virtual void checkSettingSslContext(std::shared_ptr<QSslContext> tlsContext);
|
||||
virtual std::shared_ptr<QSslContext> sslContext() const;
|
||||
|
||||
virtual QList<QSslError> tlsErrors() const = 0;
|
||||
|
||||
|
@ -92,7 +92,7 @@ public:
|
||||
using BioMethod = QSharedPointer<BIO_METHOD>;
|
||||
BioMethod bioMethod;
|
||||
|
||||
using TlsContext = QSharedPointer<QSslContext>;
|
||||
using TlsContext = std::shared_ptr<QSslContext>;
|
||||
TlsContext tlsContext;
|
||||
|
||||
using TlsConnection = QSharedPointer<SSL>;
|
||||
|
@ -172,14 +172,15 @@ QSslContext::~QSslContext()
|
||||
q_SSL_SESSION_free(session);
|
||||
}
|
||||
|
||||
QSharedPointer<QSslContext> QSslContext::sharedFromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration, bool allowRootCertOnDemandLoading)
|
||||
std::shared_ptr<QSslContext> QSslContext::sharedFromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration, bool allowRootCertOnDemandLoading)
|
||||
{
|
||||
QSharedPointer<QSslContext> sslContext = QSharedPointer<QSslContext>::create();
|
||||
initSslContext(sslContext.data(), mode, configuration, allowRootCertOnDemandLoading);
|
||||
struct AccessToPrivateCtor : QSslContext {};
|
||||
std::shared_ptr<QSslContext> sslContext = std::make_shared<AccessToPrivateCtor>();
|
||||
initSslContext(sslContext.get(), mode, configuration, allowRootCertOnDemandLoading);
|
||||
return sslContext;
|
||||
}
|
||||
|
||||
QSharedPointer<QSslContext> QSslContext::sharedFromPrivateConfiguration(QSslSocket::SslMode mode, QSslConfigurationPrivate *privConfiguration,
|
||||
std::shared_ptr<QSslContext> QSslContext::sharedFromPrivateConfiguration(QSslSocket::SslMode mode, QSslConfigurationPrivate *privConfiguration,
|
||||
bool allowRootCertOnDemandLoading)
|
||||
{
|
||||
return sharedFromConfiguration(mode, privConfiguration, allowRootCertOnDemandLoading);
|
||||
|
@ -69,9 +69,9 @@ public:
|
||||
|
||||
~QSslContext();
|
||||
|
||||
static QSharedPointer<QSslContext> sharedFromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration,
|
||||
static std::shared_ptr<QSslContext> sharedFromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration,
|
||||
bool allowRootCertOnDemandLoading);
|
||||
static QSharedPointer<QSslContext> sharedFromPrivateConfiguration(QSslSocket::SslMode mode, QSslConfigurationPrivate *privConfiguration,
|
||||
static std::shared_ptr<QSslContext> sharedFromPrivateConfiguration(QSslSocket::SslMode mode, QSslConfigurationPrivate *privConfiguration,
|
||||
bool allowRootCertOnDemandLoading);
|
||||
static long setupOpenSslOptions(QSsl::SslProtocol protocol, QSsl::SslOptions sslOptions);
|
||||
|
||||
@ -103,7 +103,6 @@ public:
|
||||
|
||||
protected:
|
||||
QSslContext();
|
||||
friend class QSharedPointer<QSslContext>;
|
||||
|
||||
private:
|
||||
static void initSslContext(QSslContext* sslContext, QSslSocket::SslMode mode, const QSslConfiguration &configuration,
|
||||
|
@ -504,13 +504,13 @@ void TlsCryptographOpenSSL::init(QSslSocket *qObj, QSslSocketPrivate *dObj)
|
||||
caToFetch = QSslCertificate{};
|
||||
}
|
||||
|
||||
void TlsCryptographOpenSSL::checkSettingSslContext(QSharedPointer<QSslContext> tlsContext)
|
||||
void TlsCryptographOpenSSL::checkSettingSslContext(std::shared_ptr<QSslContext> tlsContext)
|
||||
{
|
||||
if (!sslContextPointer)
|
||||
sslContextPointer = std::move(tlsContext);
|
||||
}
|
||||
|
||||
QSharedPointer<QSslContext> TlsCryptographOpenSSL::sslContext() const
|
||||
std::shared_ptr<QSslContext> TlsCryptographOpenSSL::sslContext() const
|
||||
{
|
||||
return sslContextPointer;
|
||||
}
|
||||
|
@ -80,8 +80,8 @@ public:
|
||||
~TlsCryptographOpenSSL();
|
||||
|
||||
void init(QSslSocket *qObj, QSslSocketPrivate *dObj) override;
|
||||
void checkSettingSslContext(QSharedPointer<QSslContext> tlsContext) override;
|
||||
QSharedPointer<QSslContext> sslContext() const override;
|
||||
void checkSettingSslContext(std::shared_ptr<QSslContext> tlsContext) override;
|
||||
std::shared_ptr<QSslContext> sslContext() const override;
|
||||
|
||||
QList<QSslError> tlsErrors() const override;
|
||||
|
||||
@ -133,7 +133,7 @@ private:
|
||||
bool initSslContext();
|
||||
void destroySslContext();
|
||||
|
||||
QSharedPointer<QSslContext> sslContextPointer;
|
||||
std::shared_ptr<QSslContext> sslContextPointer;
|
||||
SSL *ssl = nullptr; // TLSTODO: RAII.
|
||||
|
||||
QList<QSslErrorEntry> errorList;
|
||||
|
Loading…
Reference in New Issue
Block a user