Fix random failures in send_buf_full

This commit is contained in:
Ruihan Li
2024-02-23 12:39:13 +08:00
committed by Tate, Hongliang Tian
parent 83b88229a3
commit e4954827dc
2 changed files with 10 additions and 8 deletions

View File

@ -105,14 +105,9 @@ static ssize_t receive_all(int sockfd)
size_t recv_len = 0; size_t recv_len = 0;
ssize_t ret; ssize_t ret;
if (mark_filde_nonblock(sockfd) < 0) {
perror("receive_all: mark_filde_nonblock");
return -1;
}
for (;;) { for (;;) {
ret = recv(sockfd, buffer, sizeof(buffer), 0); ret = recv(sockfd, buffer, sizeof(buffer), 0);
if (ret < 0 && errno == EAGAIN) if (ret == 0)
break; break;
if (ret < 0) { if (ret < 0) {
@ -197,6 +192,9 @@ int test_full_send_buffer(struct sockaddr_in *addr)
if (pid == 0) { if (pid == 0) {
ssize_t recv_len; ssize_t recv_len;
close(sendfd);
sendfd = -1;
// Ensure that the parent executes send() first, then the child // Ensure that the parent executes send() first, then the child
// executes recv(). // executes recv().
sleep(1); sleep(1);
@ -230,6 +228,9 @@ int test_full_send_buffer(struct sockaddr_in *addr)
sent_len += 1; sent_len += 1;
fprintf(stderr, "Sent bytes: %lu\n", sent_len); fprintf(stderr, "Sent bytes: %lu\n", sent_len);
close(sendfd);
sendfd = -1;
ret = 0; ret = 0;
wait: wait:
@ -250,6 +251,7 @@ out:
close(recvfd); close(recvfd);
out_send: out_send:
if (sendfd >= 0)
close(sendfd); close(sendfd);
out_listen: out_listen:

View File

@ -18,7 +18,7 @@ echo "Start network test......"
./socketpair ./socketpair
./sockoption ./sockoption
./listen_backlog ./listen_backlog
# ./send_buf_full ./send_buf_full
./http_server & ./http_server &
./http_client ./http_client
./tcp_err ./tcp_err