From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id 76BB680C53; Fri, 2 Sep 2022 07:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102944; bh=5P/4HVhR5lyT4eld4B/ez4Z99vPsEFIBhMu+N4A6WQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZUarb+Xn9+029YXh0MB9nm9sj63zL5VqRR9RJhJNU2YNv4YLm8alsqciIc5v3zkdE rIuW1jf3ZghTYxJNjlB/uXkPz1Q3rxWmnglc8PKq6MSoPFs9IeKB7x97psH+zykk6x /0/WnBCURtLI0EWw/sSDKbB0MogHJbQeBQNJsiAWYW9xtqv8df1H5WLZFLsx4ZdyUI 6F9IiweilGM+DstxKdu92jjHkS42Zbj+f3IhXDTaaQSDgOgDdE24onG/KeqaLaYu3N +ykiQYYX0/Ji4ziJBxx0Bcaq/uI1BKNNLsxLcTmEK+zw/8+/O6/ztDKW83JZhCjtj8 gIICeOv5Oz0VQ== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 04/12] t/socket-rw-eagain: Don't brute force the port number Date: Fri, 2 Sep 2022 14:14:57 +0700 Message-Id: <20220902071153.3168814-5-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Ammar Faizi Don't brute force the port number, use `t_bind_ephemeral_port()`, much simpler and reliable for choosing a port number that is not in use. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/socket-rw-eagain.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test/socket-rw-eagain.c b/test/socket-rw-eagain.c index 2d6a817..a12c70d 100644 --- a/test/socket-rw-eagain.c +++ b/test/socket-rw-eagain.c @@ -14,14 +14,15 @@ #include #include #include #include #include #include "liburing.h" +#include "helpers.h" int main(int argc, char *argv[]) { int p_fd[2], ret; int32_t recv_s0; int32_t val = 1; struct sockaddr_in addr; @@ -37,26 +38,15 @@ int main(int argc, char *argv[]) ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); assert(ret != -1); ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); assert(ret != -1); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - - do { - addr.sin_port = htons((rand() % 61440) + 4096); - ret = bind(recv_s0, (struct sockaddr*)&addr, sizeof(addr)); - if (!ret) - break; - if (errno != EADDRINUSE) { - perror("bind"); - exit(1); - } - } while (1); - + assert(!t_bind_ephemeral_port(recv_s0, &addr)); ret = listen(recv_s0, 128); assert(ret != -1); p_fd[1] = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); val = 1; ret = setsockopt(p_fd[1], IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); -- Ammar Faizi