From 694a2fc6bd80b3ad005bfcdea8b6432c477b53c8 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Wed, 3 Jan 2024 18:08:39 +0800 Subject: [PATCH 1/5] [12_20] set default timeout to 50ms for check_output --- lolly/system/subprocess.cpp | 4 ++-- lolly/system/subprocess.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lolly/system/subprocess.cpp b/lolly/system/subprocess.cpp index bd9cb48f0..60f10e9fa 100644 --- a/lolly/system/subprocess.cpp +++ b/lolly/system/subprocess.cpp @@ -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}; @@ -58,7 +58,7 @@ check_output (string s, string& result) { } 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= tb_pipe_file_wait (file[0], TB_PIPE_EVENT_READ, timeout); tb_check_break (ok > 0); wait= tb_true; } diff --git a/lolly/system/subprocess.hpp b/lolly/system/subprocess.hpp index 65ca1c21b..77232eed4 100644 --- a/lolly/system/subprocess.hpp +++ b/lolly/system/subprocess.hpp @@ -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= 50); } // namespace system } // namespace lolly From 37c1a7d4f5a2a7c0c2b2252fc6542628e0211847 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Wed, 3 Jan 2024 18:11:42 +0800 Subject: [PATCH 2/5] 100ms --- lolly/system/subprocess.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lolly/system/subprocess.hpp b/lolly/system/subprocess.hpp index 77232eed4..88a36be67 100644 --- a/lolly/system/subprocess.hpp +++ b/lolly/system/subprocess.hpp @@ -16,6 +16,6 @@ namespace lolly { namespace system { int call (string cmd); -int check_output (string cmd, string& result, int64_t timeout= 50); +int check_output (string cmd, string& result, int64_t timeout= 100); } // namespace system } // namespace lolly From 76227f57bc1a0e58eadfd604dd54deb8af7b2381 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Wed, 3 Jan 2024 18:40:15 +0800 Subject: [PATCH 3/5] debug --- lolly/system/subprocess.cpp | 19 +++++++++++-------- lolly/system/subprocess.hpp | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lolly/system/subprocess.cpp b/lolly/system/subprocess.cpp index 60f10e9fa..8d8cade0e 100644 --- a/lolly/system/subprocess.cpp +++ b/lolly/system/subprocess.cpp @@ -49,20 +49,23 @@ check_output (string s, string& result, int64_t timeout) { // TODO: should be a config here tb_byte_t data[8192]; tb_size_t size= sizeof (data); - tb_bool_t wait= tb_false; + + int retry= 3; while (read < size) { tb_long_t real= tb_pipe_file_read (file[0], data + read, size - read); + cout << "real\t" << real << LF; if (real > 0) { read+= real; - wait= tb_false; } - else if (!real && !wait) { - // wait pipe - tb_long_t ok= tb_pipe_file_wait (file[0], TB_PIPE_EVENT_READ, timeout); - tb_check_break (ok > 0); - wait= tb_true; + tb_long_t ok= tb_pipe_file_wait (file[0], TB_PIPE_EVENT_READ, timeout); + if (ok == 0) { // timeout + retry= retry - 1; + cout << "retry: " << retry << LF; + if (retry == 0) break; + } + else if (ok == -1) { // failed + break; } - else break; } result= as_string ((tb_char_t*) data); diff --git a/lolly/system/subprocess.hpp b/lolly/system/subprocess.hpp index 88a36be67..cb1966241 100644 --- a/lolly/system/subprocess.hpp +++ b/lolly/system/subprocess.hpp @@ -16,6 +16,6 @@ namespace lolly { namespace system { int call (string cmd); -int check_output (string cmd, string& result, int64_t timeout= 100); +int check_output (string cmd, string& result, int64_t timeout= 30); } // namespace system } // namespace lolly From 1815506b4ce1a85ada9026ec1943070b8b1fcbc3 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Wed, 3 Jan 2024 19:39:45 +0800 Subject: [PATCH 4/5] wip --- lolly/system/subprocess.cpp | 27 +++++++++++++++----------- lolly/system/subprocess.hpp | 2 +- tests/lolly/system/subprocess_test.cpp | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lolly/system/subprocess.cpp b/lolly/system/subprocess.cpp index 8d8cade0e..d11152052 100644 --- a/lolly/system/subprocess.cpp +++ b/lolly/system/subprocess.cpp @@ -50,28 +50,33 @@ check_output (string s, string& result, int64_t timeout) { tb_byte_t data[8192]; tb_size_t size= sizeof (data); - int retry= 3; + tb_bool_t wait= tb_false; while (read < size) { tb_long_t real= tb_pipe_file_read (file[0], data + read, size - read); - cout << "real\t" << real << LF; if (real > 0) { read+= real; + wait= tb_false; } - tb_long_t ok= tb_pipe_file_wait (file[0], TB_PIPE_EVENT_READ, timeout); - if (ok == 0) { // timeout - retry= retry - 1; - cout << "retry: " << retry << LF; - if (retry == 0) break; - } - else if (ok == -1) { // failed - break; + else if (!real && !wait) { + tb_long_t ok = 0; + int retry= 10; + if (read > 0) { + retry= 3; + } + 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; } + else break; } 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); diff --git a/lolly/system/subprocess.hpp b/lolly/system/subprocess.hpp index cb1966241..77232eed4 100644 --- a/lolly/system/subprocess.hpp +++ b/lolly/system/subprocess.hpp @@ -16,6 +16,6 @@ namespace lolly { namespace system { int call (string cmd); -int check_output (string cmd, string& result, int64_t timeout= 30); +int check_output (string cmd, string& result, int64_t timeout= 50); } // namespace system } // namespace lolly diff --git a/tests/lolly/system/subprocess_test.cpp b/tests/lolly/system/subprocess_test.cpp index da3a84a9f..7b82da697 100644 --- a/tests/lolly/system/subprocess_test.cpp +++ b/tests/lolly/system/subprocess_test.cpp @@ -24,6 +24,7 @@ TEST_CASE ("check_output") { if (!os_wasm () && !os_mingw ()) { lolly::system::check_output ("xmake --version", result); CHECK (N (result) > 0); + cout << result << LF; } } From 6fbbfbb92af082a5dcd251f9ace72822ff0cac70 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Wed, 3 Jan 2024 19:48:34 +0800 Subject: [PATCH 5/5] wip --- lolly/system/subprocess.cpp | 5 ++--- lolly/system/subprocess.hpp | 2 +- tests/lolly/system/subprocess_test.cpp | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lolly/system/subprocess.cpp b/lolly/system/subprocess.cpp index d11152052..b07719250 100644 --- a/lolly/system/subprocess.cpp +++ b/lolly/system/subprocess.cpp @@ -49,7 +49,6 @@ check_output (string s, string& result, int64_t timeout) { // TODO: should be a config here tb_byte_t data[8192]; tb_size_t size= sizeof (data); - tb_bool_t wait= tb_false; while (read < size) { tb_long_t real= tb_pipe_file_read (file[0], data + read, size - read); @@ -59,9 +58,9 @@ check_output (string s, string& result, int64_t timeout) { } else if (!real && !wait) { tb_long_t ok = 0; - int retry= 10; + int retry= 25; if (read > 0) { - retry= 3; + retry= 2; } while (retry > 0 && (ok == 0)) { ok = tb_pipe_file_wait (file[0], TB_PIPE_EVENT_READ, timeout); diff --git a/lolly/system/subprocess.hpp b/lolly/system/subprocess.hpp index 77232eed4..0765fa3c2 100644 --- a/lolly/system/subprocess.hpp +++ b/lolly/system/subprocess.hpp @@ -16,6 +16,6 @@ namespace lolly { namespace system { int call (string cmd); -int check_output (string cmd, string& result, int64_t timeout= 50); +int check_output (string cmd, string& result, int64_t timeout= 20); } // namespace system } // namespace lolly diff --git a/tests/lolly/system/subprocess_test.cpp b/tests/lolly/system/subprocess_test.cpp index 7b82da697..da3a84a9f 100644 --- a/tests/lolly/system/subprocess_test.cpp +++ b/tests/lolly/system/subprocess_test.cpp @@ -24,7 +24,6 @@ TEST_CASE ("check_output") { if (!os_wasm () && !os_mingw ()) { lolly::system::check_output ("xmake --version", result); CHECK (N (result) > 0); - cout << result << LF; } }