From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 49754 invoked by alias); 11 Jul 2018 23:43:00 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 49734 invoked by uid 89); 11 Jul 2018 23:43:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,TRACKER_ID autolearn=no version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jul 2018 23:42:58 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0851D40776C2; Wed, 11 Jul 2018 23:42:57 +0000 (UTC) Received: from localhost (unused-10-15-17-196.yyz.redhat.com [10.15.17.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A9382156891; Wed, 11 Jul 2018 23:42:56 +0000 (UTC) From: Sergio Durigan Junior To: Pedro Alves Cc: GDB Patches , Eli Zaretskii , Jan Kratochvil , Paul Fertser , Tsutomu Seki , Armand Scholtes Subject: Re: [PATCH v4] Implement IPv6 support for GDB/gdbserver References: <20180523185719.22832-1-sergiodj@redhat.com> <20180711191609.23752-1-sergiodj@redhat.com> <453bd3a6-3cd8-b1df-5a84-52903b5deb36@redhat.com> Date: Wed, 11 Jul 2018 23:43:00 -0000 In-Reply-To: <453bd3a6-3cd8-b1df-5a84-52903b5deb36@redhat.com> (Pedro Alves's message of "Wed, 11 Jul 2018 22:48:18 +0100") Message-ID: <874lh5qqyn.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2018-07/txt/msg00327.txt.bz2 On Wednesday, July 11 2018, Pedro Alves wrote: > 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. Done. >> >> 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. I don't know why I removed the existing comment. Sorry about that. I readded it and rearranged them accordingly. >> 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. That's true, mistake on my part. > 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; Right, will do that. >> + 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; That's true. And also, in this case, I have to guard the errno checking that happens on net_open using #ifdef USE_WIN32API...#else...#endif. Done that as well. >> + } >> + >> + /* The connection succeeded. Return the socket. */ >> + return sock; >> +} >> + > OK with the issues above fixed. Thanks for the reviews. Pushed. c7ab0aef11d91b637bf091aa9176b8dc4aadee46 -- Sergio GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36 Please send encrypted e-mail if possible http://sergiodj.net/