From f1f32d71512db2019869b3fbe4ce1f1e33a5f8e2 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Thu, 4 Apr 2024 20:46:34 +0800 Subject: [PATCH] set_nonblock Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 3b8435a347d5..a6dda8a8ae69 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -101,6 +101,16 @@ static void cleanup_netns(struct nstoken *nstoken) SYS_NOFAIL("ip netns del %s", NS_TEST); } +static int set_nonblock(int fd) +{ + int flags = fcntl(fd, F_GETFL); + + if (flags == -1) + return -1; + + return fcntl(fd, F_SETFL, flags | O_NONBLOCK); +} + static int verify_tsk(int map_fd, int client_fd) { int err, cfd = client_fd; @@ -332,6 +342,9 @@ static void run_mptcp_subflow(int cgroup_fd, struct mptcp_subflow *skel) if (!ASSERT_GE(client_fd, 0, "connect to fd")) goto close_server; + if (set_nonblock(server_fd)) + goto close_server; + send_recv_data(server_fd, client_fd, total_bytes, TIMEOUT_TEST); ASSERT_OK(ss_search(ADDR_1, "fwmark:0x1"), "ss_search fwmark:0x1"); @@ -418,6 +431,9 @@ static void send_data_and_verify(char *msg, int addr1, int addr2) if (!ASSERT_NEQ(client_fd, -1, "connect_to_fd")) goto close_server; + if (set_nonblock(server_fd)) + goto close_server; + if (clock_gettime(CLOCK_MONOTONIC, &start) < 0) goto close_server;