inline bool wait_for( child_handle &p, int & exit_code, const std::chrono::duration<Rep, Period>& rel_time) { std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(rel_time); ::boost::detail::winapi::DWORD_ wait_code; wait_code = ::boost::detail::winapi::WaitForSingleObject(p.process_handle(), static_cast<::boost::detail::winapi::DWORD_>(ms.count())); if (wait_code == ::boost::detail::winapi::wait_failed) throw_last_error("WaitForSingleObject() failed"); else if (wait_code == ::boost::detail::winapi::wait_timeout) return false; // ::boost::detail::winapi::DWORD_ _exit_code; if (!::boost::detail::winapi::GetExitCodeProcess(p.process_handle(), &_exit_code)) throw_last_error("GetExitCodeProcess() failed"); exit_code = static_cast<int>(_exit_code); ::boost::detail::winapi::CloseHandle(p.proc_info.hProcess); p.proc_info.hProcess = ::boost::detail::winapi::INVALID_HANDLE_VALUE_; return true; }
inline bool wait_until( child_handle &p, int & exit_code, const std::chrono::time_point<Clock, Duration>& timeout_time, std::error_code &ec) noexcept { std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>( timeout_time - std::chrono::system_clock::now()); ::boost::detail::winapi::DWORD_ _exit_code = 1; if (::boost::detail::winapi::WaitForSingleObject(p.process_handle(), static_cast<::boost::detail::winapi::DWORD_>(ms.count())) == ::boost::detail::winapi::wait_failed) ec = std::error_code( ::boost::detail::winapi::GetLastError(), std::system_category()); else if (!::boost::detail::winapi::GetExitCodeProcess(p.process_handle(), &_exit_code)) ec = std::error_code( ::boost::detail::winapi::GetLastError(), std::system_category()); else ec.clear(); exit_code = static_cast<int>(exit_code); ::boost::detail::winapi::CloseHandle(p.proc_info.hProcess); p.proc_info.hProcess = ::boost::detail::winapi::INVALID_HANDLE_VALUE_; return true; ; }
inline void wait(child_handle &p, int & exit_code) { if (::boost::detail::winapi::WaitForSingleObject(p.process_handle(), ::boost::detail::winapi::infinite) == ::boost::detail::winapi::wait_failed) throw_last_error("WaitForSingleObject() failed"); ::boost::detail::winapi::DWORD_ _exit_code; if (!::boost::detail::winapi::GetExitCodeProcess(p.process_handle(), &_exit_code)) throw_last_error("GetExitCodeProcess() failed"); ::boost::detail::winapi::CloseHandle(p.proc_info.hProcess); p.proc_info.hProcess = ::boost::detail::winapi::INVALID_HANDLE_VALUE_; exit_code = static_cast<int>(_exit_code); }
inline void terminate(child_handle &p) { if (!::boost::detail::winapi::TerminateProcess(p.process_handle(), EXIT_FAILURE)) boost::process::detail::throw_last_error("TerminateProcess() failed"); ::boost::detail::winapi::CloseHandle(p.proc_info.hProcess); p.proc_info.hProcess = ::boost::detail::winapi::INVALID_HANDLE_VALUE_; }
inline void wait(child_handle &p, int & exit_code, std::error_code &ec) noexcept { ::boost::detail::winapi::DWORD_ _exit_code = 1; if (::boost::detail::winapi::WaitForSingleObject(p.process_handle(), ::boost::detail::winapi::infinite) == ::boost::detail::winapi::wait_failed) ec = std::error_code( ::boost::detail::winapi::GetLastError(), std::system_category()); else if (!::boost::detail::winapi::GetExitCodeProcess(p.process_handle(), &_exit_code)) ec = std::error_code( ::boost::detail::winapi::GetLastError(), std::system_category()); else ec.clear(); ::boost::detail::winapi::CloseHandle(p.proc_info.hProcess); p.proc_info.hProcess = ::boost::detail::winapi::INVALID_HANDLE_VALUE_; exit_code = static_cast<int>(_exit_code); }
inline void terminate(child_handle &p, std::error_code &ec) noexcept { if (!::boost::detail::winapi::TerminateProcess(p.process_handle(), EXIT_FAILURE)) ec = boost::process::detail::get_last_error(); else { ec.clear(); ::boost::detail::winapi::CloseHandle(p.proc_info.hProcess); p.proc_info.hProcess = ::boost::detail::winapi::INVALID_HANDLE_VALUE_; } }
inline bool wait_for( child_handle &p, int & exit_code, const std::chrono::duration<Rep, Period>& rel_time, std::error_code &ec) noexcept { std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(rel_time); ::boost::detail::winapi::DWORD_ wait_code; wait_code = ::boost::detail::winapi::WaitForSingleObject(p.process_handle(), static_cast<::boost::detail::winapi::DWORD_>(ms.count())); if (wait_code == ::boost::detail::winapi::wait_failed) ec = std::error_code( ::boost::detail::winapi::GetLastError(), std::system_category()); else if (wait_code == ::boost::detail::winapi::wait_timeout) return false; // ::boost::detail::winapi::DWORD_ _exit_code = 1; if (!::boost::detail::winapi::GetExitCodeProcess(p.process_handle(), &_exit_code)) { ec = std::error_code( ::boost::detail::winapi::GetLastError(), std::system_category()); return false; } else ec.clear(); exit_code = static_cast<int>(_exit_code); ::boost::detail::winapi::CloseHandle(p.proc_info.hProcess); p.proc_info.hProcess = ::boost::detail::winapi::INVALID_HANDLE_VALUE_; return true; ; }
inline bool is_running(const child_handle &p, int & exit_code) { ::boost::detail::winapi::DWORD_ code; //single value, not needed in the winapi. if (!::boost::detail::winapi::GetExitCodeProcess(p.process_handle(), &code)) ::boost::process::detail::throw_last_error("GetExitCodeProcess() failed"); if (code == still_active) return true; else { exit_code = code; return false; } }
inline bool is_running(const child_handle &p, int & exit_code, std::error_code &ec) noexcept { ::boost::detail::winapi::DWORD_ code; //single value, not needed in the winapi. if (!::boost::detail::winapi::GetExitCodeProcess(p.process_handle(), &code)) ec = ::boost::process::detail::get_last_error(); else ec.clear(); if (code == still_active) return true; else { exit_code = code; return false; } }