@@ -102,29 +102,31 @@ void TLSSOCKET_ECHOTEST()
102102
103103void tlssocket_echotest_nonblock_receive ()
104104{
105- int recvd = sock->recv (&(tls_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
106- if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
107- if (tc_exec_time.read () >= time_allotted) {
105+ while (bytes2recv > 0 ) {
106+ int recvd = sock->recv (&(tls_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
107+ if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
108+ if (tc_exec_time.read () >= time_allotted) {
109+ TEST_FAIL_MESSAGE (" time_allotted exceeded" );
110+ receive_error = true ;
111+ }
112+ return ;
113+ } else if (recvd < 0 ) {
114+ printf (" sock.recv returned an error %d" , recvd);
115+ TEST_FAIL ();
108116 receive_error = true ;
117+ } else {
118+ bytes2recv -= recvd;
109119 }
110- return ;
111- } else if (recvd < 0 ) {
112- receive_error = true ;
113- } else {
114- bytes2recv -= recvd;
115- }
116120
117- if (bytes2recv == 0 ) {
118- TEST_ASSERT_EQUAL (0 , memcmp (tls_global::tx_buffer, tls_global::rx_buffer, bytes2recv_total));
119-
120- static int round = 0 ;
121- printf (" [Recevr#%02d] bytes received: %d\n " , round++, bytes2recv_total);
122- tx_sem.release ();
123- } else if (receive_error || bytes2recv < 0 ) {
124- TEST_FAIL ();
125- tx_sem.release ();
121+ if (bytes2recv == 0 ) {
122+ TEST_ASSERT_EQUAL (0 , memcmp (tls_global::tx_buffer, tls_global::rx_buffer, bytes2recv_total));
123+ tx_sem.release ();
124+ } else if (receive_error || bytes2recv < 0 ) {
125+ TEST_FAIL ();
126+ tx_sem.release ();
127+ }
128+ // else - no error, not all bytes were received yet.
126129 }
127- // else - no error, not all bytes were received yet.
128130}
129131
130132void TLSSOCKET_ECHOTEST_NONBLOCK ()
@@ -177,13 +179,11 @@ void TLSSOCKET_ECHOTEST_NONBLOCK()
177179 continue ;
178180 } else if (sent <= 0 ) {
179181 printf (" [Sender#%02d] network error %d\n " , s_idx, sent);
180-
181182 TEST_FAIL ();
182183 goto END;
183184 }
184185 bytes2send -= sent;
185186 }
186- printf (" [Sender#%02d] bytes sent: %d\n " , s_idx, pkt_s);
187187#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
188188 count = fetch_stats ();
189189 for (j = 0 ; j < count; j++) {
0 commit comments