Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
transport_stdio.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
13#pragma once
14
16
17#include <atomic>
18#include <chrono>
19#include <map>
20#include <mutex>
21#include <string>
22#include <thread>
23#include <vector>
24
25#include <sys/types.h>
26
27namespace entropic {
28
37class StdioTransport : public Transport {
38public:
49 std::string command,
50 std::vector<std::string> args,
51 std::map<std::string, std::string> env = {},
52 uint32_t default_timeout_ms = 30000);
53
78 std::string display_name,
79 std::string command,
80 std::vector<std::string> args,
81 std::map<std::string, std::string> env,
82 uint32_t default_timeout_ms);
83
84 ~StdioTransport() override;
85
91 bool open() override;
92
97 void close() override;
98
106 std::string send_request(
107 const std::string& request_json,
108 uint32_t timeout_ms = 0) override;
109
115 bool is_connected() const override;
116
126 void interrupt() override;
127
141 const std::string& display_name() const { return display_name_; }
142
143private:
144 std::atomic<bool> cancel_flag_{false};
145
146 std::string display_name_;
147 std::string command_;
148 std::vector<std::string> args_;
149 std::map<std::string, std::string> env_;
150 uint32_t default_timeout_ms_;
151
152 pid_t child_pid_{-1};
153 int stdin_fd_{-1};
154 int stdout_fd_{-1};
155 int stderr_fd_{-1};
156 std::atomic<bool> connected_{false};
157 std::thread stderr_thread_;
158 std::mutex io_mutex_;
159
166 std::vector<std::string> build_env() const;
167
178 bool spawn_child(int stdin_r, int stdout_w, int stderr_w,
179 const std::vector<std::string>& env_strs);
180
189 static bool create_pipe(int& read_fd, int& write_fd);
190
199 std::string read_line(int fd, uint32_t timeout_ms);
200
211 int poll_until_ready(
212 int fd,
213 std::chrono::steady_clock::time_point deadline);
214
222 bool create_all_pipes(int (&fds)[6]);
223
230 bool open_child_process();
231
237 void stderr_reader_loop();
238
244 void terminate_child();
245
252 static void close_fd(int& fd);
253};
254
255} // namespace entropic
Stdio transport: fork/exec child, pipe stdin/stdout.
bool open() override
Spawn child process and open pipes.
bool is_connected() const override
Check if child process is alive.
void interrupt() override
Abort any blocking read and mark transport uncancellable.
std::string send_request(const std::string &request_json, uint32_t timeout_ms=0) override
Send JSON-RPC request via stdin, read response from stdout.
void close() override
Send SIGTERM, reap child, close pipes.
const std::string & display_name() const
Get the sanitized display name used for stderr labeling.
~StdioTransport() override
Destructor — ensures child is cleaned up.
Abstract transport for external MCP communication.
Definition transport.h:29
Activate model on GPU (WARM → ACTIVE).
Abstract transport for external MCP server communication.