diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2023-01-25 12:49:51 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2023-04-11 18:25:42 +0100 |
commit | 1a55c8d887bda1e8f1f5accda6633a238674d617 (patch) | |
tree | 570f6ed98c17ef18504a8282bd5f7c89dad3a70d /examples/network/torrent/peerwireclient.cpp | |
parent | e8a711ef3bf9875a249f338da28afb60f2617c78 (diff) |
Torrent example: update usage of integer types
Some of the 'int's are purposefully 32-bit because that's what the
protocol is, but others aren't. So, be more explicit.
Task-number: QTBUG-110622
Pick-to: 6.5
Change-Id: I338abca1f13b0c95f49a6f52933712f43f147590
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'examples/network/torrent/peerwireclient.cpp')
-rw-r--r-- | examples/network/torrent/peerwireclient.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/examples/network/torrent/peerwireclient.cpp b/examples/network/torrent/peerwireclient.cpp index d4264ffc3a..349371afbf 100644 --- a/examples/network/torrent/peerwireclient.cpp +++ b/examples/network/torrent/peerwireclient.cpp @@ -54,7 +54,7 @@ PeerWireClient::PeerWireClient(const QByteArray &peerId, QObject *parent) // Registers the peer ID and SHA1 sum of the torrent, and initiates // the handshake. -void PeerWireClient::initialize(const QByteArray &infoHash, int pieceCount) +void PeerWireClient::initialize(const QByteArray &infoHash, qint32 pieceCount) { this->infoHash = infoHash; peerPieces.resize(pieceCount); @@ -142,7 +142,7 @@ void PeerWireClient::sendNotInterested() // Sends a piece notification / a "have" message, informing the peer // that we have just downloaded a new piece. -void PeerWireClient::sendPieceNotification(int piece) +void PeerWireClient::sendPieceNotification(qint32 piece) { if (!sentHandShake) sendHandShake(); @@ -183,7 +183,7 @@ void PeerWireClient::sendPieceList(const QBitArray &bitField) } // Sends a request for a block. -void PeerWireClient::requestBlock(int piece, int offset, int length) +void PeerWireClient::requestBlock(qint32 piece, qint32 offset, qint32 length) { char message[] = {0, 0, 0, 1, 6}; qToBigEndian(13, &message[0]); @@ -206,7 +206,7 @@ void PeerWireClient::requestBlock(int piece, int offset, int length) } // Cancels a request for a block. -void PeerWireClient::cancelRequest(int piece, int offset, int length) +void PeerWireClient::cancelRequest(qint32 piece, qint32 offset, qint32 length) { char message[] = {0, 0, 0, 1, 8}; qToBigEndian(13, &message[0]); @@ -222,7 +222,7 @@ void PeerWireClient::cancelRequest(int piece, int offset, int length) } // Sends a block to the peer. -void PeerWireClient::sendBlock(int piece, int offset, const QByteArray &data) +void PeerWireClient::sendBlock(qint32 piece, qint32 offset, const QByteArray &data) { QByteArray block; @@ -516,7 +516,7 @@ void PeerWireClient::processIncomingData() for (int i = 1; i < packet.size(); ++i) { for (int bit = 0; bit < 8; ++bit) { if (packet.at(i) & (1 << (7 - bit))) { - int bitIndex = int(((i - 1) * 8) + bit); + qint32 bitIndex = qint32(((i - 1) * 8) + bit); if (bitIndex >= 0 && bitIndex < peerPieces.size()) { // Occasionally, broken clients claim to have // pieces whose index is outside the valid range. @@ -534,12 +534,12 @@ void PeerWireClient::processIncomingData() quint32 index = qFromBigEndian<quint32>(&packet.data()[1]); quint32 begin = qFromBigEndian<quint32>(&packet.data()[5]); quint32 length = qFromBigEndian<quint32>(&packet.data()[9]); - emit blockRequested(int(index), int(begin), int(length)); + emit blockRequested(qint32(index), qint32(begin), qint32(length)); break; } case PiecePacket: { - int index = int(qFromBigEndian<quint32>(&packet.data()[1])); - int begin = int(qFromBigEndian<quint32>(&packet.data()[5])); + qint32 index = qint32(qFromBigEndian<quint32>(&packet.data()[1])); + qint32 begin = qint32(qFromBigEndian<quint32>(&packet.data()[5])); incoming.removeAll(TorrentBlock(index, begin, packet.size() - 9)); @@ -560,9 +560,9 @@ void PeerWireClient::processIncomingData() quint32 length = qFromBigEndian<quint32>(&packet.data()[9]); for (int i = 0; i < pendingBlocks.size(); ++i) { const BlockInfo &blockInfo = pendingBlocks.at(i); - if (blockInfo.pieceIndex == int(index) - && blockInfo.offset == int(begin) - && blockInfo.length == int(length)) { + if (blockInfo.pieceIndex == qint32(index) + && blockInfo.offset == qint32(begin) + && blockInfo.length == qint32(length)) { pendingBlocks.removeAt(i); break; } |