| 111 | } |
| 112 | |
| 113 | std::string AgentClient::create_socket(const std::string& identifier) |
| 114 | { |
| 115 | // Check if a socket has already been created. |
| 116 | // If a socket exists, log an error and return the existing identifier. |
| 117 | // Multiple socket creations are not allowed by design. |
| 118 | if (!identifier_.empty()) { |
| 119 | LogError << "Attempted to create a new socket, but one already exists. Returning the existing socket identifier." |
| 120 | << VAR(identifier_); |
| 121 | return identifier_; |
| 122 | } |
| 123 | |
| 124 | if (auto port_opt = parse_tcp_port(identifier)) { |
| 125 | LogInfo << "Using TCP mode" << VAR(*port_opt); |
| 126 | return create_tcp_socket(*port_opt); |
| 127 | } |
| 128 | |
| 129 | if (should_fallback_to_tcp()) { |
| 130 | LogInfo << "IPC may fail on this system, using TCP instead"; |
| 131 | return create_tcp_socket(0); |
| 132 | } |
| 133 | |
| 134 | // Create a new socket with the provided identifier or generate a new one if empty. |
| 135 | identifier_ = identifier.empty() ? make_uuid() : identifier; |
| 136 | init_socket(identifier_, true); |
| 137 | |
| 138 | return identifier_; |
| 139 | } |
| 140 | |
| 141 | std::string AgentClient::create_tcp_socket(uint16_t port) |
| 142 | { |
no test coverage detected