66#include < cstring>
77#include < fcntl.h>
88#include < vector>
9- #include < boost/process/v1/pipe.hpp>
10- #include < boost/process/v1/io.hpp>
11- #include < boost/process/v1/child.hpp>
9+
10+ #include < boost/process/pipe.hpp>
11+ #include < boost/process/io.hpp>
12+ #include < boost/process/child.hpp>
13+
1214#include < boost/asio.hpp>
1315#include < boost/asio/posix/stream_descriptor.hpp>
1416
1517using namespace StormByte ::VideoConvert;
1618
17- Task::Execute::Base::Base (const Types::path_t & program, const std::string& arguments):Task::Base(), m_executables({ Executable (program, arguments) }) {}
18-
19- Task::Execute::Base::Base (Types::path_t && program, std::string&& arguments):Task::Base(), m_executables({ Executable (std::move (program), std::move (arguments)) }) {}
19+ Task::Execute::Base::Base (const Types::path_t & program, const std::string& arguments)
20+ : Task::Base(), m_executables({ Executable (program, arguments) }) {}
2021
21- Task::Execute::Base::Base (const std::vector<Executable>& execs):Task::Base(), m_executables(execs) {}
22+ Task::Execute::Base::Base (Types::path_t && program, std::string&& arguments)
23+ : Task::Base(), m_executables({ Executable (std::move (program), std::move (arguments)) }) {}
2224
23- Task::Execute::Base::Base (std::vector<Executable>&& execs):Task::Base(), m_executables(std::move(execs)) {}
25+ Task::Execute::Base::Base (const std::vector<Executable>& execs)
26+ : Task::Base(), m_executables(execs) {}
2427
28+ Task::Execute::Base::Base (std::vector<Executable>&& execs)
29+ : Task::Base(), m_executables(std::move(execs)) {}
2530
2631Task::STATUS Task::Execute::Base::do_work (std::optional<pid_t >& worker) noexcept {
2732 using namespace boost ;
@@ -32,21 +37,18 @@ Task::STATUS Task::Execute::Base::do_work(std::optional<pid_t>& worker) noexcept
3237 asio::io_context ios;
3338
3439 try {
35-
3640 std::vector<char > vOut (128 << 10 );
3741 std::vector<char > vErr (128 << 10 );
3842 auto outBuffer{ asio::buffer (vOut) };
3943 auto errBuffer{ asio::buffer (vErr) };
4044 auto inBuffer{ asio::buffer (m_stdin) };
4145
4246 // stdout setup
43- // stdout setup: use a pipe + posix stream_descriptor for async reads
44- boost::process::v1::pipe pipeOut;
45- asio::posix::stream_descriptor sdOut (ios, pipeOut.native_source ());
47+ process::pipe pipeOut;
48+ asio::posix::stream_descriptor sdOut (ios, pipeOut.native_source ());
4649
47- std::function<void (const system::error_code & ec, std::size_t n)> onStdOut;
48- onStdOut = [&](const system::error_code & ec, size_t n)
49- {
50+ std::function<void (const system::error_code&, std::size_t )> onStdOut;
51+ onStdOut = [&](const system::error_code& ec, size_t n) {
5052 m_stdout.reserve (m_stdout.size () + n);
5153 m_stdout.insert (m_stdout.end (), vOut.begin (), vOut.begin () + n);
5254 if (!ec) {
@@ -55,49 +57,46 @@ Task::STATUS Task::Execute::Base::do_work(std::optional<pid_t>& worker) noexcept
5557 };
5658
5759 // stderr setup
58- boost:: process::v1 ::pipe pipeErr;
59- asio::posix::stream_descriptor sdErr (ios, pipeErr.native_source ());
60+ process::pipe pipeErr;
61+ asio::posix::stream_descriptor sdErr (ios, pipeErr.native_source ());
6062
61- std::function<void (const system::error_code & ec , std::size_t n )> onStdErr;
62- onStdErr = [&](const system::error_code & ec, size_t n) {
63+ std::function<void (const system::error_code& , std::size_t )> onStdErr;
64+ onStdErr = [&](const system::error_code& ec, size_t n) {
6365 m_stderr.reserve (m_stderr.size () + n);
6466 m_stderr.insert (m_stderr.end (), vErr.begin (), vErr.begin () + n);
65- if (!ec)
66- {
67+ if (!ec) {
6768 asio::async_read (sdErr, errBuffer, onStdErr);
6869 }
6970 };
7071
7172 // stdin setup
72- boost:: process::v1 ::pipe pipeIn;
73- asio::posix::stream_descriptor sdIn (ios, pipeIn.native_sink ());
73+ process::pipe pipeIn;
74+ asio::posix::stream_descriptor sdIn (ios, pipeIn.native_sink ());
7475
7576 if (m_logger)
76- m_logger->message_line (Utils::Logger::LEVEL_DEBUG, " Executing " + m_executables[0 ].m_program .string () + " " + m_executables[0 ].m_arguments );
77+ m_logger->message_line (Utils::Logger::LEVEL_DEBUG,
78+ " Executing " + m_executables[0 ].m_program .string () + " " + m_executables[0 ].m_arguments );
7779
78- boost:: process::v1 ::child c (
80+ process::child c (
7981 m_executables[0 ].m_program .string () + " " + m_executables[0 ].m_arguments ,
80- boost:: process::v1 ::std_out > pipeOut,
81- boost:: process::v1 ::std_err > pipeErr,
82- boost:: process::v1 ::std_in < pipeIn
82+ process::std_out > pipeOut,
83+ process::std_err > pipeErr,
84+ process::std_in < pipeIn
8385 );
8486
85-
8687 asio::async_write (sdIn, inBuffer,
8788 [&](const system::error_code&, std::size_t ) {
88- // close the parent write end to signal EOF to child
8989 boost::system::error_code ec;
9090 sdIn.close (ec);
9191 });
9292
9393 asio::async_read (sdOut, outBuffer, onStdOut);
9494 asio::async_read (sdErr, errBuffer, onStdErr);
95-
96- // We update worker BEFORE this is run as this is a blocking call
95+
9796 worker = c.id ();
9897 ios.run ();
9998 c.wait ();
100- if (c.exit_code () == 0 ) status = HALT_OK; else status = HALT_ERROR;
99+ status = (c.exit_code () == 0 ) ? HALT_OK : HALT_ERROR;
101100 }
102101 catch (const std::exception&) {
103102 status = HALT_ERROR;
0 commit comments