summaryrefslogtreecommitdiffstats
path: root/examples/network
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-07-11 17:17:13 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-07-11 17:17:51 +0200
commit4dac45c9ee59ff6586d90d423654da91523ab679 (patch)
treecd4a4adf2cbc9e77bf86d2d11e71ec66afdf3be4 /examples/network
parent078cd61751aeaa310d35a3d596a21a36004a1a0f (diff)
parentf44850b5c3464cdda0ee9b1ee858d95f3ffaa3e2 (diff)
Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/downloadmanager/downloadmanager.cpp4
-rw-r--r--examples/network/downloadmanager/downloadmanager.h2
-rw-r--r--examples/network/secureudpserver/server.cpp23
-rw-r--r--examples/network/secureudpserver/server.h8
-rw-r--r--examples/network/torrent/ratecontroller.cpp4
-rw-r--r--examples/network/torrent/ratecontroller.h4
6 files changed, 22 insertions, 23 deletions
diff --git a/examples/network/downloadmanager/downloadmanager.cpp b/examples/network/downloadmanager/downloadmanager.cpp
index e820b4ff70..9e0c03c6af 100644
--- a/examples/network/downloadmanager/downloadmanager.cpp
+++ b/examples/network/downloadmanager/downloadmanager.cpp
@@ -132,7 +132,7 @@ void DownloadManager::startNextDownload()
// prepare the output
printf("Downloading %s...\n", url.toEncoded().constData());
- downloadTime.start();
+ downloadTimer.start();
}
void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
@@ -140,7 +140,7 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
progressBar.setStatus(bytesReceived, bytesTotal);
// calculate the download speed
- double speed = bytesReceived * 1000.0 / downloadTime.elapsed();
+ double speed = bytesReceived * 1000.0 / downloadTimer.elapsed();
QString unit;
if (speed < 1024) {
unit = "bytes/sec";
diff --git a/examples/network/downloadmanager/downloadmanager.h b/examples/network/downloadmanager/downloadmanager.h
index 4bc6351ff9..818a774f1f 100644
--- a/examples/network/downloadmanager/downloadmanager.h
+++ b/examples/network/downloadmanager/downloadmanager.h
@@ -83,7 +83,7 @@ private:
QQueue<QUrl> downloadQueue;
QNetworkReply *currentDownload = nullptr;
QFile output;
- QTime downloadTime;
+ QElapsedTimer downloadTimer;
TextProgressBar progressBar;
int downloadedCount = 0;
diff --git a/examples/network/secureudpserver/server.cpp b/examples/network/secureudpserver/server.cpp
index 0d83fa9b51..450eb9e68d 100644
--- a/examples/network/secureudpserver/server.cpp
+++ b/examples/network/secureudpserver/server.cpp
@@ -62,7 +62,7 @@ QString peer_info(const QHostAddress &address, quint16 port)
return info.arg(address.toString()).arg(port);
}
-QString connection_info(QSharedPointer<QDtls> connection)
+QString connection_info(QDtls *connection)
{
QString info(DtlsServer::tr("Session cipher: "));
info += connection->sessionCipher().name();
@@ -157,7 +157,7 @@ void DtlsServer::readyRead()
}
const auto client = std::find_if(knownClients.begin(), knownClients.end(),
- [&](const DtlsConnection &connection){
+ [&](const std::unique_ptr<QDtls> &connection){
return connection->peerAddress() == peerAddress
&& connection->peerPort() == peerPort;
});
@@ -170,7 +170,7 @@ void DtlsServer::readyRead()
//! [6]
if ((*client)->isConnectionEncrypted()) {
- decryptDatagram(*client, dgram);
+ decryptDatagram(client->get(), dgram);
if ((*client)->dtlsError() == QDtlsError::RemoteClosedConnectionError)
knownClients.erase(client);
return;
@@ -178,7 +178,7 @@ void DtlsServer::readyRead()
//! [6]
//! [7]
- doHandshake(*client, dgram);
+ doHandshake(client->get(), dgram);
//! [7]
}
@@ -205,13 +205,13 @@ void DtlsServer::handleNewConnection(const QHostAddress &peerAddress,
emit infoMessage(peerInfo + tr(": verified, starting a handshake"));
//! [8]
//! [9]
- DtlsConnection newConnection(new QDtls(QSslSocket::SslServerMode));
+ std::unique_ptr<QDtls> newConnection{new QDtls{QSslSocket::SslServerMode}};
newConnection->setDtlsConfiguration(serverConfiguration);
newConnection->setPeer(peerAddress, peerPort);
- newConnection->connect(newConnection.data(), &QDtls::pskRequired,
+ newConnection->connect(newConnection.get(), &QDtls::pskRequired,
this, &DtlsServer::pskRequired);
- knownClients.push_back(newConnection);
- doHandshake(newConnection, clientHello);
+ knownClients.push_back(std::move(newConnection));
+ doHandshake(knownClients.back().get(), clientHello);
//! [9]
} else if (cookieSender.dtlsError() != QDtlsError::NoError) {
emit errorMessage(tr("DTLS error: ") + cookieSender.dtlsErrorString());
@@ -221,7 +221,7 @@ void DtlsServer::handleNewConnection(const QHostAddress &peerAddress,
}
//! [11]
-void DtlsServer::doHandshake(DtlsConnection newConnection, const QByteArray &clientHello)
+void DtlsServer::doHandshake(QDtls *newConnection, const QByteArray &clientHello)
{
const bool result = newConnection->doHandshake(&serverSocket, clientHello);
if (!result) {
@@ -246,7 +246,7 @@ void DtlsServer::doHandshake(DtlsConnection newConnection, const QByteArray &cli
//! [11]
//! [12]
-void DtlsServer::decryptDatagram(DtlsConnection connection, const QByteArray &clientMessage)
+void DtlsServer::decryptDatagram(QDtls *connection, const QByteArray &clientMessage)
{
Q_ASSERT(connection->isConnectionEncrypted());
@@ -266,10 +266,9 @@ void DtlsServer::decryptDatagram(DtlsConnection connection, const QByteArray &cl
//! [14]
void DtlsServer::shutdown()
{
- for (DtlsConnection &connection : knownClients)
+ for (const auto &connection : qExchange(knownClients, {}))
connection->shutdown(&serverSocket);
- knownClients.clear();
serverSocket.close();
}
//! [14]
diff --git a/examples/network/secureudpserver/server.h b/examples/network/secureudpserver/server.h
index b720368e7b..1af8aef8a2 100644
--- a/examples/network/secureudpserver/server.h
+++ b/examples/network/secureudpserver/server.h
@@ -54,6 +54,7 @@
#include <QtNetwork>
#include <vector>
+#include <memory>
QT_BEGIN_NAMESPACE
@@ -86,9 +87,8 @@ private:
void handleNewConnection(const QHostAddress &peerAddress, quint16 peerPort,
const QByteArray &clientHello);
- using DtlsConnection = QSharedPointer<QDtls>;
- void doHandshake(DtlsConnection newConnection, const QByteArray &clientHello);
- void decryptDatagram(DtlsConnection connection, const QByteArray &clientMessage);
+ void doHandshake(QDtls *newConnection, const QByteArray &clientHello);
+ void decryptDatagram(QDtls *connection, const QByteArray &clientMessage);
void shutdown();
bool listening = false;
@@ -96,7 +96,7 @@ private:
QSslConfiguration serverConfiguration;
QDtlsClientVerifier cookieSender;
- QVector<DtlsConnection> knownClients;
+ std::vector<std::unique_ptr<QDtls>> knownClients;
Q_DISABLE_COPY(DtlsServer)
};
diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp
index 87c65096b6..96474806f5 100644
--- a/examples/network/torrent/ratecontroller.cpp
+++ b/examples/network/torrent/ratecontroller.cpp
@@ -96,8 +96,8 @@ void RateController::transfer()
if (sockets.isEmpty())
return;
- int msecs = 1000;
- if (!stopWatch.isNull())
+ qint64 msecs = 1000;
+ if (stopWatch.isValid())
msecs = qMin(msecs, stopWatch.elapsed());
qint64 bytesToWrite = (upLimit * msecs) / 1000;
diff --git a/examples/network/torrent/ratecontroller.h b/examples/network/torrent/ratecontroller.h
index a4aa596ce1..f8bff0cc36 100644
--- a/examples/network/torrent/ratecontroller.h
+++ b/examples/network/torrent/ratecontroller.h
@@ -53,7 +53,7 @@
#include <QObject>
#include <QSet>
-#include <QTime>
+#include <QElapsedTimer>
class PeerWireClient;
@@ -79,7 +79,7 @@ public slots:
void scheduleTransfer();
private:
- QTime stopWatch;
+ QElapsedTimer stopWatch;
QSet<PeerWireClient *> sockets;
int upLimit;
int downLimit;