@@ -61,7 +61,7 @@ static void _sigio_handler()
6161 signals.set (SIGNAL_SIGIO_RX | SIGNAL_SIGIO_TX);
6262}
6363
64- void UDPSOCKET_ECHOTEST ( )
64+ void UDPSOCKET_ECHOTEST_impl ( bool use_sendto )
6565{
6666 SocketAddress udp_addr;
6767 SocketAddress recv_addr;
@@ -71,6 +71,10 @@ void UDPSOCKET_ECHOTEST()
7171 UDPSocket sock;
7272 TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.open (NetworkInterface::get_default_instance ()));
7373
74+ if (!use_sendto) {
75+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.connect (udp_addr));
76+ }
77+
7478 sock.set_timeout (SOCKET_TIMEOUT);
7579 int recvd;
7680 int sent;
@@ -85,7 +89,11 @@ void UDPSOCKET_ECHOTEST()
8589
8690 for (int retry_cnt = 0 ; retry_cnt <= 2 ; retry_cnt++) {
8791 memset (rx_buffer, 0 , BUFF_SIZE);
88- sent = sock.sendto (udp_addr, tx_buffer, pkt_s);
92+ if (use_sendto) {
93+ sent = sock.sendto (udp_addr, tx_buffer, pkt_s);
94+ } else {
95+ sent = sock.send (tx_buffer, pkt_s);
96+ }
8997 if (check_oversized_packets (sent, pkt_s)) {
9098 TEST_IGNORE_MESSAGE (" This device does not handle oversized packets" );
9199 } else if (sent == pkt_s) {
@@ -97,7 +105,11 @@ void UDPSOCKET_ECHOTEST()
97105
98106 do {
99107 received_duplicate_packet = false ;
100- recvd = sock.recvfrom (&recv_addr, rx_buffer, pkt_s);
108+ if (use_sendto) {
109+ recvd = sock.recvfrom (&recv_addr, rx_buffer, pkt_s);
110+ } else {
111+ recvd = sock.recv (rx_buffer, pkt_s);
112+ }
101113 // Check if received duplicated packet
102114 for (unsigned int d_idx = 0 ; d_idx < PKTS; ++d_idx) {
103115 if (pkt_received[d_idx] && d_idx != s_idx && recvd == pkt_sizes[d_idx]) {
@@ -114,9 +126,12 @@ void UDPSOCKET_ECHOTEST()
114126 tr_error (" [Round#%02d - Receiver] error, returned %d" , s_idx, recvd);
115127 }
116128 }
117- // Verify received address is correct
118- TEST_ASSERT (udp_addr == recv_addr);
119- TEST_ASSERT_EQUAL (udp_addr.get_port (), recv_addr.get_port ());
129+
130+ if (use_sendto) {
131+ // Verify received address is correct
132+ TEST_ASSERT (udp_addr == recv_addr);
133+ TEST_ASSERT_EQUAL (udp_addr.get_port (), recv_addr.get_port ());
134+ }
120135
121136 if (memcmp (tx_buffer, rx_buffer, pkt_s) == 0 ) {
122137 packets_recv++;
@@ -135,7 +150,18 @@ void UDPSOCKET_ECHOTEST()
135150 TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.close ());
136151}
137152
138- void UDPSOCKET_ECHOTEST_NONBLOCK ()
153+ void UDPSOCKET_ECHOTEST ()
154+ {
155+ UDPSOCKET_ECHOTEST_impl (true );
156+ }
157+
158+ void UDPSOCKET_ECHOTEST_CONNECT_SEND_RECV ()
159+ {
160+ UDPSOCKET_ECHOTEST_impl (false );
161+ }
162+
163+
164+ void UDPSOCKET_ECHOTEST_NONBLOCK_impl (bool use_sendto)
139165{
140166 tc_exec_time.start ();
141167 time_allotted = split2half_rmng_udp_test_time (); // [s]
@@ -149,6 +175,11 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
149175 return ;
150176 }
151177 TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock->open (NetworkInterface::get_default_instance ()));
178+
179+ if (!use_sendto) {
180+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock->connect (udp_addr));
181+ }
182+
152183 sock->set_blocking (false );
153184 sock->sigio (callback (_sigio_handler));
154185 int sent;
@@ -160,7 +191,12 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
160191 for (int retry_cnt = 0 ; retry_cnt <= RETRIES; retry_cnt++) {
161192 fill_tx_buffer_ascii (tx_buffer, pkt_s);
162193
163- sent = sock->sendto (udp_addr, tx_buffer, pkt_s);
194+ if (use_sendto) {
195+ sent = sock->sendto (udp_addr, tx_buffer, pkt_s);
196+ } else {
197+ sent = sock->send (tx_buffer, pkt_s);
198+ }
199+
164200 if (sent == pkt_s) {
165201 packets_sent++;
166202 } else if (sent == NSAPI_ERROR_WOULD_BLOCK) {
@@ -176,7 +212,13 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
176212
177213 int recvd;
178214 for (int retry_recv = 0 ; retry_recv <= RETRIES; retry_recv++) {
179- recvd = sock->recvfrom (NULL , rx_buffer, pkt_s);
215+
216+ if (use_sendto) {
217+ recvd = sock->recvfrom (NULL , rx_buffer, pkt_s);
218+ } else {
219+ recvd = sock->recv (rx_buffer, pkt_s);
220+ }
221+
180222 if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
181223 if (tc_exec_time.read () >= time_allotted) {
182224 break ;
@@ -230,3 +272,13 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
230272 delete sock;
231273 tc_exec_time.stop ();
232274}
275+
276+ void UDPSOCKET_ECHOTEST_NONBLOCK ()
277+ {
278+ UDPSOCKET_ECHOTEST_NONBLOCK_impl (true );
279+ }
280+
281+ void UDPSOCKET_ECHOTEST_NONBLOCK_CONNECT_SEND_RECV ()
282+ {
283+ UDPSOCKET_ECHOTEST_NONBLOCK_impl (false );
284+ }
0 commit comments