[network/libktorrent] src/utp: ABI/API break: use enum class for utp::Type

Jack Hill <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit b193cca698b82756cc11aa022a2a6775ee3498a4 by Jack Hill.
Committed on 15/08/2026 at 10:18.
Pushed by jackh into branch 'master'.

ABI/API break: use enum class for utp::Type

No downstream changes required.

M  +2    -2    src/utp/connection.cpp
M  +2    -2    src/utp/connection.h
M  +4    -4    src/utp/tests/connectiontest.cpp
M  +2    -2    src/utp/utpprotocol.h
M  +3    -3    src/utp/utpserver.cpp

https://invent.kde.org/network/libktorrent/-/commit/b193cca698b82756cc11aa022a2a6775ee3498a4

diff --git a/src/utp/connection.cpp b/src/utp/connection.cpp
index 77213bbb..8c74f400 100644
--- a/src/utp/connection.cpp
+++ b/src/utp/connection.cpp
@@ -47,7 +47,7 @@ Connection::Connection(bt::Uint16 recv_connection_id, Type type, const net::Addr
     stats.timeout = 1000;
     stats.packet_size = 1500 - IP_AND_UDP_OVERHEAD - sizeof(utp::Header);
     stats.last_window_size_transmitted = 128 * 1024;
-    if (type == OUTGOING) {
+    if (type == Type::OUTGOING) {
         stats.send_connection_id = recv_connection_id + 1;
     } else {
         stats.send_connection_id = recv_connection_id - 1;
@@ -73,7 +73,7 @@ Connection::~Connection()
 
 void Connection::startConnecting()
 {
-    if (stats.type == OUTGOING) {
+    if (stats.type == Type::OUTGOING) {
         sendSYN();
     }
 }
diff --git a/src/utp/connection.h b/src/utp/connection.h
index aa92f696..97fbc166 100644
--- a/src/utp/connection.h
+++ b/src/utp/connection.h
@@ -45,7 +45,7 @@ public:
      * \var OUTGOING
      * We are initiating a connection and will send the first SYN packet.
      */
-    enum Type {
+    enum class Type {
         INCOMING,
         OUTGOING,
     };
@@ -105,7 +105,7 @@ public:
     //! Dump connection stats
     void dumpStats();
 
-    //! Start connecting (OUTGOING only)
+    //! Start connecting (Type::OUTGOING only)
     void startConnecting();
 
     //! Get the connection stats
diff --git a/src/utp/tests/connectiontest.cpp b/src/utp/tests/connectiontest.cpp
index 7ec1882f..bdc8b0d6 100644
--- a/src/utp/tests/connectiontest.cpp
+++ b/src/utp/tests/connectiontest.cpp
@@ -81,11 +81,11 @@ private:
     void testConnID()
     {
         const bt::Uint32 conn_id = 666;
-        const Connection conn(conn_id, utp::Connection::INCOMING, remote, this);
+        const Connection conn(conn_id, utp::Connection::Type::INCOMING, remote, this);
         QCOMPARE(conn.connectionStats().recv_connection_id, conn_id);
         QCOMPARE(conn.connectionStats().send_connection_id, conn_id - 1);
 
-        const Connection conn2(conn_id, utp::Connection::OUTGOING, remote, this);
+        const Connection conn2(conn_id, utp::Connection::Type::OUTGOING, remote, this);
         QCOMPARE(conn2.connectionStats().recv_connection_id, conn_id);
         QCOMPARE(conn2.connectionStats().send_connection_id, conn_id + 1);
     }
@@ -93,7 +93,7 @@ private:
     void testOutgoingConnectionSetup()
     {
         const bt::Uint32 conn_id = 666;
-        Connection conn(conn_id, utp::Connection::OUTGOING, remote, this);
+        Connection conn(conn_id, utp::Connection::Type::OUTGOING, remote, this);
         conn.startConnecting();
         const Connection::Stats &s = conn.connectionStats();
         QCOMPARE(s.state, utp::ConnectionState::SYN_SENT);
@@ -110,7 +110,7 @@ private:
     void testIncomingConnectionSetup()
     {
         const bt::Uint32 conn_id = 666;
-        Connection conn(conn_id, utp::Connection::INCOMING, remote, this);
+        Connection conn(conn_id, utp::Connection::Type::INCOMING, remote, this);
         const Connection::Stats &s = conn.connectionStats();
 
         auto pkt = buildPacket(ST_SYN, conn_id - 1, conn_id, 1, 1);
diff --git a/src/utp/utpprotocol.h b/src/utp/utpprotocol.h
index 2882fdb3..ef3262ca 100644
--- a/src/utp/utpprotocol.h
+++ b/src/utp/utpprotocol.h
@@ -105,10 +105,10 @@ KTORRENT_EXPORT QString TypeToString(bt::Uint8 type);
  * The current state of a UTP connection.
  *
  * \var IDLE
- * Used for INCOMING connections before we have processed the first SYN packet.
+ * Used for Type::INCOMING connections before we have processed the first SYN packet.
  *
  * \var SYN_SENT
- * Used after an OUTGOING connection has sent a SYN packet.
+ * Used after an Type::OUTGOING connection has sent a SYN packet.
  *
  * \var CONNECTED
  * The SYN packet exchange has been successful.
diff --git a/src/utp/utpserver.cpp b/src/utp/utpserver.cpp
index 92a763d2..2e52d7f7 100644
--- a/src/utp/utpserver.cpp
+++ b/src/utp/utpserver.cpp
@@ -115,11 +115,11 @@ void UTPServer::Private::syn(const PacketParser &parser, std::unique_ptr<bt::Buf
     const quint16 recv_conn_id = hdr->connection_id + 1;
     if (connections.contains(recv_conn_id)) {
         // Send a reset packet if the ID is in use
-        const Connection::Ptr conn(new Connection(recv_conn_id, Connection::INCOMING, addr, p));
+        const Connection::Ptr conn(new Connection(recv_conn_id, Connection::Type::INCOMING, addr, p));
         conn->setWeakPointer(conn);
         conn->sendReset();
     } else {
-        const Connection::Ptr conn(new Connection(recv_conn_id, Connection::INCOMING, addr, p));
+        const Connection::Ptr conn(new Connection(recv_conn_id, Connection::Type::INCOMING, addr, p));
         try {
             conn->setWeakPointer(conn);
             conn->handlePacket(parser, std::move(buffer));
@@ -378,7 +378,7 @@ Connection::WPtr UTPServer::connectTo(const net::Address &addr)
         recv_conn_id = QRandomGenerator::global()->bounded(32535);
     }
 
-    const Connection::Ptr conn(new Connection(recv_conn_id, Connection::OUTGOING, addr, this));
+    const Connection::Ptr conn(new Connection(recv_conn_id, Connection::Type::OUTGOING, addr, this));
     conn->setWeakPointer(conn);
     conn->moveToThread(d->utp_thread);
     d->connections.insert(recv_conn_id, conn);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.