@@ -61,7 +61,7 @@ static void _sigio_handler()
61
61
signals.set (SIGNAL_SIGIO_RX | SIGNAL_SIGIO_TX);
62
62
}
63
63
64
- void UDPSOCKET_ECHOTEST ( )
64
+ void UDPSOCKET_ECHOTEST_impl ( bool use_sendto )
65
65
{
66
66
SocketAddress udp_addr;
67
67
SocketAddress recv_addr;
@@ -71,6 +71,10 @@ void UDPSOCKET_ECHOTEST()
71
71
UDPSocket sock;
72
72
TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.open (NetworkInterface::get_default_instance ()));
73
73
74
+ if (!use_sendto) {
75
+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.connect (udp_addr));
76
+ }
77
+
74
78
sock.set_timeout (SOCKET_TIMEOUT);
75
79
int recvd;
76
80
int sent;
@@ -85,7 +89,11 @@ void UDPSOCKET_ECHOTEST()
85
89
86
90
for (int retry_cnt = 0 ; retry_cnt <= 2 ; retry_cnt++) {
87
91
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
+ }
89
97
if (check_oversized_packets (sent, pkt_s)) {
90
98
TEST_IGNORE_MESSAGE (" This device does not handle oversized packets" );
91
99
} else if (sent == pkt_s) {
@@ -97,7 +105,11 @@ void UDPSOCKET_ECHOTEST()
97
105
98
106
do {
99
107
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
+ }
101
113
// Check if received duplicated packet
102
114
for (unsigned int d_idx = 0 ; d_idx < PKTS; ++d_idx) {
103
115
if (pkt_received[d_idx] && d_idx != s_idx && recvd == pkt_sizes[d_idx]) {
@@ -114,9 +126,12 @@ void UDPSOCKET_ECHOTEST()
114
126
tr_error (" [Round#%02d - Receiver] error, returned %d" , s_idx, recvd);
115
127
}
116
128
}
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
+ }
120
135
121
136
if (memcmp (tx_buffer, rx_buffer, pkt_s) == 0 ) {
122
137
packets_recv++;
@@ -135,7 +150,18 @@ void UDPSOCKET_ECHOTEST()
135
150
TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.close ());
136
151
}
137
152
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)
139
165
{
140
166
tc_exec_time.start ();
141
167
time_allotted = split2half_rmng_udp_test_time (); // [s]
@@ -149,6 +175,11 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
149
175
return ;
150
176
}
151
177
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
+
152
183
sock->set_blocking (false );
153
184
sock->sigio (callback (_sigio_handler));
154
185
int sent;
@@ -160,7 +191,12 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
160
191
for (int retry_cnt = 0 ; retry_cnt <= RETRIES; retry_cnt++) {
161
192
fill_tx_buffer_ascii (tx_buffer, pkt_s);
162
193
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
+
164
200
if (sent == pkt_s) {
165
201
packets_sent++;
166
202
} else if (sent == NSAPI_ERROR_WOULD_BLOCK) {
@@ -176,7 +212,13 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
176
212
177
213
int recvd;
178
214
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
+
180
222
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
181
223
if (tc_exec_time.read () >= time_allotted) {
182
224
break ;
@@ -230,3 +272,13 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
230
272
delete sock;
231
273
tc_exec_time.stop ();
232
274
}
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