[network/libktorrent] src: ABI/API break: use enum class for Chunk::Status
Jack Hill <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 8401c5b0b4d2d0ca812a7d059abebe47d4ab1a38 by Jack Hill.
Committed on 15/08/2026 at 10:22.
Pushed by jackh into branch 'master'.
ABI/API break: use enum class for Chunk::Status
No downstream changes required.
M +1 -1 src/diskio/chunk.cpp
M +1 -1 src/diskio/chunk.h
M +11 -11 src/diskio/chunkmanager.cpp
M +1 -1 src/download/chunkselector.cpp
M +1 -1 src/download/downloader.cpp
M +2 -2 src/download/webseed.cpp
M +5 -5 src/net/packetsocket.cpp
M +1 -1 src/peer/peeruploader.cpp
https://invent.kde.org/network/libktorrent/-/commit/8401c5b0b4d2d0ca812a7d059abebe47d4ab1a38
diff --git a/src/diskio/chunk.cpp b/src/diskio/chunk.cpp
index 87f4bf56..0e0d6a22 100644
--- a/src/diskio/chunk.cpp
+++ b/src/diskio/chunk.cpp
@@ -12,7 +12,7 @@
namespace bt
{
Chunk::Chunk(Uint32 index, Uint32 size, Cache *cache)
- : status(Chunk::NOT_DOWNLOADED)
+ : status(Chunk::Status::NOT_DOWNLOADED)
, index(index)
, size(size)
, priority(NORMAL_PRIORITY)
diff --git a/src/diskio/chunk.h b/src/diskio/chunk.h
index 544edec7..3d1e64cd 100644
--- a/src/diskio/chunk.h
+++ b/src/diskio/chunk.h
@@ -38,7 +38,7 @@ public:
* \var NOT_DOWNLOADED
* The chunk has not been dowloaded yet and there is no buffer allocated.
*/
- enum Status {
+ enum class Status {
ON_DISK,
NOT_DOWNLOADED,
};
diff --git a/src/diskio/chunkmanager.cpp b/src/diskio/chunkmanager.cpp
index ccd7660b..28515f81 100644
--- a/src/diskio/chunkmanager.cpp
+++ b/src/diskio/chunkmanager.cpp
@@ -185,7 +185,7 @@ void ChunkManager::resetChunk(unsigned int i)
Chunk *c = d->chunks[i];
d->cache->clearPieces(c);
- c->setStatus(Chunk::NOT_DOWNLOADED);
+ c->setStatus(Chunk::Status::NOT_DOWNLOADED);
bitset.set(i, false);
d->todo.set(i, !excluded_chunks.get(i) && !only_seed_chunks.get(i));
tor.updateFilePercentage(i, *this);
@@ -210,7 +210,7 @@ void ChunkManager::chunkDownloaded(unsigned int i)
d->todo.set(i, false);
d->recalc_chunks_left = true;
d->writeIndexFileEntry(c);
- c->setStatus(Chunk::ON_DISK);
+ c->setStatus(Chunk::Status::ON_DISK);
tor.updateFilePercentage(i, *this);
} else {
Out(SYS_DIO | LOG_IMPORTANT) << "Warning: attempted to save a chunk which was excluded" << endl;
@@ -585,15 +585,15 @@ void ChunkManager::dataChecked(const bt::BitSet &ok_chunks, bt::Uint32 from, bt:
bitset.set(i, true);
d->todo.set(i, false);
// the chunk must be on disk
- c->setStatus(Chunk::ON_DISK);
+ c->setStatus(Chunk::Status::ON_DISK);
tor.updateFilePercentage(i, *this);
} else if (!ok_chunks.get(i) && bitset.get(i)) {
Out(SYS_DIO | LOG_IMPORTANT) << "Previously OK chunk " << i << " is corrupt !!!!!" << endl;
// We think we have a chunk, but we don't
bitset.set(i, false);
d->todo.set(i, !only_seed_chunks.get(i) && !excluded_chunks.get(i));
- if (c->getStatus() == Chunk::ON_DISK) {
- c->setStatus(Chunk::NOT_DOWNLOADED);
+ if (c->getStatus() == Chunk::Status::ON_DISK) {
+ c->setStatus(Chunk::Status::NOT_DOWNLOADED);
tor.updateFilePercentage(i, *this);
} else {
tor.updateFilePercentage(i, *this);
@@ -630,7 +630,7 @@ void ChunkManager::markExistingFilesAsDownloaded()
// all the chunks in the middle of the file are OK
for (Uint32 j = tf.getFirstChunk() + 1; j < tf.getLastChunk(); j++) {
Chunk *c = d->chunks[j];
- c->setStatus(Chunk::ON_DISK);
+ c->setStatus(Chunk::Status::ON_DISK);
bitset.set(j, true);
d->todo.set(j, false);
tor.updateFilePercentage(j, *this);
@@ -640,7 +640,7 @@ void ChunkManager::markExistingFilesAsDownloaded()
if (d->allFilesExistOfChunk(tf.getFirstChunk())) {
const Uint32 idx = tf.getFirstChunk();
Chunk *c = d->chunks[idx];
- c->setStatus(Chunk::ON_DISK);
+ c->setStatus(Chunk::Status::ON_DISK);
bitset.set(idx, true);
d->todo.set(idx, false);
tor.updateFilePercentage(idx, *this);
@@ -650,7 +650,7 @@ void ChunkManager::markExistingFilesAsDownloaded()
if (d->allFilesExistOfChunk(tf.getLastChunk())) {
const Uint32 idx = tf.getLastChunk();
Chunk *c = d->chunks[idx];
- c->setStatus(Chunk::ON_DISK);
+ c->setStatus(Chunk::Status::ON_DISK);
bitset.set(idx, true);
d->todo.set(idx, false);
tor.updateFilePercentage(idx, *this);
@@ -659,7 +659,7 @@ void ChunkManager::markExistingFilesAsDownloaded()
} else if (d->cache->hasExistingFiles()) {
for (Uint32 i = 0; i < d->chunks.size(); i++) {
Chunk *c = d->chunks[i];
- c->setStatus(Chunk::ON_DISK);
+ c->setStatus(Chunk::Status::ON_DISK);
bitset.set(i, true);
d->todo.set(i, false);
tor.updateFilePercentage(i, *this);
@@ -873,7 +873,7 @@ void ChunkManager::Private::saveIndexFile()
for (unsigned int i = 0; i < p->getNumChunks(); i++) {
const Chunk *c = p->getChunk(i);
- if (c->getStatus() != Chunk::NOT_DOWNLOADED) {
+ if (c->getStatus() != Chunk::Status::NOT_DOWNLOADED) {
NewChunkHeader hdr;
hdr.index = i;
fptr.write(&hdr, sizeof(NewChunkHeader));
@@ -924,7 +924,7 @@ void ChunkManager::Private::loadIndexFile()
fptr.read(&hdr, sizeof(NewChunkHeader));
Chunk *c = p->getChunk(hdr.index);
if (c) {
- c->setStatus(Chunk::ON_DISK);
+ c->setStatus(Chunk::Status::ON_DISK);
p->bitset.set(hdr.index, true);
todo.set(hdr.index, false);
recalc_chunks_left = true;
diff --git a/src/download/chunkselector.cpp b/src/download/chunkselector.cpp
index ea28dee8..e65f0200 100644
--- a/src/download/chunkselector.cpp
+++ b/src/download/chunkselector.cpp
@@ -210,7 +210,7 @@ void ChunkSelector::reincluded(Uint32 from, Uint32 to)
for (Uint32 i = from; i <= to; i++) {
const bool in_chunks = std::find(chunks.begin(), chunks.end(), i) != chunks.end();
- if (!in_chunks && cman->getChunk(i)->getStatus() != Chunk::ON_DISK) {
+ if (!in_chunks && cman->getChunk(i)->getStatus() != Chunk::Status::ON_DISK) {
// Out(SYS_DIO|LOG_DEBUG) << "ChunkSelector::reIncluded " << i << endl;
chunks.push_back(i);
}
diff --git a/src/download/downloader.cpp b/src/download/downloader.cpp
index 18db512e..795bfc94 100644
--- a/src/download/downloader.cpp
+++ b/src/download/downloader.cpp
@@ -571,7 +571,7 @@ void Downloader::loadDownloads(const QString &file)
ret = false;
}
- if (!ret || c->getStatus() == Chunk::ON_DISK || c->isExcluded()) {
+ if (!ret || c->getStatus() == Chunk::Status::ON_DISK || c->isExcluded()) {
delete cd;
} else {
current_chunks.insert(hdr.index, cd);
diff --git a/src/download/webseed.cpp b/src/download/webseed.cpp
index 7d0dfd3e..269fc534 100644
--- a/src/download/webseed.cpp
+++ b/src/download/webseed.cpp
@@ -398,7 +398,7 @@ void WebSeed::handleData(const QByteArray &tmp)
}
// ignore data if we already have it
- if (c->getStatus() != Chunk::ON_DISK) {
+ if (c->getStatus() != Chunk::Status::ON_DISK) {
if (!cur_piece || cur_piece->parentChunk() != c) {
cur_piece = c->getPiece(0, c->getSize(), false);
}
@@ -416,7 +416,7 @@ void WebSeed::handleData(const QByteArray &tmp)
// we have one ready
bytes_of_cur_chunk = 0;
cur_chunk++;
- if (c->getStatus() != Chunk::ON_DISK) {
+ if (c->getStatus() != Chunk::Status::ON_DISK) {
Q_EMIT chunkReady(c);
// It is possible that the webseed has been disabled due receiving a bad chunk
if (!isEnabled()) {
diff --git a/src/net/packetsocket.cpp b/src/net/packetsocket.cpp
index e100a4a7..89e5eae4 100644
--- a/src/net/packetsocket.cpp
+++ b/src/net/packetsocket.cpp
@@ -89,7 +89,7 @@ Uint32 PacketSocket::write(Uint32 max, bt::TimeStamp now)
const int ret = curr_packet->send(sock.get(), limit);
if (ret > 0) {
written += ret;
- if (curr_packet->getType() == PIECE) {
+ if (curr_packet->getType() == PeerMessageType::PIECE) {
up_speed->onData(ret, now);
const QMutexLocker locker(&mutex);
pending_upload_data_bytes -= ret;
@@ -101,7 +101,7 @@ Uint32 PacketSocket::write(Uint32 max, bt::TimeStamp now)
if (curr_packet->isSent()) {
// packet sent, so remove it
- if (curr_packet->getType() == PIECE) {
+ if (curr_packet->getType() == PeerMessageType::PIECE) {
// reset ctrl_packets_sent so the next packet should be a ctrl packet
ctrl_packets_sent = 0;
} else {
@@ -121,7 +121,7 @@ void PacketSocket::addPacket(Packet packet)
{
Q_ASSERT(!packet.sending());
const QMutexLocker locker(&mutex);
- if (packet.getType() == PIECE) {
+ if (packet.getType() == PeerMessageType::PIECE) {
pending_upload_data_bytes += packet.getDataLength();
data_packets.push_back(std::move(packet));
} else {
@@ -158,7 +158,7 @@ void PacketSocket::clearPieces(bool reject)
auto i = data_packets.begin();
while (i != data_packets.end()) {
const Packet &p = *i;
- if (p.getType() == bt::PIECE && !p.sending()) {
+ if (p.getType() == bt::PeerMessageType::PIECE && !p.sending()) {
if (reject) {
auto reject_pkt = p.makeRejectOfPiece();
if (reject_pkt.has_value()) {
@@ -198,7 +198,7 @@ void PacketSocket::doNotSendPiece(const bt::Request &req, bool reject)
Uint32 PacketSocket::numPendingPieceUploads() const
{
const QMutexLocker locker(&mutex);
- const bool curr_packet_is_piece = curr_packet && curr_packet->getType() == bt::PIECE;
+ const bool curr_packet_is_piece = curr_packet && curr_packet->getType() == bt::PeerMessageType::PIECE;
return data_packets.size() + (curr_packet_is_piece ? 1 : 0);
}
diff --git a/src/peer/peeruploader.cpp b/src/peer/peeruploader.cpp
index 95f49a04..0c62f551 100644
--- a/src/peer/peeruploader.cpp
+++ b/src/peer/peeruploader.cpp
@@ -48,7 +48,7 @@ Uint32 PeerUploader::handleRequests(ChunkManager &cman)
const Request r = requests.front();
Chunk *c = cman.getChunk(r.getIndex());
- if (c && c->getStatus() == Chunk::ON_DISK) {
+ if (c && c->getStatus() == Chunk::Status::ON_DISK) {
if (!peer->sendChunk(r.getIndex(), r.getOffset(), r.getLength(), c)) {
if (peer->getStats().fast_extensions) {
peer->sendReject(r);