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

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