2323#include " utest.h"
2424#include " udp_tests.h"
2525
26+ using namespace std ::chrono;
2627using namespace utest ::v1;
2728
2829namespace {
2930static const int SIGNAL_SIGIO_RX = 0x1 ;
3031static const int SIGNAL_SIGIO_TX = 0x2 ;
31- static const int SIGIO_TIMEOUT = 5000 ; // [ms]
32- static const int SOCKET_TIMEOUT = ( 10 * 1000 ); // [ms]
32+ static constexpr seconds SIGIO_TIMEOUT = 5s;
33+ static constexpr seconds SOCKET_TIMEOUT = 10s;
3334static const int RETRIES = 2 ;
3435
3536static const double EXPECTED_LOSS_RATIO = 0.0 ;
@@ -53,7 +54,7 @@ static bool pkt_received[PKTS] = {false, false, false, false, false, false, fals
5354 };
5455
5556Timer tc_exec_time;
56- int time_allotted;
57+ microseconds time_allotted;
5758}
5859
5960static void _sigio_handler ()
@@ -75,7 +76,7 @@ void UDPSOCKET_ECHOTEST_impl(bool use_sendto)
7576 TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.connect (udp_addr));
7677 }
7778
78- sock.set_timeout (SOCKET_TIMEOUT);
79+ sock.set_timeout (milliseconds ( SOCKET_TIMEOUT). count () );
7980 int recvd;
8081 int sent;
8182 int packets_sent = 0 ;
@@ -169,7 +170,7 @@ void UDPSOCKET_ECHOTEST_CONNECT_SEND_RECV()
169170void UDPSOCKET_ECHOTEST_NONBLOCK_impl (bool use_sendto)
170171{
171172 tc_exec_time.start ();
172- time_allotted = split2half_rmng_udp_test_time (); // [s]
173+ time_allotted = split2half_rmng_udp_test_time ();
173174
174175 SocketAddress udp_addr;
175176 NetworkInterface::get_default_instance ()->gethostbyname (ECHO_SERVER_ADDR, &udp_addr);
@@ -211,8 +212,12 @@ void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto)
211212 } else if (sent == pkt_s) {
212213 packets_sent++;
213214 } else if (sent == NSAPI_ERROR_WOULD_BLOCK) {
214- if (tc_exec_time.read () >= time_allotted ||
215- signals.wait_all (SIGNAL_SIGIO_TX, SIGIO_TIMEOUT) == osFlagsErrorTimeout) {
215+ if (
216+ (tc_exec_time.elapsed_time () >= time_allotted)
217+ || signals.wait_all (
218+ SIGNAL_SIGIO_TX, milliseconds (SIGIO_TIMEOUT).count ()
219+ ) == osFlagsErrorTimeout
220+ ) {
216221 continue ;
217222 }
218223 --retry_cnt;
@@ -230,10 +235,13 @@ void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto)
230235 }
231236
232237 if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
233- if (tc_exec_time.read () >= time_allotted) {
238+ if (tc_exec_time.elapsed_time () >= time_allotted) {
234239 break ;
235240 }
236- signals.wait_all (SIGNAL_SIGIO_RX, SIGIO_TIMEOUT);
241+ signals.wait_all (
242+ SIGNAL_SIGIO_RX,
243+ milliseconds (SIGIO_TIMEOUT).count ()
244+ );
237245 --retry_recv;
238246 continue ;
239247 } else if (recvd < 0 ) {
0 commit comments