void TLSSOCKET_SEND_TIMEOUT() { TLSSocket sock; if (tlssocket_connect_to_discard_srv(sock) != NSAPI_ERROR_OK) { TEST_FAIL(); return; } int err; Timer timer; static const char tx_buffer[] = {'h', 'e', 'l', 'l', 'o'}; for (int i = 0; i < 10; i++) { timer.reset(); timer.start(); err = sock.send(tx_buffer, sizeof(tx_buffer)); timer.stop(); if ((err == sizeof(tx_buffer)) && (timer.read_ms() <= 800)) { continue; } TEST_FAIL(); break; } TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close()); }
void TLSSOCKET_ECHOTEST_BURST() { TLSSocket *sock = new TLSSocket; tlssocket_connect_to_echo_srv(*sock); sock->sigio(callback(_sigio_handler, ThisThread::get_id())); // TX buffer to be preserved for comparison fill_tx_buffer_ascii(tls_global::tx_buffer, BURST_SIZE); int recvd; int bt_left; int sent; for (int i = 0; i < BURST_CNT; i++) { bt_left = BURST_SIZE; while (bt_left > 0) { sent = sock->send(&(tls_global::tx_buffer[BURST_SIZE - bt_left]), bt_left); if (sent == NSAPI_ERROR_WOULD_BLOCK) { if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) { TEST_FAIL(); goto END; } continue; } else if (sent < 0) { printf("[%02d] network error %d\n", i, sent); TEST_FAIL(); goto END; } bt_left -= sent; } bt_left = BURST_SIZE; while (bt_left > 0) { recvd = sock->recv(&(tls_global::rx_buffer[BURST_SIZE - bt_left]), BURST_SIZE); if (recvd < 0) { printf("[%02d] network error %d\n", i, recvd); break; } bt_left -= recvd; } if (bt_left != 0) { TEST_FAIL_MESSAGE("bt_left != 0"); goto END; } TEST_ASSERT_EQUAL(0, memcmp(tls_global::tx_buffer, tls_global::rx_buffer, BURST_SIZE)); } END: TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close()); delete sock; }
void TLSSOCKET_SEND_REPEAT() { SKIP_IF_TCP_UNSUPPORTED(); TLSSocket sock; tlssocket_connect_to_discard_srv(sock); int snd; Timer timer; static const char tx_buffer[] = {'h', 'e', 'l', 'l', 'o'}; for (int i = 0; i < 100; i++) { snd = sock.send(tx_buffer, sizeof(tx_buffer)); if (snd != sizeof(tx_buffer)) { TEST_FAIL(); break; } } TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close()); }