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

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