public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
From: jkratoch@sourceware.org
To: archer-commits@sourceware.org
Subject: [SCM]  jankratochvil/ipv6: .
Date: Mon, 15 Apr 2013 20:10:00 -0000	[thread overview]
Message-ID: <20130415201059.18583.qmail@sourceware.org> (raw)

The branch, jankratochvil/ipv6 has been updated
       via  410dc9a3df7413cb21be3dd86d163938b7f23dfa (commit)
      from  a2ba627216df40efd23a515651c16368d588e38b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 410dc9a3df7413cb21be3dd86d163938b7f23dfa
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Mon Apr 15 22:10:52 2013 +0200

    .

-----------------------------------------------------------------------

Summary of changes:
 gdb/gdbserver/gdbreplay.c    |  194 +++++++++++++++++-------------------------
 gdb/gdbserver/remote-utils.c |   85 ++++++++++++------
 gdb/gdbserver/server.h       |    4 +-
 gdb/ser-tcp.c                |  192 ++++++++++++++++++++++++-----------------
 4 files changed, 248 insertions(+), 227 deletions(-)

First 500 lines of diff:
diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c
index ad4c0d0..9ed2fb5 100644
--- a/gdb/gdbserver/gdbreplay.c
+++ b/gdb/gdbserver/gdbreplay.c
@@ -76,7 +76,7 @@ typedef int socklen_t;
 extern const char version[];
 extern const char host_name[];
 
-static int remote_desc_in, remote_desc_out;
+static int remote_desc;
 
 #ifdef __MINGW32CE__
 
@@ -177,152 +177,114 @@ static void
 remote_close (void)
 {
 #ifdef USE_WIN32API
-  closesocket (remote_desc_in);
-  if (remote_desc_in != remote_desc_out)
-    closesocket (remote_desc_out);
+  closesocket (remote_desc);
 #else
-  close (remote_desc_in);
-  if (remote_desc_in != remote_desc_out)
-    close (remote_desc_out);
+  close (remote_desc);
 #endif
 }
 
-/* Parse the string "fdin=<#>,fdout=<#>" into `remote_desc_in' and
-   `remote_desc_out' file descripts.  Return non-zero for success.  */
-
-static int
-parse_fds (char *name)
-{
-  const char *fdin_string = "fdin=";
-  size_t fdin_string_len = strlen (fdin_string);
-  const char *comma_fdout_string = ",fdout=";
-  size_t comma_fdout_string_len = strlen (comma_fdout_string);
-  long l;
-
-  if (strncmp (name, fdin_string, fdin_string_len) != 0)
-    return 0;
-  name += fdin_string_len;
-
-  if (*name == 0 || *name == ',')
-    return 0;
-  errno = 0;
-  l = strtol (name, &name, 10);
-  remote_desc_in = l;
-  if (errno != 0 || name == NULL || l < 0 || remote_desc_in != l)
-    return 0;
-
-  if (strncmp (name, comma_fdout_string, comma_fdout_string_len) != 0)
-    return 0;
-  name += comma_fdout_string_len;
-
-  if (*name == 0 || *name == ',')
-    return 0;
-  errno = 0;
-  l = strtol (name, &name, 10);
-  remote_desc_out = l;
-  if (errno != 0 || name == NULL || l < 0 || remote_desc_out != l)
-    return 0;
-
-  if (*name != 0)
-    return 0;
-
-  return 1;
-}
-
 /* Open a connection to a remote debugger.
    NAME is the filename used for communication.  */
 
 static void
 remote_open (char *name)
 {
-  /* "fdin=<#>,fdout=<#>"  */
-  if (parse_fds (name))
-    {
-      fprintf (stderr, "Remote debugging using file descriptors"
-               " (input = %d, output = %d)\n", remote_desc_in, remote_desc_out);
-    }
-  else if (!strchr (name, ':'))
+  char *port_str = strrchr (name, ':');
+#ifdef USE_WIN32API
+  static int winsock_initialized;
+#endif
+  struct sockaddr_in sockaddr;
+  socklen_t socklen;
+  int tmp_desc, n, i;
+  struct addrinfo hints;
+  struct addrinfo *addrinfo_base, *addrinfo;
+
+  if (port_str == NULL)
     {
-      fprintf (stderr, "%s: Must specify tcp connection as host:addr"
-	       " or use fdin=<fd #>,fdout=<fd #>\n", name);
+      fprintf (stderr, "%s: Must specify tcp connection as host:addr\n", name);
       fflush (stderr);
       exit (1);
     }
-  else
-    {
-      int remote_desc;
+
 #ifdef USE_WIN32API
-      static int winsock_initialized;
+  if (!winsock_initialized)
+    {
+      WSADATA wsad;
+
+      WSAStartup (MAKEWORD (1, 0), &wsad);
+      winsock_initialized = 1;
+    }
 #endif
-      char *port_str;
-      int port;
-      struct sockaddr_in sockaddr;
-      socklen_t tmp;
-      int tmp_desc;
 
-      port_str = strchr (name, ':');
+  memset (&hints, 0, sizeof hints);
+  hints.ai_family = AF_UNSPEC;
+  hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_PASSIVE;
+  hints.ai_socktype = SOCK_STREAM;
 
-      port = atoi (port_str + 1);
+  *port_str = 0;
+  n = getaddrinfo (name, port_str, &hints, &addrinfo_base);
+  if (n != 0)
+    {
+      fprintf (stderr, "%s:%s: cannot resolve: %s\n",
+	       name, port_str, gai_strerror (n));
+      exit (1);
+    }
 
-#ifdef USE_WIN32API
-      if (!winsock_initialized)
+  for (addrinfo = addrinfo_base; addrinfo != NULL;
+       addrinfo = addrinfo->ai_next)
+    {
+      tmp_desc = socket (addrinfo->ai_family, addrinfo->ai_socktype,
+			 addrinfo->ai_protocol);
+      if (tmp_desc == -1)
 	{
-	  WSADATA wsad;
+	  if (addrinfo->ai_next != NULL)
+	    continue;
+	  perror_with_name ("Can't open socket");
+	}
+
+      /* Allow rapid reuse of this port. */
+      i = 1;
+      setsockopt (tmp_desc, SOL_SOCKET, SO_REUSEADDR, &i, sizeof (i));
 
-	  WSAStartup (MAKEWORD (1, 0), &wsad);
-	  winsock_initialized = 1;
+      if (bind (tmp_desc, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0
+	  || listen (tmp_desc, 1) != 0)
+	{
+	  if (addrinfo->ai_next != NULL)
+	    {
+	      close (tmp_desc);
+	      continue;
+	    }
+	  perror_with_name ("Can't bind address");
 	}
-#endif
+      break;
+    }
 
-      tmp_desc = socket (PF_INET, SOCK_STREAM, 0);
-      if (tmp_desc == -1)
-	perror_with_name ("Can't open socket");
+  socklen = sizeof (sockaddr);
+  remote_desc = accept (tmp_desc, (struct sockaddr *) &sockaddr, &socklen);
+  if (remote_desc == -1)
+    perror_with_name ("Accept failed");
 
-      /* Allow rapid reuse of this port. */
-      tmp = 1;
-      setsockopt (tmp_desc, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp,
-		  sizeof (tmp));
-
-      sockaddr.sin_family = PF_INET;
-      sockaddr.sin_port = htons (port);
-      sockaddr.sin_addr.s_addr = INADDR_ANY;
-
-      if (bind (tmp_desc, (struct sockaddr *) &sockaddr, sizeof (sockaddr))
-	  || listen (tmp_desc, 1))
-	perror_with_name ("Can't bind address");
-
-      tmp = sizeof (sockaddr);
-      remote_desc = accept (tmp_desc, (struct sockaddr *) &sockaddr, &tmp);
-      if (remote_desc == -1)
-	perror_with_name ("Accept failed");
-
-      /* Enable TCP keep alive process. */
-      tmp = 1;
-      setsockopt (tmp_desc, SOL_SOCKET, SO_KEEPALIVE,
-		  (char *) &tmp, sizeof (tmp));
-
-      /* Tell TCP not to delay small packets.  This greatly speeds up
-	 interactive response. */
-      tmp = 1;
-      setsockopt (remote_desc, IPPROTO_TCP, TCP_NODELAY,
-		  (char *) &tmp, sizeof (tmp));
+  /* Enable TCP keep alive process. */
+  i = 1;
+  setsockopt (tmp_desc, SOL_SOCKET, SO_KEEPALIVE, &i, sizeof (i));
+
+  /* Tell TCP not to delay small packets.  This greatly speeds up
+     interactive response. */
+  i = 1;
+  setsockopt (remote_desc, IPPROTO_TCP, TCP_NODELAY, &i, sizeof (i));
 
 #ifndef USE_WIN32API
-      close (tmp_desc);		/* No longer need this */
+  close (tmp_desc);		/* No longer need this */
 
-      signal (SIGPIPE, SIG_IGN);	/* If we don't do this, then
-					   gdbreplay simply exits when
-					   the remote side dies.  */
+  signal (SIGPIPE, SIG_IGN);	/* If we don't do this, then
+				   gdbreplay simply exits when
+				   the remote side dies.  */
 #else
-      closesocket (tmp_desc);	/* No longer need this */
+  closesocket (tmp_desc);	/* No longer need this */
 #endif
-      remote_desc_in = remote_desc_out = remote_desc;
-    }
 
 #if defined(F_SETFL) && defined (FASYNC)
-  fcntl (remote_desc_in, F_SETFL, FASYNC);
-  if (remote_desc_in != remote_desc_out)
-    fcntl (remote_desc_out, F_SETFL, FASYNC);
+  fcntl (remote_desc, F_SETFL, FASYNC);
 #endif
 
   fprintf (stderr, "Replay logfile using %s\n", name);
diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index fe0e39a..9f896b0 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -60,7 +60,6 @@
 #if HAVE_ERRNO_H
 #include <errno.h>
 #endif
-#include <ctype.h>
 
 #if USE_WIN32API
 #include <winsock2.h>
@@ -221,16 +220,16 @@ handle_accept_event (int err, gdb_client_data client_data)
    NAME is the filename used for communication.  */
 
 void
-remote_prepare (char *name)
+remote_prepare (const char *name)
 {
-  char *port_str;
+  const char *port_str;
+  char *hostname;
+  int n;
+  struct addrinfo hints;
+  struct addrinfo *addrinfo_base, *addrinfo;
 #ifdef USE_WIN32API
   static int winsock_initialized;
 #endif
-  int port;
-  struct sockaddr_in sockaddr;
-  socklen_t tmp;
-  char *port_end;
 
   remote_is_stdio = 0;
   if (strcmp (name, STDIO_CONNECTION_NAME) == 0)
@@ -243,17 +242,13 @@ remote_prepare (char *name)
       return;
     }
 
-  port_str = strchr (name, ':');
+  port_str = strrchr (name, ':');
   if (port_str == NULL)
     {
       transport_is_reliable = 0;
       return;
     }
 
-  port = strtoul (port_str + 1, &port_end, 10);
-  if (port_str[1] == '\0' || *port_end != '\0')
-    fatal ("Bad port argument: %s", name);
-
 #ifdef USE_WIN32API
   if (!winsock_initialized)
     {
@@ -264,22 +259,56 @@ remote_prepare (char *name)
     }
 #endif
 
-  listen_desc = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
-  if (listen_desc == -1)
-    perror_with_name ("Can't open socket");
+  memset (&hints, 0, sizeof hints);
+  hints.ai_family = AF_UNSPEC;
+  hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_PASSIVE;
+  hints.ai_socktype = SOCK_STREAM;
 
-  /* Allow rapid reuse of this port. */
-  tmp = 1;
-  setsockopt (listen_desc, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp,
-	      sizeof (tmp));
+  hostname = xstrdup (name);
+  hostname[port_str - name] = 0;
+  port_str++;
+  if (*hostname == 0)
+    hostname = NULL;
 
-  sockaddr.sin_family = PF_INET;
-  sockaddr.sin_port = htons (port);
-  sockaddr.sin_addr.s_addr = INADDR_ANY;
+  n = getaddrinfo (hostname, port_str, &hints, &addrinfo_base);
+  if (n != 0)
+    {
+      fprintf (stderr, _("%s:%s: cannot resolve: %s\n"),
+	       hostname, port_str, gai_strerror (n));
+      transport_is_reliable = 0;
+      return;
+    }
+
+  for (addrinfo = addrinfo_base; addrinfo != NULL; addrinfo = addrinfo->ai_next)
+    {
+      int i;
 
-  if (bind (listen_desc, (struct sockaddr *) &sockaddr, sizeof (sockaddr))
-      || listen (listen_desc, 1))
-    perror_with_name ("Can't bind address");
+printf("ai_family=%d,ai_socktype=%d\n",addrinfo->ai_family,addrinfo->ai_socktype);
+      listen_desc = socket (addrinfo->ai_family, addrinfo->ai_socktype,
+			    addrinfo->ai_protocol);
+      if (listen_desc == -1)
+	{
+	  if (addrinfo->ai_next != NULL)
+	    continue;
+	  perror_with_name ("Can't open socket");
+	}
+
+      /* Allow rapid reuse of this port. */
+      i = 1;
+      setsockopt (listen_desc, SOL_SOCKET, SO_REUSEADDR, &i, sizeof (i));
+
+      if (bind (listen_desc, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0
+	  || listen (listen_desc, 1) != 0)
+	{
+	  if (addrinfo->ai_next != NULL)
+	    {
+	      close (listen_desc);
+	      continue;
+	    }
+	  perror_with_name ("Can't bind address");
+	}
+      break;
+    }
 
   transport_is_reliable = 1;
 }
@@ -288,11 +317,11 @@ remote_prepare (char *name)
    NAME is the filename used for communication.  */
 
 void
-remote_open (char *name)
+remote_open (const char *name)
 {
-  char *port_str;
+  const char *port_str;
 
-  port_str = strchr (name, ':');
+  port_str = strrchr (name, ':');
 #ifdef USE_WIN32API
   if (port_str == NULL)
     error ("Only <host>:<port> is supported on this platform.");
diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h
index 139cd49..664b997 100644
--- a/gdb/gdbserver/server.h
+++ b/gdb/gdbserver/server.h
@@ -289,8 +289,8 @@ int putpkt (char *buf);
 int putpkt_binary (char *buf, int len);
 int putpkt_notif (char *buf);
 int getpkt (char *buf);
-void remote_prepare (char *name);
-void remote_open (char *name);
+void remote_prepare (const char *name);
+void remote_open (const char *name);
 void remote_close (void);
 void write_ok (char *buf);
 void write_enn (char *buf);
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 03db465..58877d9 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -150,77 +150,39 @@ wait_for_connect (struct serial *scb, unsigned int *polls)
   return n;
 }
 
-/* Open a tcp socket.  */
+/* make_cleanup stub for net_close.  */
 
-int
-net_open (struct serial *scb, const char *name)
+static void
+net_close_cleanup (void *arg)
+{
+  struct serial *scb = arg;
+
+  net_close (scb);
+}
+
+/* Create socket and connect it to ADDRINFO.  On return SCB->FD is -1 on error
+   (and errno is set) or SCB->FD is a connected file descriptor.  */
+
+static void
+scb_connect (struct serial *scb, const struct addrinfo *addrinfo)
 {
-  char *port_str, hostname[100];
-  int n, port, tmp;
-  struct addrinfo hints;
-  struct addrinfo *addrinfo_base, *addrinfo = NULL;
 #ifdef USE_WIN32API
   u_long ioarg;
 #else
   int ioarg;
 #endif
-  unsigned int polls = 0, retval = -1;
-  struct cleanup *back_to;
-
-  memset (&hints, 0, sizeof hints);
-  hints.ai_family = AF_UNSPEC;
-  hints.ai_flags = AI_ADDRCONFIG;
-  hints.ai_socktype = SOCK_STREAM;
-  if (strncmp (name, "udp:", 4) == 0)
-    {
-      hints.ai_socktype = SOCK_DGRAM;
-      name = name + 4;
-    }
-  else if (strncmp (name, "tcp:", 4) == 0)
-    name = name + 4;
+  int n, tmp;
+  unsigned int polls = 0;
+  struct cleanup *scb_cleanup;
 
-  port_str = strchr (name, ':');
+  gdb_assert (scb->fd == -1);
 
-  if (!port_str)
-    error (_("net_open: No colon in host name!"));  /* Shouldn't ever
-						       happen.  */
-
-  tmp = min (port_str - name, (int) sizeof hostname - 1);
-  strncpy (hostname, name, tmp);	/* Don't want colon.  */
-  hostname[tmp] = '\000';	/* Tie off host name.  */
-  port = atoi (port_str + 1);
-
-  /* Default hostname is localhost.  */
-  if (!hostname[0])
-    strcpy (hostname, "localhost");
-
-  if (getaddrinfo (hostname, port_str, &hints, &addrinfo_base) != 0)
-    {
-      fprintf_unfiltered (gdb_stderr, _("%s:%s: cannot resolve: %s\n"),
-			  hostname, port_str, gai_strerror (n));
-      errno = ENOENT;
-      return -1;
-    }
-
-  assert (addrinfo_base != NULL);
-  back_to = make_cleanup_freeaddrinfo (addrinfo_base);
-
- retry:
+  scb->fd = socket (addrinfo->ai_family, addrinfo->ai_socktype,
+		    addrinfo->ai_protocol);
+  if (scb->fd == -1)
+    return;
 
-  for (addrinfo = addrinfo_base; addrinfo != NULL; addrinfo = addrinfo->ai_next)
-    {
-      scb->fd = socket (addrinfo->ai_family, addrinfo->ai_socktype,
-			addrinfo->ai_protocol);
-      if (scb->fd >= 0)
-	break;
-    }
-  if (addrinfo == NULL)
-    {
-      fprintf_unfiltered (gdb_stderr, "%s:%s: cannot create socket: %s\n",
-			  hostname, port_str, safe_strerror (errno));
-      do_cleanups (back_to);
-      return -1;
-    }
+  scb_cleanup = make_cleanup (net_close_cleanup, scb);
 


hooks/post-receive
--
Repository for Project Archer.


             reply	other threads:[~2013-04-15 20:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-15 20:10 jkratoch [this message]
2013-04-18 20:00 jkratoch
2013-04-19 18:43 jkratoch
2013-04-22 19:36 jkratoch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130415201059.18583.qmail@sourceware.org \
    --to=jkratoch@sourceware.org \
    --cc=archer-commits@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).