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.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by gnuweeb.org (Postfix) with ESMTPS id 3DE0980111 for ; Thu, 30 Jun 2022 11:31:29 +0000 (UTC) Authentication-Results: gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=DSg2NVBT; dkim-atps=neutral Received: by mail-pl1-f176.google.com with SMTP id jh14so16792466plb.1 for ; Thu, 30 Jun 2022 04:31:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aQuRZYIz9QunG3INUJqeHn04NNvKE3NAELMTnwVzTXs=; b=DSg2NVBTdwTOVurkEj4cKRcWG/roGQGvcT5SVcbBvl7ZK3qjK/KcIxhVNdjq4NLE0L YNkQnJgqxny+EFV2Hjfoz5G+jEif/Fy/LoE31RrZJAkHmmlZTSDc3LnkcGxXgKMIyR9/ vsfBCi88LtMYRjPNRCBEkw/BC1A2hV2c+xeTNMXKxi4U3e5uaJVE/cwvfe+4oG2yoxDe UIBKB5y+CFxiNS2hC0m6pvBVxz5NFtHGe6w+ZwOKTNoIQygf3+bv2wq4vWlaExc0YuQJ U1JtRgqWQPLGyiigCre9JgTStcqVi3NYOKsCgY3yFUcm3xj/Znn/A+VyHO8AgEi8Tw8w R1Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aQuRZYIz9QunG3INUJqeHn04NNvKE3NAELMTnwVzTXs=; b=JtmuAghg7x5dCt2ct5ec+77fQyBZgDe+Q1Z1JDgalx3rA6a8sr3idN3XsNLda4wDY8 iM3lHb6x+gp7eXSbOydF214zGTZEX2TPYsXCmJAiS6KvsDeFk17mMIOjMFOosyubm1Yj ycKI01jN55sqMVLv+yDlCFcLLuw7aB5XSNutzn/TQx//YggzPKUD3w1ELRgQUpdidGTW 667acLFvaGXOyAna7t7vbhla7SPSoWI4yODpWjVzftIrScptZTD/dmioGTLMJ8OauioG Ucv9r9Ul37lIy3fc//ebltIXy9fuiG/9CjJYnKDcBuHL0iWYYpd1V8HryxHMk8daflO5 8ZOA== X-Gm-Message-State: AJIora+Iq8ucneAJiPQxZ46+dAMPpzVqrjC02ztgHjv80VJX92UK3/z7 aFnS0Z6gBBZNqq1S4F3+bcgovKDKaAjp6hDKR9U= X-Google-Smtp-Source: AGRyM1t0xenqiXHeVj7aSSLxV9upQOQWXSpBwzSxsee0ppPp8t7g5lnobAgLtmJRyKSp0VzSx33fdfXk6OyFLpZnxGM= X-Received: by 2002:a17:90a:410a:b0:1ec:7fc8:6d15 with SMTP id u10-20020a17090a410a00b001ec7fc86d15mr9802530pjf.236.1656588688678; Thu, 30 Jun 2022 04:31:28 -0700 (PDT) MIME-Version: 1.0 References: <20220630091422.1463570-1-dylany@fb.com> <20220630091422.1463570-2-dylany@fb.com> In-Reply-To: <20220630091422.1463570-2-dylany@fb.com> From: Ammar Faizi Date: Thu, 30 Jun 2022 18:31:12 +0700 Message-ID: Subject: Re: [PATCH v2 liburing 1/7] add t_create_socket_pair To: Dylan Yudaken Cc: Jens Axboe , Pavel Begunkov , io_uring Mailing List , Facebook Kernel Team Content-Type: text/plain; charset="UTF-8" List-Id: On Thu, Jun 30, 2022 at 4:19 PM Dylan Yudaken wrote: > +int t_create_socket_pair(int fd[2], bool stream) > +{ [ snip... ] > + if (!stream) { > + /* connect the other udp side */ > + if (getsockname(fd[1], &serv_addr, (socklen_t *)&paddrlen)) { > + fprintf(stderr, "getsockname failed\n"); > + goto errno_cleanup; > + } > + inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr); > + > + if (connect(fd[0], &serv_addr, paddrlen)) { > + fprintf(stderr, "connect failed\n"); > + goto errno_cleanup; > + } > + return 0; > + } > + > + /* for stream case we must accept and cleanup the listen socket */ > + > + ret = accept(fd[0], NULL, NULL); > + if (ret < 0) > + goto errno_cleanup; > + > + close(fd[0]); > + fd[0] = ret; > + > + val = 1; > + if (stream && setsockopt(fd[0], SOL_TCP, TCP_NODELAY, &val, sizeof(val))) > + goto errno_cleanup; > + val = 1; > + if (stream && setsockopt(fd[1], SOL_TCP, TCP_NODELAY, &val, sizeof(val))) > + goto errno_cleanup; If we reach here, the @stream is always true, because when it's false, we early return from the `if (!stream)` above. So these two @stream checks for setsockopt() are not needed. > + return 0; > + > +errno_cleanup: > + ret = errno; > + close(fd[0]); > + close(fd[1]); > + return ret; > +} -- Ammar Faizi