From: DJ Delorie <dj@redhat.com>
To: Siddhesh Poyarekar <siddhesh@sourceware.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v2] getaddrinfo: Refactor code for readability
Date: Tue, 22 Mar 2022 15:05:34 -0400 [thread overview]
Message-ID: <xna6dhg64h.fsf@greed.delorie.com> (raw)
In-Reply-To: <20220322171005.2566082-1-siddhesh@sourceware.org>
LGTM
Reviewed-by: DJ Delorie <dj@redhat.com>
Siddhesh Poyarekar <siddhesh@sourceware.org> writes:
> diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
>
> +static bool
> +try_connect (int *fdp, int *afp, struct sockaddr_in6 *source_addrp,
> + const struct sockaddr *addr, socklen_t addrlen, int family)
> +{
> + int fd = *fdp;
> + int af = *afp;
> + socklen_t sl = sizeof (*source_addrp);
> +
> + while (true)
> + {
> + if (fd != -1 && __connect (fd, addr, addrlen) == 0
> + && __getsockname (fd, (struct sockaddr *) source_addrp, &sl) == 0)
> + return true;
> +
> + if (errno == EAFNOSUPPORT && af == AF_INET6 && family == AF_INET)
> + {
> + /* This could mean IPv6 sockets are IPv6-only. */
> + if (fd != -1)
> + __close_nocancel_nostatus (fd);
> + *afp = af = AF_INET;
> + *fdp = fd = __socket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC,
> + IPPROTO_IP);
> + continue;
> + }
> +
> + return false;
> + }
> +
> + __builtin_unreachable ();
> +}
Ok.
> if (fd != -1)
> - close_retry:
> __close_nocancel_nostatus (fd);
Ok.
> - socklen_t sl = sizeof (results[i].source_addr);
> - if (fd != -1
> - && __connect (fd, q->ai_addr, q->ai_addrlen) == 0
> - && __getsockname (fd,
> - (struct sockaddr *) &results[i].source_addr,
> - &sl) == 0)
> + if (try_connect (&fd, &af, &results[i].source_addr, q->ai_addr,
> + q->ai_addrlen, q->ai_family))
Ok.
> - results[i].source_addr_len = sl;
> + results[i].source_addr_len = sizeof (results[i].source_addr);
Ok.
> - else if (errno == EAFNOSUPPORT && af == AF_INET6
> - && q->ai_family == AF_INET)
> - /* This could mean IPv6 sockets are IPv6-only. */
> - goto close_retry;
Ok.
prev parent reply other threads:[~2022-03-22 19:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-14 17:30 [PATCH 0/3] More getaddrinfo refactoring Siddhesh Poyarekar
2022-03-14 17:30 ` [PATCH 1/3] gaiconf_init: Refactor some bits for readability Siddhesh Poyarekar
2022-03-17 22:41 ` DJ Delorie
2022-03-14 17:30 ` [PATCH 2/3] gai_init: Avoid jumping from if condition to its else counterpart Siddhesh Poyarekar
2022-03-17 23:48 ` DJ Delorie
2022-03-14 17:30 ` [PATCH 3/3] getaddrinfo: Refactor code for readability Siddhesh Poyarekar
2022-03-18 0:20 ` DJ Delorie
2022-03-22 17:10 ` [PATCH v2] " Siddhesh Poyarekar
2022-03-22 19:05 ` DJ Delorie [this message]
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=xna6dhg64h.fsf@greed.delorie.com \
--to=dj@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=siddhesh@sourceware.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).