Since Qt 4.7, it is no longer necessary to manage incoming connections
manually in specializations of QTcpServer. Instead, newly created
sockets can be added to the internal queue.
-QTcpSocket* SslServer::nextPendingConnection()
-{
- if (_pendingConnections.isEmpty())
- return nullptr;
- else
- return _pendingConnections.takeFirst();
-}
-
void SslServer::incomingConnection(qintptr socketDescriptor)
{
void SslServer::incomingConnection(qintptr socketDescriptor)
{
- auto* serverSocket = new QSslSocket(this);
- if (serverSocket->setSocketDescriptor(socketDescriptor)) {
+ auto* socket = new QSslSocket(this);
+ if (socket->setSocketDescriptor(socketDescriptor)) {
- serverSocket->setLocalCertificate(_cert);
- serverSocket->setPrivateKey(_key);
- serverSocket->addCaCertificates(_ca);
+ socket->setLocalCertificate(_cert);
+ socket->setPrivateKey(_key);
+ socket->addCaCertificates(_ca);
- _pendingConnections << serverSocket;
- emit newConnection();
+ addPendingConnection(socket);
#pragma once
#include <QFile>
#pragma once
#include <QFile>
#include <QSslCertificate>
#include <QSslKey>
#include <QTcpServer>
#include <QSslCertificate>
#include <QSslKey>
#include <QTcpServer>
public:
SslServer(QObject* parent = nullptr);
public:
SslServer(QObject* parent = nullptr);
- bool hasPendingConnections() const override { return !_pendingConnections.isEmpty(); }
- QTcpSocket* nextPendingConnection() override;
-
const QSslCertificate& certificate() const { return _cert; }
const QSslKey& key() const { return _key; }
bool isCertValid() const { return _isCertValid; }
const QSslCertificate& certificate() const { return _cert; }
const QSslKey& key() const { return _key; }
bool isCertValid() const { return _isCertValid; }
MetricsServer* _metricsServer{nullptr};
MetricsServer* _metricsServer{nullptr};
- QLinkedList<QTcpSocket*> _pendingConnections;
QSslCertificate _cert;
QSslKey _key;
QList<QSslCertificate> _ca;
QSslCertificate _cert;
QSslKey _key;
QList<QSslCertificate> _ca;