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

View File

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