Blame SOURCES/gdb-rhbz881849-ipv6-3of3.patch

7bc85d
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
7bc85d
From: Sergio Durigan Junior <sergiodj@redhat.com>
7bc85d
Date: Fri, 3 Aug 2018 18:04:38 -0400
7bc85d
Subject: gdb-rhbz881849-ipv6-3of3.patch
7bc85d
7bc85d
Fix thinko when deciding whether to disable TCP's Nagle algorithm
7bc85d
7bc85d
This patch fixes a thinko that happened when I was implementing the
7bc85d
IPv6 support on GDB/gdbserver.  On certain situations, it is necessary
7bc85d
to disable TCP's Nagle algorithm (NODELAY).  For obvious reasons, this
7bc85d
only applies when we are dealing with a TCP connection.
7bc85d
7bc85d
While implementing the IPv6 patch, I noticed that the net_open
7bc85d
function (on gdb/ser-tcp.c) kept a flag indicating whether the
7bc85d
connection type was UDP or TCP.  I eliminated that flag, and started
7bc85d
using the 'struct addrinfo *' related to the successful connection
7bc85d
directly.  However, I made a mistake:
7bc85d
7bc85d
  if (success_ainfo->ai_socktype == IPPROTO_TCP)
7bc85d
                     ^^^^^^^^^^^
7bc85d
    {
7bc85d
      /* Disable Nagle algorithm.  Needed in some cases.  */
7bc85d
      int tmp = 1;
7bc85d
7bc85d
      setsockopt (scb->fd, IPPROTO_TCP, TCP_NODELAY,
7bc85d
		  (char *) &tmp, sizeof (tmp));
7bc85d
    }
7bc85d
7bc85d
The 'ai_socktype' field specifies the socket type (SOCK_STREAM or
7bc85d
SOCK_DGRAM), and not the protocol.  This test was always failing, and
7bc85d
the Nagle algorithm was never being disabled.
7bc85d
7bc85d
The obvious fix is to use the 'ai_protocol' field.  This is what this
7bc85d
patch does.
7bc85d
7bc85d
Huge "thank you" to Joel Brobecker who reported the regression (he was
7bc85d
experiencing an unusual delay while debugging a bare-metal program
7bc85d
running under QEMU) and helped me set up a proper reproducer for the
7bc85d
bug.
7bc85d
7bc85d
gdb/ChangeLog:
7bc85d
2018-08-03  Sergio Durigan Junior  <sergiodj@redhat.com>
7bc85d
7bc85d
	* ser-tcp.c (net_open): Fix thinko when deciding whether to
7bc85d
	disable TCP's Nagle algorithm (use "ai_protocol" instead of
7bc85d
	"ai_socktype").
7bc85d
7bc85d
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
7bc85d
--- a/gdb/ChangeLog
7bc85d
+++ b/gdb/ChangeLog
7bc85d
@@ -1,3 +1,9 @@
7bc85d
+2018-08-03  Sergio Durigan Junior  <sergiodj@redhat.com>
7bc85d
+
7bc85d
+	* ser-tcp.c (net_open): Fix thinko when deciding whether to
7bc85d
+	disable TCP's Nagle algorithm (use "ai_protocol" instead of
7bc85d
+	"ai_socktype").
7bc85d
+
7bc85d
 2018-09-05  Joel Brobecker  <brobecker@adacore.com>
7bc85d
 
7bc85d
 	* version.in: Set GDB version number to 8.2.
7bc85d
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
7bc85d
--- a/gdb/ser-tcp.c
7bc85d
+++ b/gdb/ser-tcp.c
7bc85d
@@ -367,7 +367,7 @@ net_open (struct serial *scb, const char *name)
7bc85d
 
7bc85d
   ioctl (scb->fd, FIONBIO, &ioarg);
7bc85d
 
7bc85d
-  if (success_ainfo->ai_socktype == IPPROTO_TCP)
7bc85d
+  if (success_ainfo->ai_protocol == IPPROTO_TCP)
7bc85d
     {
7bc85d
       /* Disable Nagle algorithm.  Needed in some cases.  */
7bc85d
       int tmp = 1;