diff options
author | Geliang Tang <tanggeliang@kylinos.cn> | 2024-04-19 15:46:15 +0800 |
---|---|---|
committer | Geliang Tang <tanggeliang@kylinos.cn> | 2024-04-22 10:56:56 +0800 |
commit | 496972b8eab5063c7e9182a17f4ec27b45964efd (patch) | |
tree | faaafd02695a443b2d85ac658ba2f81bfa3646e5 | |
parent | d66529e879aa72c0727d514a7d04bbcfcb59128d (diff) | |
download | mptcp_net-next-496972b8eab5063c7e9182a17f4ec27b45964efd.tar.gz |
Revert "selftests/bpf: Add select for send_recv_data"
This reverts commit 46d87af537f0d7cb26b9f113cec9fe7d9255f648.
-rw-r--r-- | tools/testing/selftests/bpf/network_helpers.c | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 2664134275db9d..e0213ce7a0e146 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -580,12 +580,10 @@ struct send_recv_arg { static void *send_recv_server(void *arg) { struct send_recv_arg *a = (struct send_recv_arg *)arg; - struct timeval timeout = { .tv_sec = 3 }; + int flags = fcntl(a->fd, F_GETFL); ssize_t nr_sent = 0, bytes = 0; char batch[1500]; int err = 0, fd; - fd_set wset; - int max_fd; fd = accept(a->fd, NULL, NULL); while (fd == -1) { @@ -601,22 +599,13 @@ static void *send_recv_server(void *arg) } while (bytes < a->bytes && !READ_ONCE(a->stop)) { - /* FD sets */ - FD_ZERO(&wset); - FD_SET(fd, &wset); - max_fd = fd; - - if (select(max_fd + 1, NULL, &wset, NULL, &timeout) == -1) { - log_err("Failed to select"); - err = -1; - break; - } - nr_sent = send(fd, &batch, MIN(a->bytes - bytes, sizeof(batch)), 0); if (nr_sent == -1 && errno == EINTR) continue; if (nr_sent == -1) { + if (flags & O_NONBLOCK && errno == EWOULDBLOCK) + continue; err = -errno; break; } @@ -641,7 +630,7 @@ done: int send_recv_data(int lfd, int fd, uint32_t total_bytes) { - struct timeval timeout = { .tv_sec = 3 }; + int flags = fcntl(lfd, F_GETFL); ssize_t nr_recv = 0, bytes = 0; struct send_recv_arg arg = { .fd = lfd, @@ -651,9 +640,7 @@ int send_recv_data(int lfd, int fd, uint32_t total_bytes) pthread_t srv_thread; void *thread_ret; char batch[1500]; - int max_fd = fd; int err = 0; - fd_set rset; err = pthread_create(&srv_thread, NULL, send_recv_server, (void *)&arg); if (err) { @@ -663,21 +650,13 @@ int send_recv_data(int lfd, int fd, uint32_t total_bytes) /* recv total_bytes */ while (bytes < total_bytes && !READ_ONCE(arg.stop)) { - /* FD sets */ - FD_ZERO(&rset); - FD_SET(fd, &rset); - - if (select(max_fd + 1, &rset, NULL, NULL, &timeout) == -1) { - log_err("Failed to select"); - err = -1; - break; - } - nr_recv = recv(fd, &batch, MIN(total_bytes - bytes, sizeof(batch)), 0); if (nr_recv == -1 && errno == EINTR) continue; if (nr_recv == -1) { + if (flags & O_NONBLOCK && errno == EWOULDBLOCK) + continue; err = -errno; break; } |