From patchwork Fri Aug 3 22:14:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 28758 Received: (qmail 21608 invoked by alias); 3 Aug 2018 22:15:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 21486 invoked by uid 89); 3 Aug 2018 22:14:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham 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; Fri, 03 Aug 2018 22:14:58 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B99B406E886; Fri, 3 Aug 2018 22:14:56 +0000 (UTC) Received: from psique.yyz.redhat.com (unused-10-15-17-196.yyz.redhat.com [10.15.17.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1B7E10CD63A; Fri, 3 Aug 2018 22:14:53 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Joel Brobecker , Sergio Durigan Junior Subject: [obvious/pushed] Fix thinko when deciding whether to disable TCP's Nagle algorithm Date: Fri, 3 Aug 2018 18:14:50 -0400 Message-Id: <20180803221450.11838-1-sergiodj@redhat.com> X-IsSubscribed: yes This patch fixes a thinko that happened when I was implementing the IPv6 support on GDB/gdbserver. On certain situations, it is necessary to disable TCP's Nagle algorithm (NODELAY). For obvious reasons, this only applies when we are dealing with a TCP connection. While implementing the IPv6 patch, I noticed that the net_open function (on gdb/ser-tcp.c) kept a flag indicating whether the connection type was UDP or TCP. I eliminated that flag, and started using the 'struct addrinfo *' related to the successful connection directly. However, I made a mistake: if (success_ainfo->ai_socktype == IPPROTO_TCP) ^^^^^^^^^^^ { /* Disable Nagle algorithm. Needed in some cases. */ int tmp = 1; setsockopt (scb->fd, IPPROTO_TCP, TCP_NODELAY, (char *) &tmp, sizeof (tmp)); } The 'ai_socktype' field specifies the socket type (SOCK_STREAM or SOCK_DGRAM), and not the protocol. This test was always failing, and the Nagle algorithm was never being disabled. The obvious fix is to use the 'ai_protocol' field. This is what this patch does. Huge "thank you" to Joel Brobecker who reported the regression (he was experiencing an unusual delay while debugging a bare-metal program running under QEMU) and helped me set up a proper reproducer for the bug. gdb/ChangeLog: 2018-08-03 Sergio Durigan Junior * ser-tcp.c (net_open): Fix thinko when deciding whether to disable TCP's Nagle algorithm (use "ai_protocol" instead of "ai_socktype"). --- gdb/ChangeLog | 6 ++++++ gdb/ser-tcp.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 227e3ff74f..43594561d5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-08-03 Sergio Durigan Junior + + * ser-tcp.c (net_open): Fix thinko when deciding whether to + disable TCP's Nagle algorithm (use "ai_protocol" instead of + "ai_socktype"). + 2018-08-02 Tom Tromey PR symtab/16842. diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c index 618d2d931a..bdfd55663b 100644 --- a/gdb/ser-tcp.c +++ b/gdb/ser-tcp.c @@ -371,7 +371,7 @@ net_open (struct serial *scb, const char *name) ioctl (scb->fd, FIONBIO, &ioarg); - if (success_ainfo->ai_socktype == IPPROTO_TCP) + if (success_ainfo->ai_protocol == IPPROTO_TCP) { /* Disable Nagle algorithm. Needed in some cases. */ int tmp = 1;