@@ -68,59 +68,61 @@ ProcessExecutor::ProcessExecutor(const std::list<std::pair<std::string, std::siz
6868 assert (mSettings .jobs > 1 );
6969}
7070
71- class PipeWriter : public ErrorLogger {
72- public:
73- enum PipeSignal {REPORT_OUT=' 1' ,REPORT_ERROR=' 2' , CHILD_END=' 5' };
71+ namespace {
72+ class PipeWriter : public ErrorLogger {
73+ public:
74+ enum PipeSignal {REPORT_OUT=' 1' ,REPORT_ERROR=' 2' , CHILD_END=' 5' };
7475
75- explicit PipeWriter (int pipe) : mWpipe(pipe) {}
76+ explicit PipeWriter (int pipe) : mWpipe(pipe) {}
7677
77- void reportOut (const std::string &outmsg, Color c) override {
78- writeToPipe (REPORT_OUT, static_cast <char >(c) + outmsg);
79- }
80-
81- void reportErr (const ErrorMessage &msg) override {
82- writeToPipe (REPORT_ERROR, msg.serialize ());
83- }
84-
85- void writeEnd (const std::string& str) const {
86- writeToPipe (CHILD_END, str);
87- }
78+ void reportOut (const std::string &outmsg, Color c) override {
79+ writeToPipe (REPORT_OUT, static_cast <char >(c) + outmsg);
80+ }
8881
89- private:
90- // TODO: how to log file name in error?
91- void writeToPipeInternal (PipeSignal type, const void * data, std::size_t to_write) const
92- {
93- const ssize_t bytes_written = write (mWpipe , data, to_write);
94- if (bytes_written <= 0 ) {
95- const int err = errno;
96- std::cerr << " #### ThreadExecutor::writeToPipeInternal() error for type " << type << " : " << std::strerror (err) << std::endl;
97- std::exit (EXIT_FAILURE);
82+ void reportErr (const ErrorMessage &msg) override {
83+ writeToPipe (REPORT_ERROR, msg.serialize ());
9884 }
99- // TODO: write until everything is written
100- if (bytes_written != to_write) {
101- std::cerr << " #### ThreadExecutor::writeToPipeInternal() error for type " << type << " : insufficient data written (expected: " << to_write << " / got: " << bytes_written << " )" << std::endl;
102- std::exit (EXIT_FAILURE);
85+
86+ void writeEnd (const std::string& str) const {
87+ writeToPipe (CHILD_END, str);
10388 }
104- }
10589
106- void writeToPipe (PipeSignal type, const std::string &data) const
107- {
90+ private:
91+ // TODO: how to log file name in error?
92+ void writeToPipeInternal (PipeSignal type, const void * data, std::size_t to_write) const
10893 {
109- const char t = static_cast <char >(type);
110- writeToPipeInternal (type, &t, 1 );
94+ const ssize_t bytes_written = write (mWpipe , data, to_write);
95+ if (bytes_written <= 0 ) {
96+ const int err = errno;
97+ std::cerr << " #### ThreadExecutor::writeToPipeInternal() error for type " << type << " : " << std::strerror (err) << std::endl;
98+ std::exit (EXIT_FAILURE);
99+ }
100+ // TODO: write until everything is written
101+ if (bytes_written != to_write) {
102+ std::cerr << " #### ThreadExecutor::writeToPipeInternal() error for type " << type << " : insufficient data written (expected: " << to_write << " / got: " << bytes_written << " )" << std::endl;
103+ std::exit (EXIT_FAILURE);
104+ }
111105 }
112106
113- const unsigned int len = static_cast < unsigned int >( data. length ());
107+ void writeToPipe (PipeSignal type, const std::string & data) const
114108 {
115- static constexpr std::size_t l_size = sizeof (unsigned int );
116- writeToPipeInternal (type, &len, l_size);
117- }
109+ {
110+ const char t = static_cast <char >(type);
111+ writeToPipeInternal (type, &t, 1 );
112+ }
118113
119- writeToPipeInternal (type, data.c_str (), len);
120- }
114+ const unsigned int len = static_cast <unsigned int >(data.length ());
115+ {
116+ static constexpr std::size_t l_size = sizeof (unsigned int );
117+ writeToPipeInternal (type, &len, l_size);
118+ }
121119
122- const int mWpipe ;
123- };
120+ writeToPipeInternal (type, data.c_str (), len);
121+ }
122+
123+ const int mWpipe ;
124+ };
125+ }
124126
125127bool ProcessExecutor::handleRead (int rpipe, unsigned int &result, const std::string& filename)
126128{
0 commit comments