flush
[awesomized/libmemcached] / testing / lib / ForkAndExec.hpp
index b88c56a727a1a0ba575765926a8a17b4afca675f..ad7b415150c38ec04b911c749263ec21cc7be194 100644 (file)
@@ -4,6 +4,8 @@
 
 class ForkAndExec {
 public:
+  enum mode { READ, WRITE };
+
   ForkAndExec(const char *binary, char **argv);
   ~ForkAndExec();
 
@@ -12,10 +14,17 @@ public:
   ForkAndExec(ForkAndExec &&) = default;
   ForkAndExec &operator = (ForkAndExec &&) = default;
 
-  optional<pid_t> operator () ();
+  [[nodiscard]]
+  int createPipe();
+  pid_t operator () ();
 
 private:
-  int pipes[2];
+  int ready[2], pipes[2];
   const char *binary;
   char **argv;
+
+  bool prepareExecReadyPipe();
+  void prepareOutputPipe();
+  void closePipe(int &fd);
+  void pollExecReadyPipe();
 };