public inbox for [email protected]
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Dylan Yudaken <[email protected]>
Cc: Jens Axboe <[email protected]>,
	Pavel Begunkov <[email protected]>,
	 io_uring Mailing List <[email protected]>,
	Facebook Kernel Team <[email protected]>
Subject: Re: [PATCH v2 liburing 1/7] add t_create_socket_pair
Date: Thu, 30 Jun 2022 18:31:12 +0700	[thread overview]
Message-ID: <CAFBCWQL38oChF7juHKUv4i4zF0je+98uWkXYhckJAmr89G=ncw@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>

On Thu, Jun 30, 2022 at 4:19 PM Dylan Yudaken <[email protected]> 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

  reply	other threads:[~2022-06-30 11:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30  9:14 [PATCH v2 liburing 0/7] liburing: multishot receive Dylan Yudaken
2022-06-30  9:14 ` [PATCH v2 liburing 1/7] add t_create_socket_pair Dylan Yudaken
2022-06-30 11:31   ` Ammar Faizi [this message]
2022-06-30  9:14 ` [PATCH v2 liburing 2/7] add IORING_RECV_MULTISHOT to io_uring.h Dylan Yudaken
2022-06-30  9:14 ` [PATCH v2 liburing 3/7] add io_uring_prep_(recv|recvmsg)_multishot Dylan Yudaken
2022-06-30  9:14 ` [PATCH v2 liburing 4/7] add IORING_RECV_MULTISHOT docs Dylan Yudaken
2022-06-30  9:14 ` [PATCH v2 liburing 5/7] add recv-multishot test Dylan Yudaken
2022-06-30 11:24   ` Ammar Faizi
2022-06-30 16:53     ` Dylan Yudaken
2022-06-30  9:14 ` [PATCH v2 liburing 6/7] add poll overflow test Dylan Yudaken
2022-06-30  9:14 ` [PATCH v2 liburing 7/7] add accept with " Dylan Yudaken

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFBCWQL38oChF7juHKUv4i4zF0je+98uWkXYhckJAmr89G=ncw@mail.gmail.com' \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox