tstRTTcp-1.cpp revision e99cdffa1ee7d0d0451908d60a5d2faa124f14e9
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/* * * * * * * * Test 3 * * * * * * * */
{
char szBuf[4096];
/* say hello */
RTTESTI_CHECK_RC_RET(RTTcpWrite(hSocket, "hello\n", sizeof("hello\n") - 1), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
RTTESTI_CHECK_RC_RET(RTTcpRead(hSocket, szBuf, sizeof("dude!\n") - 1, NULL), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
/* Send ~20 MB of data that the client receives while trying to disconnect. */
{
RTTESTI_CHECK_RC_RET(RTTcpWrite(hSocket, szBuf, sizeof(szBuf)), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
}
return VERR_TCP_SERVER_STOP;
}
void test3()
{
{
int rc = RTTcpServerCreate("localhost", 9999, RTTHREADTYPE_DEFAULT, "server-2", test3Server, NULL, &pServer);
#ifdef RT_OS_SOLARIS
/** @todo testboxsh1 occationally hits this for some stupid reason. i=21 in
* one occurrence. Fudge a bit for now and see if it helps. */
if (rc == VERR_NET_ADDRESS_IN_USE)
{
RTThreadSleep(500);
rc = RTTcpServerCreate("localhost", 9999, RTTHREADTYPE_DEFAULT, "server-2", test3Server, NULL, &pServer);
}
#endif
if (rc != VINF_SUCCESS)
{
return;
}
if (RT_SUCCESS(rc))
{
char szBuf[512];
do /* break non-loop */
{
} while (0);
}
}
}
/* * * * * * * * Test 2 * * * * * * * */
{
char szBuf[512];
/* say hello */
RTTESTI_CHECK_RC_RET(RTTcpWrite(hSocket, "hello\n", sizeof("hello\n") - 1), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
RTTESTI_CHECK_RC_RET(RTTcpRead(hSocket, szBuf, sizeof("dude!\n") - 1, NULL), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
/* wait for a goodbye which doesn't arrive. */
RTTESTI_CHECK_RC_RET(RTTcpRead(hSocket, szBuf, sizeof("byebye\n") - 1, NULL), VERR_NET_SHUTDOWN, VERR_TCP_SERVER_STOP);
return VERR_TCP_SERVER_STOP;
}
void test2()
{
int rc;
if (RT_SUCCESS(rc))
{
char szBuf[512];
do /* break non-loop */
{
} while (0);
}
}
/* * * * * * * * Test 1 * * * * * * * */
{
char szBuf[512];
/* say hello */
RTTESTI_CHECK_RC_RET(RTTcpWrite(hSocket, "hello\n", sizeof("hello\n") - 1), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
RTTESTI_CHECK_RC_RET(RTTcpRead(hSocket, szBuf, sizeof("dude!\n") - 1, NULL), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
/* say goodbye */
RTTESTI_CHECK_RC_RET(RTTcpRead(hSocket, szBuf, sizeof("byebye\n") - 1, NULL), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
RTTESTI_CHECK_RC_RET(RTTcpWrite(hSocket, "bye\n", sizeof("bye\n") - 1), VINF_SUCCESS, VERR_TCP_SERVER_STOP);
return VERR_TCP_SERVER_STOP;
}
void test1()
{
int rc;
if (RT_SUCCESS(rc))
{
do /* break non-loop */
{
char szBuf[512];
} while (0);
}
}
int main()
{
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
test1();
test2();
test3();
/** @todo test the full RTTcp API. */
return RTTestSummaryAndDestroy(g_hTest);
}