Add an optional timeout parameter when waiting for a local process to exit

This commit is contained in:
Eric Frias 2014-05-14 08:51:30 -04:00
parent eb501387e8
commit db7b1bdd69
3 changed files with 10 additions and 9 deletions

View file

@ -31,13 +31,13 @@ namespace fc
* *
* @return *this * @return *this
*/ */
virtual iprocess& exec( const fc::path& exe, std::vector<std::string> args, virtual iprocess& exec( const path& exe, std::vector<std::string> args,
const fc::path& work_dir = fc::path(), exec_opts opts = open_all ) = 0; const path& work_dir = path(), exec_opts opts = open_all ) = 0;
/** /**
* @return blocks until the process exits * @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 * @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 * @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 * @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;
}; };

View file

@ -20,7 +20,8 @@ namespace fc {
const fc::path& work_dir = fc::path(), const fc::path& work_dir = fc::path(),
exec_opts opts = open_all ); exec_opts opts = open_all );
virtual int result();
virtual int result(const microseconds& timeout = microseconds::maximum());
virtual void kill(); virtual void kill();
virtual fc::buffered_ostream_ptr in_stream(); virtual fc::buffered_ostream_ptr in_stream();
virtual fc::buffered_istream_ptr out_stream(); virtual fc::buffered_istream_ptr out_stream();

View file

@ -179,9 +179,9 @@ fc::buffered_istream_ptr process::err_stream() {
return my->_err; return my->_err;
} }
int process::result() int process::result(const microseconds& timeout /* = microseconds::maximum() */)
{ {
return my->_exited.wait(); return my->_exited.wait(timeout);
} }
} }