static DECLCALLBACK(int) test1Server(RTSOCKET hSocket, void *pvUser) { RTTestSetDefault(g_hTest, NULL); char szBuf[512]; RTTESTI_CHECK_RET(pvUser == NULL, VERR_UDP_SERVER_STOP); RTNETADDR ClientAddress; /* wait for exclamation! */ size_t cbReallyRead; RTTESTI_CHECK_RC_RET(RTSocketReadFrom(hSocket, szBuf, sizeof("dude!\n") - 1, &cbReallyRead, &ClientAddress), VINF_SUCCESS, VERR_UDP_SERVER_STOP); szBuf[sizeof("dude!\n") - 1] = '\0'; RTTESTI_CHECK_RET(cbReallyRead == sizeof("dude!\n") - 1, VERR_UDP_SERVER_STOP); RTTESTI_CHECK_RET(strcmp(szBuf, "dude!\n") == 0, VERR_UDP_SERVER_STOP); /* say hello. */ RTTESTI_CHECK_RC_RET(RTSocketWriteTo(hSocket, "hello\n", sizeof("hello\n") - 1, &ClientAddress), VINF_SUCCESS, VERR_UDP_SERVER_STOP); /* wait for goodbye. */ RTTESTI_CHECK_RC_RET(RTSocketReadFrom(hSocket, szBuf, sizeof("byebye\n") - 1, &cbReallyRead, &ClientAddress), VINF_SUCCESS, VERR_UDP_SERVER_STOP); RTTESTI_CHECK_RET(cbReallyRead == sizeof("byebye\n") - 1, VERR_UDP_SERVER_STOP); szBuf[sizeof("byebye\n") - 1] = '\0'; RTTESTI_CHECK_RET(strcmp(szBuf, "byebye\n") == 0, VERR_UDP_SERVER_STOP); /* say buhbye */ RTTESTI_CHECK_RC_RET(RTSocketWriteTo(hSocket, "buh bye\n", sizeof("buh bye\n") - 1, &ClientAddress), VINF_SUCCESS, VERR_UDP_SERVER_STOP); return VINF_SUCCESS; }
/** Thread function for tst4. */ static DECLCALLBACK(int) tst4Thread(RTTHREAD hSelf, void *pvArg) { // uint32_t iThread = (uint32_t)(uintptr_t)pvArg; RTMEMPOOL hMemPool = g_hMemPool4; /* setup. */ RTTestSetDefault(g_hTest, NULL); /* wait for the kick-off */ RTThreadUserWait(hSelf, RT_INDEFINITE_WAIT); /* do the work. */ for (uint32_t i = 0; i < 1024; i++) { void *apvHistory[256]; RT_ZERO(apvHistory); uint32_t j; for (j = 0; j < RT_ELEMENTS(apvHistory) - (i % 200); j++) RTTESTI_CHECK_RET(apvHistory[j] = RTMemPoolAlloc(hMemPool, (i & 15) + (j & 63)), VERR_NO_MEMORY); for (uint32_t k = i & 7; k < j; k += 3) { RTTESTI_CHECK_RET(RTMemPoolRelease(hMemPool, apvHistory[k]) == 0, VERR_INTERNAL_ERROR); apvHistory[k] = NULL; } while (j-- > 0) RTTESTI_CHECK_RET(RTMemPoolRelease(hMemPool, apvHistory[j]) == 0, VERR_INTERNAL_ERROR); } return VINF_SUCCESS; }