mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 07:36:41 +02:00
Use async_pipe for stderr reading
This commit is contained in:
parent
ad05e87f6d
commit
32ca5144a5
2 changed files with 5 additions and 6 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), pipe_stderr_(ioc)
|
||||
{
|
||||
params_ = uri_.getQuery("params");
|
||||
wd_timeout_sec_ = cpt::stoul(uri_.getQuery("wd_timeout", "0"));
|
||||
|
@ -104,14 +105,13 @@ void ProcessStream::do_connect()
|
|||
LOG(DEBUG, LOG_TAG) << "Launching: '" << path_ + exe_ << "', with params: '" << params_ << "', in path: '" << path_ << "'\n";
|
||||
|
||||
pipe_stdout_ = bp::pipe();
|
||||
pipe_stderr_ = bp::pipe();
|
||||
pipe_stderr_ = bp::async_pipe(ioc_);
|
||||
// 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());
|
||||
on_connect();
|
||||
if (wd_timeout_sec_ > 0)
|
||||
{
|
||||
|
@ -147,7 +147,7 @@ void ProcessStream::stderrReadLine()
|
|||
const std::string delimiter = "\n";
|
||||
auto self(shared_from_this());
|
||||
boost::asio::async_read_until(
|
||||
*stream_stderr_, streambuf_stderr_, delimiter, [this, self, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
||||
pipe_stderr_, streambuf_stderr_, delimiter, [this, self, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
||||
if (ec)
|
||||
{
|
||||
LOG(ERROR, LOG_TAG) << "Error while reading from stderr: " << ec.message() << "\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue