File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 2323 */
2424// ----------------------------------------------------------------------
2525
26+ #include < chrono>
27+ #include < sstream>
2628#include < iostream>
2729#include < thread>
2830
@@ -40,13 +42,25 @@ int main(int argc, char* argv[])
4042 }
4143 urcl::control::ScriptSender sender (PORT, " textmsg(\" Hello, World!\" )" );
4244
43- std::cout << " Waiting for incoming requests on port " << PORT << " ..." << std::endl;
45+ std::stringstream ss;
46+ ss << " Waiting for incoming requests on port " << PORT;
47+ if (second_to_run > 0 )
48+ {
49+ ss << " for " << second_to_run << " seconds" ;
50+ }
51+ else
52+ {
53+ ss << " indefinitely" ;
54+ }
55+
56+ std::cout << ss.str () << std::endl;
4457
45- unsigned long startTime = clock ();
46- while (second_to_run < 0 || (( clock ( ) - startTime) / CLOCKS_PER_SEC) < static_cast < unsigned int > (second_to_run))
58+ const auto start_time = std::chrono::system_clock::now ();
59+ while (second_to_run < 0 || std::chrono::system_clock::now ( ) - start_time < std::chrono::seconds (second_to_run))
4760 {
48- std::this_thread::sleep_for (std::chrono::seconds ( 1 ));
61+ std::this_thread::sleep_for (std::chrono::milliseconds ( 500 ));
4962 }
63+ std::cout << " Timeout reached" << std::endl;
5064
5165 return 0 ;
5266}
You can’t perform that action at this time.
0 commit comments