43 template<
typename TPoller>
44 TPipe(TPoller& poller,
const std::string& exe,
const std::vector<std::string>& args,
bool stderrToStdout =
false)
45 : PipeLow(exe, args, stderrToStdout)
50 ReadHandle = std::make_unique<TPipeFileHandle<TPoller>>(PipeLow.ReadFd, poller);
51 WriteHandle = std::make_unique<TPipeFileHandle<TPoller>>(PipeLow.WriteFd, poller);
52 if (!stderrToStdout) {
53 ErrHandle = std::make_unique<TPipeFileHandle<TPoller>>(PipeLow.ErrFd, poller);
58 int Pid()
const {
return PipeLow.ChildPid; }
129 TPipeLow(
const std::string& exe,
const std::vector<std::string>& args,
bool mergeErr);
135 std::vector<std::string> Args;
142 bool StderrToStdout =
false;
145 struct ITypelessFileHandle {
146 virtual ~ITypelessFileHandle() =
default;
147 virtual TFuture<ssize_t> ReadSome(
void* buffer,
size_t size) = 0;
148 virtual TFuture<ssize_t> WriteSome(
const void* buffer,
size_t size) = 0;
151 template<
typename TPoller>
152 struct TPipeFileHandle final :
public ITypelessFileHandle {
153 TPipeFileHandle(
int fd, TPoller& poller)
157 TFuture<ssize_t> ReadSome(
void* buffer,
size_t size)
override {
158 co_return co_await Handle.ReadSome(buffer, size);
160 TFuture<ssize_t> WriteSome(
const void* buffer,
size_t size)
override {
161 co_return co_await Handle.WriteSome(buffer, size);
164 typename TPoller::TFileHandle Handle;
169 std::unique_ptr<ITypelessFileHandle> ReadHandle;
170 std::unique_ptr<ITypelessFileHandle> WriteHandle;
171 std::unique_ptr<ITypelessFileHandle> ErrHandle;
int Wait()
Waits for the child process to exit and returns its exit status.
Definition pipe.cpp:193
void CloseRead()
Closes the read end of the child's stdout pipe.
Definition pipe.hpp:61
TPipe(TPoller &poller, const std::string &exe, const std::vector< std::string > &args, bool stderrToStdout=false)
Spawns exe with args and wires up async I/O handles.
Definition pipe.hpp:44
void CloseWrite()
Closes the write end of the child's stdin pipe, sending EOF to the child.
Definition pipe.hpp:66
TFuture< ssize_t > ReadSome(void *buffer, size_t size)
Reads up to size bytes from the child's stdout.
Definition pipe.cpp:177
TFuture< ssize_t > WriteSome(const void *buffer, size_t size)
Writes up to size bytes to the child's stdin.
Definition pipe.cpp:189
TFuture< ssize_t > ReadSomeErr(void *buffer, size_t size)
Reads up to size bytes from the child's stderr.
Definition pipe.cpp:181
void CloseErr()
Closes the read end of the child's stderr pipe.
Definition pipe.hpp:71
int Pid() const
Returns the child's process ID.
Definition pipe.hpp:58
TFuture< int > AsyncWait()
Waits for the child process to exit without blocking the event loop.
Definition pipe.cpp:208
Implementation of a promise/future system for coroutines.
Owned coroutine handle that carries a result of type T.
Definition corochain.hpp:185