void TCPSOCKET_RECV_100K_NONBLOCK() { TCPSocket sock; _tcpsocket_connect_to_chargen_srv(sock); sock.set_blocking(false); sock.sigio(callback(_sigio_handler, Thread::gettid())); Timer timer; timer.start(); rcv_n_chk_against_rfc864_pattern_nonblock(sock); timer.stop(); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close()); printf("MBED: Time taken: %fs\n", timer.read()); }
void TCPSOCKET_RECV_100K_NONBLOCK() { TCPSocket sock; nsapi_error_t err = _tcpsocket_connect_to_chargen_srv(sock); if (err != NSAPI_ERROR_OK) { TEST_FAIL(); return; } sock.set_blocking(false); sock.sigio(callback(_sigio_handler, Thread::gettid())); rcv_n_chk_against_rfc864_pattern_nonblock(sock); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close()); }
/** * Test TCP data exchange via the asynchronous sigio() mechanism */ void test_tcp_echo_async() { TCPSocket sock; SocketAddress host_address; bool callback_triggered = false; int x; int size; driver.disconnect(); TEST_ASSERT(do_connect(&driver) == 0); TEST_ASSERT( driver.gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); host_address.set_port(MBED_CONF_APP_ECHO_TCP_PORT); tr_debug("TCP: Server %s address: %s on port %d.", MBED_CONF_APP_ECHO_SERVER, host_address.get_ip_address(), host_address.get_port()); TEST_ASSERT(sock.open(&driver) == 0) // Set up the async callback and set the timeout to zero sock.sigio(callback(async_cb, &callback_triggered)); sock.set_timeout(0); TEST_ASSERT(sock.connect(host_address) == 0); // Test min, max, and some random sizes in-between do_tcp_echo_async(&sock, 1, &callback_triggered); do_tcp_echo_async(&sock, MBED_CONF_APP_TCP_MAX_PACKET_SIZE, &callback_triggered); sock.close(); drop_connection(&driver); tr_debug("TCP packets of size up to %d byte(s) echoed asynchronously and successfully.", MBED_CONF_APP_TCP_MAX_PACKET_SIZE); }