diff --git a/Sources/OpenGraphCxx/DebugServer/DebugServer.mm b/Sources/OpenGraphCxx/DebugServer/DebugServer.mm index 5c8d4200..08c0ca93 100644 --- a/Sources/OpenGraphCxx/DebugServer/DebugServer.mm +++ b/Sources/OpenGraphCxx/DebugServer/DebugServer.mm @@ -5,6 +5,11 @@ // Audited for 6.5.1 // Status: Blocked by profile command +// TODO: +// 1. select will both fail on AG and OG with different error. +// 2. run(timeout)'s purpose? And update documentation for hpp and h +// 3. Implement profile commands. + #include #if OG_TARGET_OS_DARWIN @@ -107,10 +112,48 @@ char address[32]; uint32_t converted_ip = htonl(ip); inet_ntop(AF_INET, &converted_ip, address, sizeof(address)); - os_log_info(misc_log(), "debug server graph://%s:%d/?token=%u", address, port, token); + os_log(misc_log(), "debug server graph://%s:%d/?token=%u", address, port, token); fprintf(stderr, "debug server graph://%s:%d/?token=%u\n", address, port, token); } +OG::DebugServer::DebugServer(DebugServer&& other) OG_NOEXCEPT + : sockfd(other.sockfd) + , ip(other.ip) + , port(other.port) + , token(other.token) + , source(other.source) + , connections(std::move(other.connections)) +{ + other.sockfd = -1; + other.ip = 0; + other.port = 0; + other.token = 0; + other.source = nullptr; +} + +OG::DebugServer& OG::DebugServer::operator=(DebugServer&& other) OG_NOEXCEPT { + if (this != &other) { + shutdown(); + for (auto &connection : connections) { + connection.reset(); + } + + sockfd = other.sockfd; + ip = other.ip; + port = other.port; + token = other.token; + source = other.source; + connections = std::move(other.connections); + + other.sockfd = -1; + other.ip = 0; + other.port = 0; + other.token = 0; + other.source = nullptr; + } + return *this; +} + OG::DebugServer::~DebugServer() { shutdown(); for (auto &connection : connections) { diff --git a/Sources/OpenGraphCxx/include/OpenGraphCxx/DebugServer/DebugServer.hpp b/Sources/OpenGraphCxx/include/OpenGraphCxx/DebugServer/DebugServer.hpp index c6c7d9a4..eff658c0 100644 --- a/Sources/OpenGraphCxx/include/OpenGraphCxx/DebugServer/DebugServer.hpp +++ b/Sources/OpenGraphCxx/include/OpenGraphCxx/DebugServer/DebugServer.hpp @@ -14,6 +14,7 @@ #include #include #include +#include OG_ASSUME_NONNULL_BEGIN @@ -49,6 +50,23 @@ class DebugServer { /// @param mode The operating mode for the debug server DebugServer(OGDebugServerMode mode); + /// Move constructor for transferring ownership of server resources. + /// + /// @param other The DebugServer instance to move from + DebugServer(DebugServer&& other) OG_NOEXCEPT; + + /// Move assignment operator for transferring ownership of server resources. + /// + /// @param other The DebugServer instance to move from + /// @return Reference to this instance after the move + DebugServer& operator=(DebugServer&& other) OG_NOEXCEPT; + + /// Deleted copy constructor to prevent accidental copying. + DebugServer(const DebugServer&) = delete; + + /// Deleted copy assignment operator to prevent accidental copying. + DebugServer& operator=(const DebugServer&) = delete; + /// Destroys the debug server and cleans up all resources. /// Automatically closes all active connections and stops the server. ~DebugServer(); @@ -57,7 +75,7 @@ class DebugServer { /// /// @return A CFURLRef containing the server URL, or nullptr if not running. /// The caller is responsible for releasing the returned URL. - CFURLRef _Nullable copy_url() const; + CFURLRef _Nullable copy_url() const SWIFT_RETURNS_INDEPENDENT_VALUE; /// Shuts down the debug server and closes all connections. /// Called internally during destruction or explicit stop. diff --git a/Tests/OpenGraphCxxTests/DebugServer/DebugServerTests.swift b/Tests/OpenGraphCxxTests/DebugServer/DebugServerTests.swift index db9b51fc..c1b17df8 100644 --- a/Tests/OpenGraphCxxTests/DebugServer/DebugServerTests.swift +++ b/Tests/OpenGraphCxxTests/DebugServer/DebugServerTests.swift @@ -25,7 +25,8 @@ struct DebugServerTests { @Test func commandTest() async throws { let debugServer = OG.DebugServer([.valid]) - let url = try #require(debugServer.copy_url()) as URL + let cfURL = debugServer.copy_url() + let url = try #require(cfURL) as URL let components = try #require(URLComponents(url: url, resolvingAgainstBaseURL: false)) let token = try #require(components.queryItems?.first { $0.name == "token" }?.value.flatMap { UInt32($0) }) debugServer.run(1)