From db7b1bdd69a46ab099cab95eee4c12fe49d6eb1c Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Wed, 14 May 2014 08:51:30 -0400 Subject: [PATCH] Add an optional timeout parameter when waiting for a local process to exit --- include/fc/interprocess/iprocess.hpp | 12 ++++++------ include/fc/interprocess/process.hpp | 3 ++- src/interprocess/process.cpp | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/fc/interprocess/iprocess.hpp b/include/fc/interprocess/iprocess.hpp index 3dcbfed..0f8671e 100644 --- a/include/fc/interprocess/iprocess.hpp +++ b/include/fc/interprocess/iprocess.hpp @@ -31,13 +31,13 @@ namespace fc * * @return *this */ - virtual iprocess& exec( const fc::path& exe, std::vector args, - const fc::path& work_dir = fc::path(), exec_opts opts = open_all ) = 0; + virtual iprocess& exec( const path& exe, std::vector args, + const path& work_dir = path(), exec_opts opts = open_all ) = 0; /** * @return blocks until the process exits */ - virtual int result() = 0; + virtual int result(const microseconds& timeout = microseconds::maximum()) = 0; /** @@ -48,16 +48,16 @@ namespace fc /** * @brief returns a stream that writes to the process' stdin */ - virtual fc::buffered_ostream_ptr in_stream() = 0; + virtual buffered_ostream_ptr in_stream() = 0; /** * @brief returns a stream that reads from the process' stdout */ - virtual fc::buffered_istream_ptr out_stream() = 0; + virtual buffered_istream_ptr out_stream() = 0; /** * @brief returns a stream that reads from the process' stderr */ - virtual fc::buffered_istream_ptr err_stream() = 0; + virtual buffered_istream_ptr err_stream() = 0; }; diff --git a/include/fc/interprocess/process.hpp b/include/fc/interprocess/process.hpp index eb13a4a..28333ef 100644 --- a/include/fc/interprocess/process.hpp +++ b/include/fc/interprocess/process.hpp @@ -20,7 +20,8 @@ namespace fc { const fc::path& work_dir = fc::path(), exec_opts opts = open_all ); - virtual int result(); + + virtual int result(const microseconds& timeout = microseconds::maximum()); virtual void kill(); virtual fc::buffered_ostream_ptr in_stream(); virtual fc::buffered_istream_ptr out_stream(); diff --git a/src/interprocess/process.cpp b/src/interprocess/process.cpp index 5cb46d6..5504138 100644 --- a/src/interprocess/process.cpp +++ b/src/interprocess/process.cpp @@ -179,9 +179,9 @@ fc::buffered_istream_ptr process::err_stream() { return my->_err; } -int process::result() +int process::result(const microseconds& timeout /* = microseconds::maximum() */) { - return my->_exited.wait(); + return my->_exited.wait(timeout); } }