summaryrefslogtreecommitdiffstats
path: root/examples/network/torrent
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-11-11 16:26:04 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-11-18 13:59:41 +0100
commit3a07c391847b81c7bf40d95fc4d7c49f63073abc (patch)
treeae481ec0170e6cd53cbd09a28fc780fe0ab467d2 /examples/network/torrent
parentc5f3c61469517a4ac00e4da01fe0bab9188c1488 (diff)
Port from qAsConst() to std::as_const()
We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace. This is a 6.4 re-run of the script we ran in dev, in order to avoid conflicts between the branches when cherry-picking. Change-Id: I5eca3df3179dfb2b2682c75a479ba9a4259cc703 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/network/torrent')
-rw-r--r--examples/network/torrent/filemanager.cpp4
-rw-r--r--examples/network/torrent/mainwindow.cpp4
-rw-r--r--examples/network/torrent/ratecontroller.cpp4
-rw-r--r--examples/network/torrent/torrentclient.cpp32
-rw-r--r--examples/network/torrent/torrentserver.cpp2
5 files changed, 23 insertions, 23 deletions
diff --git a/examples/network/torrent/filemanager.cpp b/examples/network/torrent/filemanager.cpp
index c86c3f2dd4..df964b9730 100644
--- a/examples/network/torrent/filemanager.cpp
+++ b/examples/network/torrent/filemanager.cpp
@@ -30,7 +30,7 @@ FileManager::~FileManager()
cond.wakeOne();
wait();
- for (QFile *file : qAsConst(files)) {
+ for (QFile *file : std::as_const(files)) {
file->close();
delete file;
}
@@ -391,7 +391,7 @@ void FileManager::verifyFileContents()
}
// Verify all pending pieces
- for (int index : qAsConst(newPendingVerificationRequests))
+ for (int index : std::as_const(newPendingVerificationRequests))
emit pieceVerified(index, verifySinglePiece(index));
}
diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp
index 4d710953a1..4c898743ba 100644
--- a/examples/network/torrent/mainwindow.cpp
+++ b/examples/network/torrent/mainwindow.cpp
@@ -311,7 +311,7 @@ bool MainWindow::addTorrent(const QString &fileName, const QString &destinationF
const QByteArray &resumeState)
{
// Check if the torrent is already being downloaded.
- for (const Job &job : qAsConst(jobs)) {
+ for (const Job &job : std::as_const(jobs)) {
if (job.torrentFileName == fileName && job.destinationDirectory == destinationFolder) {
QMessageBox::warning(this, tr("Already downloading"),
tr("The torrent file %1 is "
@@ -644,7 +644,7 @@ void MainWindow::closeEvent(QCloseEvent *)
// them to signal that they have stopped.
jobsToStop = 0;
jobsStopped = 0;
- for (const Job &job : qAsConst(jobs)) {
+ for (const Job &job : std::as_const(jobs)) {
++jobsToStop;
TorrentClient *client = job.client;
client->disconnect();
diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp
index 3dd256a0f6..c5e33ab63c 100644
--- a/examples/network/torrent/ratecontroller.cpp
+++ b/examples/network/torrent/ratecontroller.cpp
@@ -33,7 +33,7 @@ void RateController::removeSocket(PeerWireClient *socket)
void RateController::setDownloadLimit(int bytesPerSecond)
{
downLimit = bytesPerSecond;
- for (PeerWireClient *socket : qAsConst(sockets))
+ for (PeerWireClient *socket : std::as_const(sockets))
socket->setReadBufferSize(downLimit * 4);
}
@@ -63,7 +63,7 @@ void RateController::transfer()
}
QSet<PeerWireClient *> pendingSockets;
- for (PeerWireClient *client : qAsConst(sockets)) {
+ for (PeerWireClient *client : std::as_const(sockets)) {
if (client->canTransferMore())
pendingSockets << client;
}
diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp
index fcc1b285f1..6fefb3855c 100644
--- a/examples/network/torrent/torrentclient.cpp
+++ b/examples/network/torrent/torrentclient.cpp
@@ -416,7 +416,7 @@ void TorrentClient::stop()
}
// Abort all existing connections
- for (PeerWireClient *client : qAsConst(d->connections)) {
+ for (PeerWireClient *client : std::as_const(d->connections)) {
RateController::instance()->removeSocket(client);
ConnectionManager::instance()->removeConnection(client);
client->abort();
@@ -439,7 +439,7 @@ void TorrentClient::setPaused(bool paused)
// connections to 0. Keep the list of peers, so we can quickly
// resume later.
d->setState(Paused);
- for (PeerWireClient *client : qAsConst(d->connections))
+ for (PeerWireClient *client : std::as_const(d->connections))
client->abort();
d->connections.clear();
TorrentServer::instance()->removeClient(this);
@@ -574,7 +574,7 @@ void TorrentClient::pieceVerified(int pieceIndex, bool ok)
}
// Update the peer list so we know who's still interesting.
- for (TorrentPeer *peer : qAsConst(d->peers)) {
+ for (TorrentPeer *peer : std::as_const(d->peers)) {
if (!peer->interesting)
continue;
bool interesting = false;
@@ -594,7 +594,7 @@ void TorrentClient::pieceVerified(int pieceIndex, bool ok)
d->incompletePieces.clearBit(pieceIndex);
// Notify connected peers.
- for (PeerWireClient *client : qAsConst(d->connections)) {
+ for (PeerWireClient *client : std::as_const(d->connections)) {
if (client->state() == QAbstractSocket::ConnectedState
&& !client->availablePieces().testBit(pieceIndex)) {
client->sendPieceNotification(pieceIndex);
@@ -672,9 +672,9 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
qint64 now = QDateTime::currentSecsSinceEpoch();
QList<TorrentPeer *> freePeers;
QMap<QString, int> connectionsPerPeer;
- for (TorrentPeer *peer : qAsConst(d->peers)) {
+ for (TorrentPeer *peer : std::as_const(d->peers)) {
bool busy = false;
- for (PeerWireClient *client : qAsConst(d->connections)) {
+ for (PeerWireClient *client : std::as_const(d->connections)) {
if (client->state() == PeerWireClient::ConnectedState
&& client->peerAddress() == peer->address
&& client->peerPort() == peer->port) {
@@ -694,7 +694,7 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
// Assign points based on connection speed and pieces available.
QList<QPair<int, TorrentPeer *> > points;
- for (TorrentPeer *peer : qAsConst(freePeers)) {
+ for (TorrentPeer *peer : std::as_const(freePeers)) {
int tmp = 0;
if (peer->interesting) {
tmp += peer->numCompletedPieces;
@@ -717,7 +717,7 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
QMultiMap<int, TorrentPeer *> pointMap;
int lowestScore = 0;
int lastIndex = 0;
- for (const PointPair &point : qAsConst(points)) {
+ for (const PointPair &point : std::as_const(points)) {
if (point.first > lowestScore) {
lowestScore = point.first;
++lastIndex;
@@ -768,7 +768,7 @@ void TorrentClient::setupOutgoingConnection()
PeerWireClient *client = qobject_cast<PeerWireClient *>(sender());
// Update connection statistics.
- for (TorrentPeer *peer : qAsConst(d->peers)) {
+ for (TorrentPeer *peer : std::as_const(d->peers)) {
if (peer->port == client->peerPort() && peer->address == client->peerAddress()) {
peer->connectTime = peer->lastVisited - peer->connectStart;
break;
@@ -1040,7 +1040,7 @@ void TorrentClient::scheduleUploads()
// no use in unchoking them.
QList<PeerWireClient *> allClients = d->connections;
QList<QPair<qint64, PeerWireClient *>> transferSpeeds;
- for (PeerWireClient *client : qAsConst(allClients)) {
+ for (PeerWireClient *client : std::as_const(allClients)) {
if (client->state() == QAbstractSocket::ConnectedState
&& client->availablePieces().count(true) != d->pieceCount) {
if (d->state == Seeding) {
@@ -1098,7 +1098,7 @@ void TorrentClient::scheduleDownloads()
// Check what each client is doing, and assign payloads to those
// who are either idle or done.
- for (PeerWireClient *client : qAsConst(d->connections))
+ for (PeerWireClient *client : std::as_const(d->connections))
schedulePieceForClient(client);
}
@@ -1177,7 +1177,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
incompletePiecesAvailableToClient &= client->availablePieces();
// Remove all pieces that this client has already requested.
- for (int i : qAsConst(currentPieces))
+ for (int i : std::as_const(currentPieces))
incompletePiecesAvailableToClient.clearBit(i);
// Only continue if more pieces can be scheduled. If no pieces
@@ -1213,7 +1213,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
memset(occurrences, 0, d->pieceCount * sizeof(int));
// Count how many of each piece are available.
- for (PeerWireClient *peer : qAsConst(d->connections)) {
+ for (PeerWireClient *peer : std::as_const(d->connections)) {
QBitArray peerPieces = peer->availablePieces();
int peerPiecesSize = peerPieces.size();
for (int i = 0; i < peerPiecesSize; ++i) {
@@ -1311,7 +1311,7 @@ void TorrentClient::requestMore(PeerWireClient *client)
// Starting with the first piece that we're waiting for, request
// blocks until the quota is filled up.
- for (TorrentPiece *piece : qAsConst(piecesInProgress)) {
+ for (TorrentPiece *piece : std::as_const(piecesInProgress)) {
numBlocksInProgress += requestBlocks(client, piece, maxInProgress - numBlocksInProgress);
if (numBlocksInProgress == maxInProgress)
break;
@@ -1414,7 +1414,7 @@ void TorrentClient::addToPeerList(const QList<TorrentPeer> &peerList)
}
bool known = false;
- for (const TorrentPeer *knownPeer : qAsConst(d->peers)) {
+ for (const TorrentPeer *knownPeer : std::as_const(d->peers)) {
if (knownPeer->port == peer.port
&& knownPeer->address == peer.address) {
known = true;
@@ -1445,7 +1445,7 @@ void TorrentClient::addToPeerList(const QList<TorrentPeer> &peerList)
const auto firstNInactivePeers = [&tooMany, this] (TorrentPeer *peer) {
if (!tooMany)
return false;
- for (const PeerWireClient *client : qAsConst(d->connections)) {
+ for (const PeerWireClient *client : std::as_const(d->connections)) {
if (client->peer() == peer && (client->downloadSpeed() + client->uploadSpeed()) > 1024)
return false;
}
diff --git a/examples/network/torrent/torrentserver.cpp b/examples/network/torrent/torrentserver.cpp
index 8bdf98dd49..9751c25497 100644
--- a/examples/network/torrent/torrentserver.cpp
+++ b/examples/network/torrent/torrentserver.cpp
@@ -55,7 +55,7 @@ void TorrentServer::removeClient()
void TorrentServer::processInfoHash(const QByteArray &infoHash)
{
PeerWireClient *peer = qobject_cast<PeerWireClient *>(sender());
- for (TorrentClient *client : qAsConst(clients)) {
+ for (TorrentClient *client : std::as_const(clients)) {
if (client->state() >= TorrentClient::Searching && client->infoHash() == infoHash) {
peer->disconnect(peer, nullptr, this, nullptr);
client->setupIncomingConnection(peer);