X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fproc.cpp;h=3137b0433a990e839a691a3d59f5d023e1c22cf7;hb=fd86376a8e7d3f1b09be3d018f772ef884937238;hp=33d1a14c9c83a8126d4bd039897aaa6a278b58cb;hpb=ca74cd8cdaf25b5ae778bef1dbabad21cea13b2d;p=blank.git diff --git a/src/app/proc.cpp b/src/app/proc.cpp index 33d1a14..3137b04 100644 --- a/src/app/proc.cpp +++ b/src/app/proc.cpp @@ -1,14 +1,16 @@ #include "Process.hpp" #ifdef _WIN32 -# error "TODO: windows implementation of Process" +# include +# include #else -# include # include +# include # include # include #endif +#include #include using namespace std; @@ -28,6 +30,7 @@ struct Process::Impl { size_t ReadOut(void *buffer, size_t max_len); size_t ReadErr(void *buffer, size_t max_len); + void Terminate(); int Join(); #ifdef _WIN32 @@ -72,6 +75,12 @@ size_t Process::ReadErr(void *buffer, size_t max_len) { return impl->ReadErr(buffer, max_len); } +void Process::Terminate() { + if (!joined) { + impl->Terminate(); + } +} + int Process::Join() { if (joined) { return status; @@ -266,6 +275,16 @@ size_t Process::Impl::ReadErr(void *buffer, size_t max_len) { #endif } +void Process::Impl::Terminate() { +#ifdef _WIN32 + if (!TerminateProcess(pi.hProcess, -1)) { +#else + if (kill(pid, SIGTERM) == -1) { +#endif + throw runtime_error("failed to terminate child process"); + } +} + int Process::Impl::Join() { #ifdef _WIN32 CloseHandle(fd_in[1]);