41 template<
typename TPoller>
42 TPipe(TPoller& poller,
const std::string& exe,
const std::vector<std::string>& args,
bool stderrToStdout =
false)
43 : PipeLow(exe, args, stderrToStdout)
47 ReadHandle = std::make_unique<TPipeFileHandle<TPoller>>(PipeLow.ReadFd, poller);
48 WriteHandle = std::make_unique<TPipeFileHandle<TPoller>>(PipeLow.WriteFd, poller);
49 if (!stderrToStdout) {
50 ErrHandle = std::make_unique<TPipeFileHandle<TPoller>>(PipeLow.ErrFd, poller);
55 int Pid()
const {
return PipeLow.ChildPid; }
108 TPipeLow(
const std::string& exe,
const std::vector<std::string>& args,
bool mergeErr);
114 std::vector<std::string> Args;
121 bool StderrToStdout =
false;
124 struct TTypelessFileHandle {
125 virtual ~TTypelessFileHandle() =
default;
126 virtual TFuture<ssize_t> ReadSome(
void* buffer,
size_t size) = 0;
127 virtual TFuture<ssize_t> WriteSome(
const void* buffer,
size_t size) = 0;
130 template<
typename TPoller>
131 struct TPipeFileHandle :
public TTypelessFileHandle {
132 TPipeFileHandle(
int fd, TPoller& poller)
136 TFuture<ssize_t> ReadSome(
void* buffer,
size_t size)
override {
137 co_return co_await Handle.ReadSome(buffer, size);
139 TFuture<ssize_t> WriteSome(
const void* buffer,
size_t size)
override {
140 co_return co_await Handle.WriteSome(buffer, size);
143 typename TPoller::TFileHandle Handle;
147 std::unique_ptr<TTypelessFileHandle> ReadHandle;
148 std::unique_ptr<TTypelessFileHandle> WriteHandle;
149 std::unique_ptr<TTypelessFileHandle> ErrHandle;
Spawns a child process and exposes its stdin/stdout/stderr as async handles.
Definition pipe.hpp:30
int Wait()
Waits for the child process to exit and returns its exit status.
Definition pipe.cpp:187
void CloseRead()
Closes the read end of the child's stdout pipe.
Definition pipe.hpp:58
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:42
void CloseWrite()
Closes the write end of the child's stdin pipe, sending EOF to the child.
Definition pipe.hpp:63
TFuture< ssize_t > ReadSome(void *buffer, size_t size)
Reads up to size bytes from the child's stdout.
Definition pipe.cpp:171
TFuture< ssize_t > WriteSome(const void *buffer, size_t size)
Writes up to size bytes to the child's stdin.
Definition pipe.cpp:183
TFuture< ssize_t > ReadSomeErr(void *buffer, size_t size)
Reads up to size bytes from the child's stderr.
Definition pipe.cpp:175
void CloseErr()
Closes the read end of the child's stderr pipe.
Definition pipe.hpp:68
int Pid() const
Returns the child's process ID.
Definition pipe.hpp:55
Implementation of a promise/future system for coroutines.
Owned coroutine handle that carries a result of type T.
Definition corochain.hpp:185