diff options
author | Evan Martin <martine@danga.com> | 2011-05-06 18:46:11 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-05-06 19:21:06 (GMT) |
commit | 6cf3f79fb45e196bd47ea25f9c030c3364494ebc (patch) | |
tree | ad165d26cee376a8383b3ffa44acbb31cad4626c /src/subprocess.h | |
parent | 661c5435e8bf108ded8ba795cc0a3aafda03b791 (diff) | |
download | Ninja-6cf3f79fb45e196bd47ea25f9c030c3364494ebc.zip Ninja-6cf3f79fb45e196bd47ea25f9c030c3364494ebc.tar.gz Ninja-6cf3f79fb45e196bd47ea25f9c030c3364494ebc.tar.bz2 |
windows: subprocess implementation for Windows
Heavily based on a patch from Sergey Nenakhov <nenakhov.sergey@gmail.com>.
Diffstat (limited to 'src/subprocess.h')
-rw-r--r-- | src/subprocess.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/subprocess.h b/src/subprocess.h index 934a220..9828bf4 100644 --- a/src/subprocess.h +++ b/src/subprocess.h @@ -20,6 +20,10 @@ #include <queue> using namespace std; +#ifdef _WIN32 +#include <windows.h> +#endif + /// Subprocess wraps a single async subprocess. It is entirely /// passive: it expects the caller to notify it when its fds are ready /// for reading, as well as call Finish() to reap the child once done() @@ -27,8 +31,8 @@ using namespace std; struct Subprocess { Subprocess(); ~Subprocess(); - bool Start(const string& command); - void OnFDReady(); + bool Start(struct SubprocessSet* set, const string& command); + void OnPipeReady(); /// Returns true on successful process exit. bool Finish(); @@ -38,8 +42,20 @@ struct Subprocess { private: string buf_; + +#ifdef _WIN32 + /// Set up pipe_ as the parent-side pipe of the subprocess; return the + /// other end of the pipe, usable in the child process. + HANDLE SetupPipe(HANDLE ioport); + + HANDLE child_; + HANDLE pipe_; + OVERLAPPED overlapped_; + char overlapped_buf_[4 << 10]; +#else int fd_; pid_t pid_; +#endif friend struct SubprocessSet; }; @@ -48,12 +64,19 @@ struct Subprocess { /// DoWork() waits for any state change in subprocesses; finished_ /// is a queue of subprocesses as they finish. struct SubprocessSet { + SubprocessSet(); + ~SubprocessSet(); + void Add(Subprocess* subprocess); void DoWork(); Subprocess* NextFinished(); vector<Subprocess*> running_; queue<Subprocess*> finished_; + +#ifdef _WIN32 + HANDLE ioport_; +#endif }; #endif // NINJA_SUBPROCESS_H_ |