Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12_20] set default timeout to 25*20ms and 2*20ms for check_output #244

Merged
merged 5 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions lolly/system/subprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ call (string cmd) {
}

int
check_output (string s, string& result) {
check_output (string s, string& result, int64_t timeout) {
tb_long_t status= -1;
// init pipe files
tb_pipe_file_ref_t file[2]= {0};
Expand Down Expand Up @@ -57,8 +57,15 @@ check_output (string s, string& result) {
wait= tb_false;
}
else if (!real && !wait) {
// wait pipe
tb_long_t ok= tb_pipe_file_wait (file[0], TB_PIPE_EVENT_READ, 1000);
tb_long_t ok = 0;
int retry= 25;
if (read > 0) {
retry= 2;
}
while (retry > 0 && (ok == 0)) {
ok = tb_pipe_file_wait (file[0], TB_PIPE_EVENT_READ, timeout);
retry= retry - 1;
}
tb_check_break (ok > 0);
wait= tb_true;
}
Expand All @@ -68,7 +75,7 @@ check_output (string s, string& result) {
result= as_string ((tb_char_t*) data);

// wait process
tb_process_wait (process, &status, -1);
tb_process_wait (process, &status, timeout);

// exit process
tb_process_exit (process);
Expand Down
2 changes: 1 addition & 1 deletion lolly/system/subprocess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
namespace lolly {
namespace system {
int call (string cmd);
int check_output (string cmd, string& result);
int check_output (string cmd, string& result, int64_t timeout= 20);
} // namespace system
} // namespace lolly