From 1a55c8d887bda1e8f1f5accda6633a238674d617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 25 Jan 2023 12:49:51 +0100 Subject: 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 Reviewed-by: Timur Pocheptsov Reviewed-by: Marc Mutz --- examples/network/torrent/peerwireclient.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'examples/network/torrent/peerwireclient.cpp') 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(&packet.data()[1]); quint32 begin = qFromBigEndian(&packet.data()[5]); quint32 length = qFromBigEndian(&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(&packet.data()[1])); - int begin = int(qFromBigEndian(&packet.data()[5])); + qint32 index = qint32(qFromBigEndian(&packet.data()[1])); + qint32 begin = qint32(qFromBigEndian(&packet.data()[5])); incoming.removeAll(TorrentBlock(index, begin, packet.size() - 9)); @@ -560,9 +560,9 @@ void PeerWireClient::processIncomingData() quint32 length = qFromBigEndian(&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; } -- cgit v1.2.3