Changeset 32810 in vbox for trunk/src/VBox/Runtime/testcase
- Timestamp:
- Sep 29, 2010 10:56:54 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTTcp-1.cpp
r32801 r32810 10 10 static RTTEST g_hTest; 11 11 12 13 /* * * * * * * * Test 3 * * * * * * * */ 14 15 static 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 40 void 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 * * * * * * * */ 12 74 13 75 static DECLCALLBACK(int) test2Server(RTSOCKET hSocket, void *pvUser) … … 59 121 } 60 122 123 124 /* * * * * * * * Test 1 * * * * * * * */ 61 125 62 126 static DECLCALLBACK(int) test1Server(RTSOCKET hSocket, void *pvUser) … … 126 190 test1(); 127 191 test2(); 192 test3(); 128 193 129 194 /** @todo test the full RTTcp API. */
Note:
See TracChangeset
for help on using the changeset viewer.