Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion Sources/OpenGraphCxx/DebugServer/DebugServer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 <OpenGraphCxx/DebugServer/DebugServer.hpp>
#if OG_TARGET_OS_DARWIN

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <OpenGraphCxx/Vector/vector.hpp>
#include <dispatch/dispatch.h>
#include <memory>
#include <swift/bridging>

OG_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -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();
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion Tests/OpenGraphCxxTests/DebugServer/DebugServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down