예제 #1
0
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());
}
예제 #2
0
파일: main.cpp 프로젝트: 0xc0170/mbed
void drop_bad_packets(TLSSocket &sock, int orig_timeout)
{
    nsapi_error_t err;
    sock.set_timeout(0);
    while (true) {
        err = sock.recv(NULL, 0);
        if (err == NSAPI_ERROR_WOULD_BLOCK) {
            break;
        }
    }
    sock.set_timeout(orig_timeout);
}
예제 #3
0
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;
}
예제 #4
0
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());
}
예제 #5
0
void TLSSOCKET_CONNECT_INVALID()
{
    TLSSocket sock;
    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));

    TEST_ASSERT(sock.connect(NULL, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS) < 0);
    TEST_ASSERT(sock.connect("", MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS) < 0);
    TEST_ASSERT(sock.connect("", 0) < 0);

    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK,
                      sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS));

    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}