mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 07:36:41 +02:00
Revert back to process from boost::process
This commit is contained in:
parent
d493493868
commit
e195298e74
3 changed files with 259 additions and 24 deletions
|
@ -35,7 +35,8 @@ namespace streamreader
|
|||
static constexpr auto LOG_TAG = "ProcessStream";
|
||||
|
||||
|
||||
ProcessStream::ProcessStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const StreamUri& uri) : PosixStream(pcmListener, ioc, uri)
|
||||
ProcessStream::ProcessStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const StreamUri& uri)
|
||||
: PosixStream(pcmListener, ioc, uri), path_(""), process_(nullptr)
|
||||
{
|
||||
params_ = uri_.getQuery("params");
|
||||
wd_timeout_sec_ = cpt::stoul(uri_.getQuery("wd_timeout", "0"));
|
||||
|
@ -102,18 +103,11 @@ void ProcessStream::do_connect()
|
|||
return;
|
||||
initExeAndPath(uri_.path);
|
||||
LOG(DEBUG, LOG_TAG) << "Launching: '" << path_ + exe_ << "', with params: '" << params_ << "', in path: '" << path_ << "'\n";
|
||||
|
||||
pipe_stdout_ = bp::pipe();
|
||||
// could use bp::async_pipe, but this is broken in boost 1.72:
|
||||
// https://github.com/boostorg/process/issues/116
|
||||
pipe_stderr_ = bp::pipe();
|
||||
// stdout pipe should not block
|
||||
int flags = fcntl(pipe_stdout_.native_source(), F_GETFL, 0);
|
||||
fcntl(pipe_stdout_.native_source(), F_SETFL, flags | O_NONBLOCK);
|
||||
|
||||
process_ = bp::child(path_ + exe_ + " " + params_, bp::std_out > pipe_stdout_, bp::std_err > pipe_stderr_, bp::start_dir = path_);
|
||||
stream_ = make_unique<stream_descriptor>(ioc_, pipe_stdout_.native_source());
|
||||
stream_stderr_ = make_unique<stream_descriptor>(ioc_, pipe_stderr_.native_source());
|
||||
process_.reset(new Process(path_ + exe_ + " " + params_, path_));
|
||||
int flags = fcntl(process_->getStdout(), F_GETFL, 0);
|
||||
fcntl(process_->getStdout(), F_SETFL, flags | O_NONBLOCK);
|
||||
stream_ = make_unique<stream_descriptor>(ioc_, process_->getStdout());
|
||||
stream_stderr_ = make_unique<stream_descriptor>(ioc_, process_->getStderr());
|
||||
on_connect();
|
||||
if (wd_timeout_sec_ > 0)
|
||||
{
|
||||
|
@ -130,8 +124,8 @@ void ProcessStream::do_connect()
|
|||
|
||||
void ProcessStream::do_disconnect()
|
||||
{
|
||||
if (process_.running())
|
||||
::kill(-process_.native_handle(), SIGINT);
|
||||
if (process_)
|
||||
process_->kill();
|
||||
}
|
||||
|
||||
|
||||
|
@ -177,7 +171,7 @@ void ProcessStream::onTimeout(const Watchdog& /*watchdog*/, std::chrono::millise
|
|||
{
|
||||
LOG(ERROR, LOG_TAG) << "Watchdog timeout: " << ms.count() / 1000 << "s\n";
|
||||
if (process_)
|
||||
::kill(-process_.native_handle(), SIGINT);
|
||||
process_->kill();
|
||||
}
|
||||
|
||||
} // namespace streamreader
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue