From: Pedro Alves <palves@redhat.com>
To: Sergio Durigan Junior <sergiodj@redhat.com>,
GDB Patches <gdb-patches@sourceware.org>
Cc: Eli Zaretskii <eliz@gnu.org>,
Jan Kratochvil <jan.kratochvil@redhat.com>,
Paul Fertser <fercerpav@gmail.com>,
Tsutomu Seki <sekiriki@gmail.com>,
Armand Scholtes <armandsmailings@home.nl>
Subject: Re: [PATCH v4] Implement IPv6 support for GDB/gdbserver
Date: Wed, 11 Jul 2018 21:48:00 -0000 [thread overview]
Message-ID: <453bd3a6-3cd8-b1df-5a84-52903b5deb36@redhat.com> (raw)
In-Reply-To: <20180711191609.23752-1-sergiodj@redhat.com>
On 07/11/2018 08:16 PM, Sergio Durigan Junior wrote:
> Changes since v3:
>
> - No longer use gdb::optional as a return type for try_connect; use
> int instead.
>
> - Fix a bunch of typos and thinkos.
>
Thanks.
> +/* Helper class to guarantee that we always call 'freeaddrinfo'. */
> +
> +class scoped_free_addrinfo
> +{
> +public:
> + /* Default constructor. */
> + scoped_free_addrinfo (struct addrinfo *ainfo)
> + : m_res (ainfo)
explicit.
>
> if (
> #ifdef USE_WIN32API
> - /* Under Windows, calling "connect" with a non-blocking socket
> - results in WSAEWOULDBLOCK, not WSAEINPROGRESS. */
> + /* Any other error (except EINPROGRESS) will be "swallowed"
> + here. We return without specifying a return value, and
> + set errno if the caller wants to inspect what
> + happened. */
This comment should be outside "#ifdef USE_WIN32API", and the
existing comment "Under Windows, ... WSAEWOULDBLOCK" should be
preserved.
> err != WSAEWOULDBLOCK
> #else
> err != EINPROGRESS
> #endif
> )
> {
> + close (sock);
> errno = err;
> - net_close (scb);
> return -1;
> }
>
> + /* On Windows, the fourth parameter to getsockopt is a "char *";
> + on UNIX systems it is generally "void *". The cast to "char *"
> + is OK everywhere, since in C++ any data pointer type can be
> + implicitly converted to "void *". */
> + int ret = getsockopt (sock, SOL_SOCKET, SO_ERROR, (char *) &err, &len);
> +
> + if (ret < 0)
> + {
> + close (sock);
> + errno = ret;
I don't think this "errno = ret" here is right. getsockopt returns
-1 on error with errno already set. Pedantically, close can
fail and set errno, so the correct thing to do is:
int save_errno = errno;
close (sock);
errno = save_errno;
return -1;
> + return -1;
> + }
> + else if (ret == 0 && err != 0)
> + {
> + close (sock);
> + errno = err;
> +
> + /* Check if the connection was refused. */
> + if (
> #ifdef USE_WIN32API
> - && err == WSAECONNREFUSED
> + err == WSAECONNREFUSED
> #else
> - && err == ECONNREFUSED
> + err == ECONNREFUSED
> #endif
> - && wait_for_connect (NULL, &polls) >= 0)
> - {
> - close (scb->fd);
> - goto retry;
> - }
> - if (err)
> - errno = err;
> - net_close (scb);
> + )
> return -1;> - }
> - }
> + else
> + {
> + /* If we have any other kind of error, just return nothing. */
> + return -1;
> + }
Aren't both the then/else branches exactly the same, i.e.,
just "return -1;" ?
Seems like you can all the "if then/else", and just return -1;
> + }
> +
> + /* The connection succeeded. Return the socket. */
> + return sock;
> +}
> +
OK with the issues above fixed.
Thanks,
Pedro Alves
next prev parent reply other threads:[~2018-07-11 21:48 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-23 21:48 [PATCH] " Sergio Durigan Junior
2018-05-23 23:40 ` Eli Zaretskii
2018-05-24 0:41 ` Sergio Durigan Junior
2018-05-24 16:54 ` Eli Zaretskii
2018-05-25 1:57 ` Sergio Durigan Junior
2018-05-31 20:10 ` Sergio Durigan Junior
2018-06-06 12:26 ` Pedro Alves
2018-06-08 1:13 ` Sergio Durigan Junior
2018-06-08 13:53 ` Pedro Alves
2018-06-08 17:47 ` Sergio Durigan Junior
2018-06-08 18:44 ` Pedro Alves
2018-06-08 19:28 ` Pedro Alves
2018-06-08 19:51 ` Pedro Alves
2018-06-08 20:43 ` Sergio Durigan Junior
2018-06-08 21:21 ` Sergio Durigan Junior
2018-06-08 21:51 ` Pedro Alves
2018-06-08 22:01 ` Sergio Durigan Junior
2018-06-15 0:25 ` [PATCH v2] " Sergio Durigan Junior
2018-06-15 7:12 ` Eli Zaretskii
2018-06-20 15:24 ` Pedro Alves
2018-06-21 4:54 ` Sergio Durigan Junior
2018-07-07 20:47 ` [PATCH v3] " Sergio Durigan Junior
2018-07-11 12:55 ` Pedro Alves
2018-07-11 19:13 ` Sergio Durigan Junior
2018-07-11 19:16 ` [PATCH v4] " Sergio Durigan Junior
2018-07-11 21:48 ` Pedro Alves [this message]
2018-07-11 23:43 ` Sergio Durigan Junior
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=453bd3a6-3cd8-b1df-5a84-52903b5deb36@redhat.com \
--to=palves@redhat.com \
--cc=armandsmailings@home.nl \
--cc=eliz@gnu.org \
--cc=fercerpav@gmail.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.com \
--cc=sekiriki@gmail.com \
--cc=sergiodj@redhat.com \
/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).