From nobody Mon Apr 6 23:08:52 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0394C38145 for ; Fri, 2 Sep 2022 01:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234852AbiIBBBN (ORCPT ); Thu, 1 Sep 2022 21:01:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235060AbiIBBAn (ORCPT ); Thu, 1 Sep 2022 21:00:43 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 174F45283C for ; Thu, 1 Sep 2022 18:00:39 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.38.99]) by gnuweeb.org (Postfix) with ESMTPSA id 9384080C0F; Fri, 2 Sep 2022 01:00:35 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662080439; bh=9GSXmeVjCxnKtOIl8QXARd1WE15qBfZ6Fsg6NpWTl7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YZDE+vqvKQs2IiFObLQGYe56c1JQ2spJtNsYb1nxLPiDd5/q7gq/GsVqs5liG1Cyr hs+QBx8s5lZKRX84VZedS9HOGM1Kkxqg/Luse9g5s0lJ6nWgZIh+y5E93hBmsTIW8g lSTXPcPiQg4TtvP5bGB9u19wwIJh3CRdQKGqkMfTY24TUMx3tWORDRaZiH0vuC0k+p iw5pBJ6pntwMxEvqK6yF0Whq1dIh5YIjil+VKlMsBN1pKt7rYfktXGPRBdfMVmaVUD vxrDiVJlkqbJVH4ibX+r9VZsmalWovS2ZwDKMhYGkMZ/VTlz+eB2nAmj662hjfee9n Mw61yG7GrB8ig== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , Kanna Scarlet , Muhammad Rizki , GNU/Weeb Mailing List , io-uring Mailing List , Linux Kernel Mailing List Subject: [PATCH liburing v1 05/12] t/socket-rw-offset: Don't brute force the port number Date: Fri, 2 Sep 2022 07:59:39 +0700 Message-Id: <20220902005825.2484023-6-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902005825.2484023-1-ammar.faizi@intel.com> References: <20220902005825.2484023-1-ammar.faizi@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Ammar Faizi --- test/socket-rw-offset.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/test/socket-rw-offset.c b/test/socket-rw-offset.c index 987b6c9..c422442 100644 --- a/test/socket-rw-offset.c +++ b/test/socket-rw-offset.c @@ -10,60 +10,51 @@ #include #include =20 #include #include #include #include #include #include #include #include =20 #include "liburing.h" +#include "helpers.h" =20 int main(int argc, char *argv[]) { int p_fd[2], ret; int32_t recv_s0; int32_t val =3D 1; struct sockaddr_in addr; struct iovec iov_r[1], iov_w[1]; =20 if (argc > 1) return 0; =20 srand(getpid()); =20 recv_s0 =3D socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); =20 ret =3D setsockopt(recv_s0, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); assert(ret !=3D -1); ret =3D setsockopt(recv_s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); assert(ret !=3D -1); =20 addr.sin_family =3D AF_INET; addr.sin_addr.s_addr =3D inet_addr("127.0.0.1"); - - do { - addr.sin_port =3D htons((rand() % 61440) + 4096); - ret =3D bind(recv_s0, (struct sockaddr*)&addr, sizeof(addr)); - if (!ret) - break; - if (errno !=3D EADDRINUSE) { - perror("bind"); - exit(1); - } - } while (1); + assert(!t_bind_ephemeral_port(recv_s0, &addr)); ret =3D listen(recv_s0, 128); assert(ret !=3D -1); =20 =20 p_fd[1] =3D socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); =20 val =3D 1; ret =3D setsockopt(p_fd[1], IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); assert(ret !=3D -1); =20 int32_t flags =3D fcntl(p_fd[1], F_GETFL, 0); assert(flags !=3D -1); =20 --=20 Ammar Faizi