diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-10-25 10:24:53 +0200 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2022-10-25 17:30:37 +0300 |
commit | b7f32cea30174e391027fecc9d431ca16b2f87c2 (patch) | |
tree | e9fe8c29bf361fa96b9a79243bffde0d1405b6e8 /libbutl/process.hxx | |
parent | 397d710073eae9ad282bc0df9482a41d621acde5 (diff) |
All passing to process ownership to one end of pipe
Diffstat (limited to 'libbutl/process.hxx')
-rw-r--r-- | libbutl/process.hxx | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/libbutl/process.hxx b/libbutl/process.hxx index 47cc507..cf5bcd8 100644 --- a/libbutl/process.hxx +++ b/libbutl/process.hxx @@ -298,21 +298,41 @@ namespace butl const char* const* envvars = nullptr); // If the descriptors are pipes that you have created, then you should use - // this constructor instead to communicate this information. + // this constructor instead to communicate this information (the parent + // end may need to be "probed" on Windows). // // For generality, if the "other" end of the pipe is -1, then assume this // is not a pipe. // struct pipe { - int in = -1; - int out = -1; - pipe () = default; pipe (int i, int o): in (i), out (o) {} explicit pipe (const fdpipe& p): in (p.in.get ()), out (p.out.get ()) {} + + // Transfer ownership to one end of the pipe. + // + pipe (auto_fd i, int o): in (i.release ()), out (o), own_in (true) {} + pipe (int i, auto_fd o): in (i), out (o.release ()), own_out (true) {} + + // Moveable-only type. + // + pipe (pipe&&); + pipe& operator= (pipe&&); + + pipe (const pipe&) = delete; + pipe& operator= (const pipe&) = delete; + + ~pipe (); + + public: + int in = -1; + int out = -1; + + bool own_in = false; + bool own_out = false; }; process (const process_path&, const char* [], |