Skip to content

Commit f60acac

Browse files
committed
Reduce unecessary states for piped process statet
Reduce the number of possible states for the piped_process statet since we only really need to know if it's running or has an error for now.
1 parent 8510283 commit f60acac

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/util/piped_process.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ std::wstring process_windows_args(const std::vector<std::string> commandvec)
116116

117117
piped_processt::piped_processt(const std::vector<std::string> commandvec)
118118
{
119-
// Default state
120-
process_state = statet::NOT_CREATED;
121119
# ifdef _WIN32
122120
// Security attributes for pipe creation
123121
SECURITY_ATTRIBUTES sec_attr;
@@ -300,7 +298,7 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
300298
command_stream = fdopen(pipe_input[1], "w");
301299
}
302300
# endif
303-
process_state = statet::CREATED;
301+
process_state = statet::RUNNING;
304302
}
305303

306304
piped_processt::~piped_processt()
@@ -329,7 +327,7 @@ piped_processt::~piped_processt()
329327

330328
piped_processt::send_responset piped_processt::send(const std::string &message)
331329
{
332-
if(process_state != statet::CREATED)
330+
if(process_state != statet::RUNNING)
333331
{
334332
return send_responset::ERRORED;
335333
}
@@ -355,7 +353,7 @@ piped_processt::send_responset piped_processt::send(const std::string &message)
355353
std::string piped_processt::receive()
356354
{
357355
INVARIANT(
358-
process_state == statet::CREATED,
356+
process_state == statet::RUNNING,
359357
"Can only receive() from a fully initialised process");
360358
std::string response = std::string("");
361359
char buff[BUFSIZE];
@@ -374,7 +372,7 @@ std::string piped_processt::receive()
374372
// Added the status back in here to keep parity with old implementation
375373
// TODO: check which statuses are really used/needed.
376374
if(nbytes == 0) // Update if the pipe is stopped
377-
process_state = statet::STOPPED;
375+
process_state = statet::ERRORED;
378376
success = nbytes > 0;
379377
#endif
380378
INVARIANT(
@@ -464,7 +462,7 @@ bool piped_processt::can_receive()
464462

465463
void piped_processt::wait_receivable(int wait_time)
466464
{
467-
while(process_state == statet::CREATED && !can_receive(0))
465+
while(process_state == statet::RUNNING && !can_receive(0))
468466
{
469467
#ifdef _WIN32
470468
Sleep(wait_time);

src/util/piped_process.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class piped_processt
2727
/// Enumeration to keep track of child process state.
2828
enum class statet
2929
{
30-
NOT_CREATED,
31-
CREATED,
32-
STOPPED,
30+
RUNNING,
3331
ERRORED
3432
};
3533

0 commit comments

Comments
 (0)