Skip to content

Commit

Permalink
Torrent example: replace Java-style iteration with STL iterators
Browse files Browse the repository at this point in the history
Java-iterators are going to be deprecated.

Change-Id: I2e6353f3fd9e2ddaf0767e7f6cea713249d9591e
Reviewed-by: Mårten Nordheim <[email protected]>
Reviewed-by: Paul Wicking <[email protected]>
  • Loading branch information
marc-kdab committed May 23, 2019
1 parent 070517f commit 77e708d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions examples/network/torrent/ratecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ void RateController::transfer()
qint64 writeChunk = qMax<qint64>(1, bytesToWrite / pendingSockets.size());
qint64 readChunk = qMax<qint64>(1, bytesToRead / pendingSockets.size());

QSetIterator<PeerWireClient *> it(pendingSockets);
while (it.hasNext() && (bytesToWrite > 0 || bytesToRead > 0)) {
PeerWireClient *socket = it.next();
for (auto it = pendingSockets.begin(), end = pendingSockets.end(); it != end && (bytesToWrite > 0 || bytesToRead > 0); /*erasing*/) {
auto current = it++;
PeerWireClient *socket = *current;
if (socket->state() != QAbstractSocket::ConnectedState) {
pendingSockets.remove(socket);
pendingSockets.erase(current);
continue;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ void RateController::transfer()
if (dataTransferred && socket->canTransferMore())
canTransferMore = true;
else
pendingSockets.remove(socket);
pendingSockets.erase(current);
}
} while (canTransferMore && (bytesToWrite > 0 || bytesToRead > 0) && !pendingSockets.isEmpty());

Expand Down

0 comments on commit 77e708d

Please sign in to comment.