提交 3046b5a6 编写于 作者: M mlinlmcc 提交者: Gitee

适配不同芯片:不同平台recv实现不同,可能存在单次recv数据不完全的情况

上级 9d5ad488
...@@ -139,9 +139,18 @@ static void SampleTcpServerTask(void) ...@@ -139,9 +139,18 @@ static void SampleTcpServerTask(void)
waitServer(); waitServer();
memset_s(buf, BUF_SIZE, 0, BUF_SIZE); memset_s(buf, BUF_SIZE, 0, BUF_SIZE);
ret = recv(sfd, buf, sizeof(buf), 0); int recvSum = 0;
printf("[tcp server]recv, ret=%d\n", ret); int recvTimes = 50;
TEST_ASSERT_EQUAL_INT(ret, len * strlen(CLI_MSG)); while (recvTimes > 0) {
ret = recv(clientFd, buf, sizeof(buf), 0);
recvSum += ret;
if (recvSum == (len * strlen(SRV_MSG)) || ret <= 0) {
break;
}
recvTimes--;
}
printf("[tcp server]recv, recvSum=%d,recvTimes=%d\n", recvSum, recvTimes);
TEST_ASSERT_EQUAL_INT(len * strlen(CLI_MSG), recvSum);
ret = shutdown(sfd, SHUT_RDWR); ret = shutdown(sfd, SHUT_RDWR);
printf("[tcp server]shutdown, ret=%d\n", ret); printf("[tcp server]shutdown, ret=%d\n", ret);
...@@ -226,9 +235,18 @@ static void SampleTcpClientTask(void) ...@@ -226,9 +235,18 @@ static void SampleTcpClientTask(void)
waitClient(); waitClient();
memset_s(buf, BUF_SIZE, 0, BUF_SIZE); memset_s(buf, BUF_SIZE, 0, BUF_SIZE);
ret = recv(sfd, buf, sizeof(buf), 0); int recvSum = 0;
printf("[tcp client]recv, ret=%d\n", ret); int recvTimes = 50;
TEST_ASSERT_EQUAL_INT(ret, len * strlen(SRV_MSG)); while (recvTimes > 0) {
ret = recv(clientFd, buf, sizeof(buf), 0);
recvSum += ret;
if (recvSum == (len * strlen(SRV_MSG)) || ret <= 0) {
break;
}
recvTimes--;
}
printf("[tcp client]recv, recvSum=%d,recvTimes=%d\n", recvSum, recvTimes);
TEST_ASSERT_EQUAL_INT(len * strlen(SRV_MSG), recvSum);
ret = shutdown(sfd, SHUT_RDWR); ret = shutdown(sfd, SHUT_RDWR);
printf("[tcp client]shutdown, ret=%d\n", ret); printf("[tcp client]shutdown, ret=%d\n", ret);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册