VirtualBox

Changeset 32810 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Sep 29, 2010 10:56:54 AM (14 years ago)
Author:
vboxsync
Message:

tcp.cpp: Outlined fix rtTcpClose fix for 3.2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTTcp-1.cpp

    r32801 r32810  
    1010static RTTEST g_hTest;
    1111
     12
     13/* * * * * * * *   Test 3    * * * * * * * */
     14
     15static DECLCALLBACK(int) test3Server(RTSOCKET hSocket, void *pvUser)
     16{
     17    RTTestSetDefault(g_hTest, NULL);
     18    char szBuf[4096];
     19
     20    /* say hello */
     21    RTTESTI_CHECK_RC_RET(RTTcpWrite(hSocket, "hello\n", sizeof("hello\n") - 1), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
     22    RT_ZERO(szBuf);
     23    RTTESTI_CHECK_RC_RET(RTTcpRead(hSocket, szBuf, sizeof("dude!\n") - 1, NULL), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
     24    szBuf[sizeof("dude!\n") - 1] = '\0';
     25    RTTESTI_CHECK_RET(strcmp(szBuf, "dude!\n") == 0, VERR_TCP_SERVER_STOP);
     26
     27    /* Send ~20 MB of data that the client receives while trying to disconnect. */
     28    RT_ZERO(szBuf);
     29    size_t cbSent = 0;
     30    while (cbSent < 20 * _1M)
     31    {
     32        RTTESTI_CHECK_RC_RET(RTTcpWrite(hSocket, szBuf, sizeof(szBuf)), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
     33        cbSent += sizeof(szBuf);
     34    }
     35
     36    return VERR_TCP_SERVER_STOP;
     37}
     38
     39
     40void test3()
     41{
     42    RTTestSub(g_hTest, "Graceful disconnect");
     43
     44    uint32_t cStartErrors = RTTestErrorCount(g_hTest);
     45    for (unsigned i = 0; i < 100 && cStartErrors == RTTestErrorCount(g_hTest); i++)
     46    {
     47        PRTTCPSERVER pServer;
     48        RTTESTI_CHECK_RC_RETV(RTTcpServerCreate("localhost", 9999, RTTHREADTYPE_DEFAULT, "server-2",
     49                                                test3Server, NULL, &pServer), VINF_SUCCESS);
     50
     51        int rc;
     52        RTSOCKET hSocket;
     53        RTTESTI_CHECK_RC(rc = RTTcpClientConnect("localhost", 9999, &hSocket), VINF_SUCCESS);
     54        if (RT_SUCCESS(rc))
     55        {
     56            char szBuf[512];
     57            RT_ZERO(szBuf);
     58            do /* break non-loop */
     59            {
     60                RTTESTI_CHECK_RC_BREAK(RTTcpRead(hSocket, szBuf, sizeof("hello\n") - 1, NULL), VINF_SUCCESS);
     61                RTTESTI_CHECK_BREAK(strcmp(szBuf, "hello\n") == 0);
     62                RTTESTI_CHECK_RC_BREAK(RTTcpWrite(hSocket, "dude!\n", sizeof("dude!\n") - 1), VINF_SUCCESS);
     63            } while (0);
     64
     65            RTTESTI_CHECK_RC(RTTcpClientClose(hSocket), VINF_SUCCESS);
     66        }
     67
     68        RTTESTI_CHECK_RC(RTTcpServerDestroy(pServer), VINF_SUCCESS);
     69    }
     70}
     71
     72
     73/* * * * * * * *   Test 2    * * * * * * * */
    1274
    1375static DECLCALLBACK(int) test2Server(RTSOCKET hSocket, void *pvUser)
     
    59121}
    60122
     123
     124/* * * * * * * *   Test 1    * * * * * * * */
    61125
    62126static DECLCALLBACK(int) test1Server(RTSOCKET hSocket, void *pvUser)
     
    126190    test1();
    127191    test2();
     192    test3();
    128193
    129194    /** @todo test the full RTTcp API. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette