QSslContext: provide sharedFromConfiguration()
It's a version of fromConfiguration() that returns the QSslContext instance in a shared instead of a naked pointer. Use it in QSslSocketBackend. The idea here, of course, is to use QSharedPointer<T>::create(), which co-locates the refcount with the payload in a single memory allocation, instead of QSharedPointer<T>(new T), which causes two allocations. Change-Id: Ia5396fb3b291f2912fca5cd97e0aa1e45e065e55 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
d6bb01e177
commit
a63a506d54
@ -375,6 +375,13 @@ QSslContext* QSslContext::fromConfiguration(QSslSocket::SslMode mode, const QSsl
|
||||
return sslContext;
|
||||
}
|
||||
|
||||
QSharedPointer<QSslContext> QSslContext::sharedFromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration, bool allowRootCertOnDemandLoading)
|
||||
{
|
||||
QSharedPointer<QSslContext> sslContext = QSharedPointer<QSslContext>::create();
|
||||
initSslContext(sslContext.data(), mode, configuration, allowRootCertOnDemandLoading);
|
||||
return sslContext;
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x1000100fL && !defined(OPENSSL_NO_NEXTPROTONEG)
|
||||
|
||||
static int next_proto_cb(SSL *, unsigned char **out, unsigned char *outlen,
|
||||
|
@ -72,6 +72,8 @@ public:
|
||||
|
||||
static QSslContext* fromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration,
|
||||
bool allowRootCertOnDemandLoading);
|
||||
static QSharedPointer<QSslContext> sharedFromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration,
|
||||
bool allowRootCertOnDemandLoading);
|
||||
|
||||
QSslError::SslError error() const;
|
||||
QString errorString() const;
|
||||
@ -99,6 +101,7 @@ public:
|
||||
|
||||
protected:
|
||||
QSslContext();
|
||||
friend class QSharedPointer<QSslContext>;
|
||||
|
||||
private:
|
||||
static void initSslContext(QSslContext* sslContext, QSslSocket::SslMode mode, const QSslConfiguration &configuration,
|
||||
|
@ -360,8 +360,7 @@ bool QSslSocketBackendPrivate::initSslContext()
|
||||
// create a deep copy of our configuration
|
||||
QSslConfigurationPrivate *configurationCopy = new QSslConfigurationPrivate(configuration);
|
||||
configurationCopy->ref.store(0); // the QSslConfiguration constructor refs up
|
||||
sslContextPointer = QSharedPointer<QSslContext>(
|
||||
QSslContext::fromConfiguration(mode, configurationCopy, allowRootCertOnDemandLoading));
|
||||
sslContextPointer = QSslContext::sharedFromConfiguration(mode, configurationCopy, allowRootCertOnDemandLoading);
|
||||
}
|
||||
|
||||
if (sslContextPointer->error() != QSslError::NoError) {
|
||||
|
Loading…
Reference in New Issue
Block a user