MCPcopy Create free account
hub / github.com/78/tenbox / HandleClient

Method HandleClient

src/daemon/rpc_server.cpp:146–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146void RpcServer::HandleClient(ipc::UnixSocketConnection client) {
147 pthread_setname_np(pthread_self(), "rpc-handler");
148 const std::string line = client.ReadLine();
149 if (line.empty()) return;
150 auto request = nlohmann::json::parse(line, nullptr, false);
151 if (request.is_discarded()) {
152 auto response = Error("bad_json", "request is not valid JSON").dump() + "\n";
153 (void)client.Send(response);
154 return;
155 }
156
157 if (request.value("type", "") == "vm.console.attach") {
158 std::string error;
159 if (!runtime_manager_.AttachConsole(request.value("vm_id", ""), &client, &error)) {
160 auto response = Error("console_attach_failed", error).dump() + "\n";
161 (void)client.Send(response);
162 return;
163 }
164 return;
165 }
166
167 if (request.value("type", "") == "vm.logs.follow") {
168 std::string error;
169 if (!runtime_manager_.AttachLogFollower(request.value("vm_id", ""), &client, &error)) {
170 auto response = Error("logs_follow_failed", error).dump() + "\n";
171 (void)client.Send(response);
172 return;
173 }
174 return;
175 }
176
177 auto response = HandleRequest(request).dump();
178 response.push_back('\n');
179 (void)client.Send(response);
180}
181
182nlohmann::json RpcServer::HandleRequest(const nlohmann::json& request) {
183 const std::string type = request.value("type", "");

Callers

nothing calls this directly

Calls 5

AttachLogFollowerMethod · 0.80
ErrorFunction · 0.70
ReadLineMethod · 0.45
SendMethod · 0.45
AttachConsoleMethod · 0.45

Tested by

no test coverage detected