gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10015 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r10015 - gnunet/src/util
Date: Fri, 15 Jan 2010 17:36:30 +0100

Author: grothoff
Date: 2010-01-15 17:36:30 +0100 (Fri, 15 Jan 2010)
New Revision: 10015

Modified:
   gnunet/src/util/server.c
   gnunet/src/util/service.c
   gnunet/src/util/test_client.c
   gnunet/src/util/test_server.c
   gnunet/src/util/test_server_disconnect.c
   gnunet/src/util/test_server_with_client.c
   gnunet/src/util/test_service.c
Log:
making code work better with dual-stack, preparing for triple-stack

Modified: gnunet/src/util/server.c
===================================================================
--- gnunet/src/util/server.c    2010-01-15 15:24:30 UTC (rev 10014)
+++ gnunet/src/util/server.c    2010-01-15 16:36:30 UTC (rev 10015)
@@ -112,6 +112,12 @@
   void *access_cls;
 
   /**
+   * NULL-terminated array of sockets used to listen for new
+   * connections.
+   */
+  struct GNUNET_NETWORK_Handle **listen_sockets;
+
+  /**
    * After how long should an idle connection time
    * out (on write).
    */
@@ -123,12 +129,6 @@
   size_t maxbuf;
 
   /**
-   * Socket used to listen for new connections.  Set to
-   * "-1" by GNUNET_SERVER_destroy to initiate shutdown.
-   */
-  struct GNUNET_NETWORK_Handle *listen_socket;
-
-  /**
    * Task scheduled to do the listening.
    */
   GNUNET_SCHEDULER_TaskIdentifier listen_task;
@@ -265,8 +265,7 @@
 
 
 /**
- * Scheduler says our listen socket is ready.
- * Process it!
+ * Scheduler says our listen socket is ready.  Process it!
  *
  * @param cls handle to our server for which we are processing the listen
  *        socket
@@ -280,10 +279,13 @@
   struct GNUNET_CONNECTION_Handle *sock;
   struct GNUNET_SERVER_Client *client;
   struct GNUNET_NETWORK_FDSet *r;
+  unsigned int i;
 
   server->listen_task = GNUNET_SCHEDULER_NO_TASK;
   r = GNUNET_NETWORK_fdset_create ();
-  GNUNET_NETWORK_fdset_set (r, server->listen_socket);
+  i = 0;
+  while (NULL != server->listen_sockets[i])
+    GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]);
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     {
       /* ignore shutdown, someone else will take care of it! */
@@ -297,27 +299,33 @@
       GNUNET_NETWORK_fdset_destroy (r);
       return;                   
     }
-  GNUNET_assert (GNUNET_NETWORK_fdset_isset
-                 (tc->read_ready, server->listen_socket));
-  sock =
-    GNUNET_CONNECTION_create_from_accept (tc->sched, server->access,
-                                          server->access_cls,
-                                          server->listen_socket,
-                                          server->maxbuf);
-  if (sock != NULL)
+  i = 0;
+  while (NULL != server->listen_sockets[i])
     {
+      if (GNUNET_NETWORK_fdset_isset (tc->read_ready, 
server->listen_sockets[i]))
+       {
+         sock =
+           GNUNET_CONNECTION_create_from_accept (tc->sched, server->access,
+                                                 server->access_cls,
+                                                 server->listen_sockets[i],
+                                                 server->maxbuf);
+         if (sock != NULL)
+           {
 #if DEBUG_SERVER
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Server accepted incoming connection.\n");
+             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                         "Server accepted incoming connection.\n");
 #endif
-      client = GNUNET_SERVER_connect_socket (server, sock);
-      GNUNET_CONNECTION_ignore_shutdown (sock, 
server->clients_ignore_shutdown);
-      /* decrement reference count, we don't keep "client" alive */
-      GNUNET_SERVER_client_drop (client);
-    }  
+             client = GNUNET_SERVER_connect_socket (server, sock);
+             GNUNET_CONNECTION_ignore_shutdown (sock, 
server->clients_ignore_shutdown);
+             /* decrement reference count, we don't keep "client" alive */
+             GNUNET_SERVER_client_drop (client);
+           }  
+       }
+      i++;
+    }
   /* listen for more! */
   server->listen_task = GNUNET_SCHEDULER_add_select (server->sched,
-                                                     
GNUNET_SCHEDULER_PRIORITY_HIGH,
+                                                    
GNUNET_SCHEDULER_PRIORITY_HIGH,
                                                      GNUNET_SCHEDULER_NO_TASK,
                                                      
GNUNET_TIME_UNIT_FOREVER_REL,
                                                      r, NULL,
@@ -338,6 +346,7 @@
   const static int on = 1;
   struct GNUNET_NETWORK_Handle *sock;
   uint16_t port;
+  int eno;
 
   switch (serverAddr->sa_family)
     {
@@ -348,39 +357,55 @@
       port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port);
       break;
     default:
-      GNUNET_break (0);
-      return NULL;
+      port = 0;
+      break;
     }
   sock = GNUNET_NETWORK_socket_create (serverAddr->sa_family, SOCK_STREAM, 0);
   if (NULL == sock)
     {
       GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
+      errno = 0;
       return NULL;
-    }
-  if (GNUNET_NETWORK_socket_setsockopt
-      (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
+    } 
+  if ( (port != 0) &&
+       (GNUNET_NETWORK_socket_setsockopt
+       (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
-                         "setsockopt");
+                        "setsockopt");
   /* bind the socket */
   if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK)
     {
-      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  _
-                  ("`%s' failed for port %d. Is the service already 
running?\n"),
-                  "bind", port);
+      eno = errno;
+      if (errno != EADDRINUSE)
+       {
+         /* we don't log 'EADDRINUSE' here since an IPv4 bind may
+            fail if we already took the port on IPv6; if both IPv4 and
+            IPv6 binds fail, then our caller will log using the
+            errno preserved in 'eno' */
+         GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+         if (port != 0)
+           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                       _
+                       ("`%s' failed for port %d (%s).\n"),
+                       "bind", port,
+                       (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
+         eno = 0;
+       }
       GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+      errno = eno;
       return NULL;
     }
   if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
     {
       GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
       GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+      errno = 0;
       return NULL;
     }
 #if DEBUG_SERVER
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Server starts to listen on port %u.\n", port);
+  if (port != 0)
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "Server starts to listen on port %u.\n", port);
 #endif
   return sock;
 }
@@ -392,8 +417,7 @@
  * @param sched scheduler to use
  * @param access function for access control
  * @param access_cls closure for access
- * @param serverAddr address to listen on (including port), use NULL
- *        for internal server (no listening)
+ * @param serverAddr address to listen on (including port), NULL terminated 
array
  * @param socklen length of serverAddr
  * @param maxbuf maximum write buffer size for accepted sockets
  * @param idle_timeout after how long should we timeout idle connections?
@@ -406,35 +430,61 @@
 GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched,
                       GNUNET_CONNECTION_AccessCheck access,
                       void *access_cls,
-                      const struct sockaddr *serverAddr,
-                      socklen_t socklen,
+                     struct sockaddr *const *serverAddr,
+                      const socklen_t *socklen,
                       size_t maxbuf,
                       struct GNUNET_TIME_Relative
-                      idle_timeout, int require_found)
+                      idle_timeout, 
+                     int require_found)
 {
   struct GNUNET_SERVER_Handle *ret;
-  struct GNUNET_NETWORK_Handle *lsock;
+  struct GNUNET_NETWORK_Handle **lsocks;
   struct GNUNET_NETWORK_FDSet *r;
+  unsigned int i;
+  unsigned int j;
 
-  lsock = NULL;
-  if (serverAddr != NULL)
+  i = 0;
+  while (serverAddr[i] != NULL)
+    i++;
+  if (i > 0)
     {
-      lsock = open_listen_socket (serverAddr, socklen);
-      if (lsock == NULL)
-        return NULL;
+      lsocks = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle*) * (i+1));
+      i = 0;
+      j = 0;
+      while (serverAddr[i] != NULL)
+       {
+         lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]);
+         if (lsocks[j] != NULL)
+           j++;
+         i++;
+       }
+      if (j == 0)
+       {
+         if (errno != 0)
+           GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+         GNUNET_free (lsocks);
+         lsocks = NULL;
+       }
     }
+  else
+    {
+      lsocks = NULL;
+    }
   ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle));
   ret->sched = sched;
   ret->maxbuf = maxbuf;
   ret->idle_timeout = idle_timeout;
-  ret->listen_socket = lsock;
+  ret->listen_sockets = lsocks;
   ret->access = access;
   ret->access_cls = access_cls;
   ret->require_found = require_found;
-  if (lsock != NULL)
+  if (lsocks != NULL)
     {
+      
       r = GNUNET_NETWORK_fdset_create ();
-      GNUNET_NETWORK_fdset_set (r, ret->listen_socket);
+      i = 0;
+      while (NULL != ret->listen_sockets[i])
+       GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]);
       ret->listen_task = GNUNET_SCHEDULER_add_select (sched,
                                                       
GNUNET_SCHEDULER_PRIORITY_HIGH,
                                                       GNUNET_SCHEDULER_NO_TASK,
@@ -457,6 +507,7 @@
   struct GNUNET_SERVER_Client *pos;
   struct HandlerList *hpos;
   struct NotifyList *npos;
+  unsigned int i;
 
 #if DEBUG_SERVER
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n");
@@ -466,8 +517,14 @@
       GNUNET_SCHEDULER_cancel (s->sched, s->listen_task);
       s->listen_task = GNUNET_SCHEDULER_NO_TASK;
     }
-  GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s->listen_socket));
-  s->listen_socket = NULL;
+  if (s->listen_sockets != NULL)
+    {
+      i = 0;
+      while (s->listen_sockets[i] != NULL)
+       GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close 
(s->listen_sockets[i++]));
+      GNUNET_free (s->listen_sockets);
+      s->listen_sockets = NULL;
+    }
   while (s->clients != NULL)
     {
       pos = s->clients;

Modified: gnunet/src/util/service.c
===================================================================
--- gnunet/src/util/service.c   2010-01-15 15:24:30 UTC (rev 10014)
+++ gnunet/src/util/service.c   2010-01-15 16:36:30 UTC (rev 10015)
@@ -35,6 +35,8 @@
 #include "gnunet_server_lib.h"
 #include "gnunet_service_lib.h"
 
+#define DEBUG_SERVICE GNUNET_NO
+
 /* ******************* access control ******************** */
 
 /**
@@ -433,9 +435,9 @@
   struct GNUNET_SCHEDULER_Handle *sched;
 
   /**
-   * Address to bind to.
+   * NULL-terminated array of addresses to bind to.
    */
-  struct sockaddr *addr;
+  struct sockaddr **addrs;
 
   /**
    * Name of our service.
@@ -519,9 +521,9 @@
   enum GNUNET_SERVICE_Options options;
 
   /**
-   * Length of addr.
+   * Array of the lengths of the entries in addrs.
    */
-  socklen_t addrlen;
+  socklen_t * addrlens;
 
 };
 
@@ -766,8 +768,10 @@
   struct addrinfo hints;
   struct addrinfo *res;
   struct addrinfo *pos;
+  struct addrinfo *next;
   int ret;
   int tolerant;
+  unsigned int i;
   struct GNUNET_NETWORK_Handle *desc;
 
   if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
@@ -884,6 +888,12 @@
 
   if (hostname != NULL)
     {
+#if DEBUG_SERVICE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Resolving `%s' since that is where `%s' will bind to.\n",
+                 hostname,
+                 sctx->serviceName);
+#endif
       memset (&hints, 0, sizeof (struct addrinfo));
       if (disablev6)
         hints.ai_family = AF_INET;
@@ -896,13 +906,16 @@
           GNUNET_free (hostname);
           return GNUNET_SYSERR;
         }
-      pos = res;
-      while ((NULL != pos) &&
-             (((disablev6) &&
-               (pos->ai_family != AF_INET)) ||
-              ((pos->ai_family != AF_INET) && (pos->ai_family != AF_INET6))))
-        pos = pos->ai_next;
-      if (pos == NULL)
+      next = res;
+      i = 0;
+      while (NULL != (pos = next)) 
+       {
+         next = pos->ai_next;
+         if ( (disablev6) && (pos->ai_family == AF_INET6))
+           continue;
+         i++;
+       }
+      if (0 == i)
         {
           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                       _("Failed to find %saddress for `%s'.\n"),
@@ -911,32 +924,42 @@
           GNUNET_free (hostname);
           return GNUNET_SYSERR;
         }
+      sctx->addrs = GNUNET_malloc ((i+1) * sizeof(struct sockaddr*));
+      sctx->addrlens = GNUNET_malloc ((i+1) * sizeof (socklen_t));
+      i = 0;
+      next = res;
+      while (NULL != (pos = next)) 
+       {
+         next = pos->ai_next;
+         if ( (disablev6) && (pos->ai_family == AF_INET6))
+           continue;
+#if DEBUG_SERVICE
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                     "Service `%s' will bind to `%s'\n",
+                     sctx->serviceName,
+                     GNUNET_a2s (pos->ai_addr,
+                                 pos->ai_addrlen));
+#endif
+         if (pos->ai_family == AF_INET)
+           {
+             GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
+             sctx->addrlens[i] = pos->ai_addrlen;
+             sctx->addrs[i] = GNUNET_malloc (sctx->addrlens[i]);
+             memcpy (sctx->addrs[i], pos->ai_addr, sctx->addrlens[i]);
+             ((struct sockaddr_in *) sctx->addrs[i])->sin_port = htons (port);
+           }
+         else
+           {
+             GNUNET_assert (pos->ai_family == AF_INET6);
+             GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
+             sctx->addrlens[i] = pos->ai_addrlen;
+             sctx->addrs[i] = GNUNET_malloc (sctx->addrlens[i]);
+             memcpy (sctx->addrs[i], pos->ai_addr, sctx->addrlens[i]);
+             ((struct sockaddr_in6 *) sctx->addrs[i])->sin6_port = htons 
(port);
+           }     
+         i++;
+       }
       GNUNET_free (hostname);
-      if (pos->ai_family == AF_INET)
-        {
-          GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
-          sctx->addrlen = pos->ai_addrlen;
-          sctx->addr = GNUNET_malloc (sctx->addrlen);
-          memcpy (sctx->addr, res->ai_addr, sctx->addrlen);
-          ((struct sockaddr_in *) sctx->addr)->sin_port = htons (port);
-          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                      _
-                      ("Configured to bind to %s address; %s connections to 
this service will fail!\n"),
-                      "IPv4", "IPv6");
-        }
-      else
-        {
-          GNUNET_assert (pos->ai_family == AF_INET6);
-          GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
-          sctx->addrlen = pos->ai_addrlen;
-          sctx->addr = GNUNET_malloc (sctx->addrlen);
-          memcpy (sctx->addr, res->ai_addr, sctx->addrlen);
-          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                      _
-                      ("Configured to bind to %s address; %s connections to 
this service will fail!\n"),
-                      "IPv6", "IPv4");
-          ((struct sockaddr_in6 *) sctx->addr)->sin6_port = htons (port);
-        }
       freeaddrinfo (res);
     }
   else
@@ -945,28 +968,38 @@
       if (disablev6)
         {
           /* V4-only */
-          sctx->addrlen = sizeof (struct sockaddr_in);
-          sctx->addr = GNUNET_malloc (sctx->addrlen);
+         sctx->addrs = GNUNET_malloc (2 * sizeof(struct sockaddr*));
+         sctx->addrlens = GNUNET_malloc (2 * sizeof (socklen_t));
+          sctx->addrlens[0] = sizeof (struct sockaddr_in);
+          sctx->addrs[0] = GNUNET_malloc (sctx->addrlens[0]);
 #if HAVE_SOCKADDR_IN_SIN_LEN
-          ((struct sockaddr_in *) sctx->addr)->sin_len = sctx->addrlen;
+          ((struct sockaddr_in *) sctx->addrs[0])->sin_len = sctx->addrlens[0];
 #endif
-          ((struct sockaddr_in *) sctx->addr)->sin_family = AF_INET;
-          ((struct sockaddr_in *) sctx->addr)->sin_port = htons (port);
-          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                      _
-                      ("Configured to bind to %s address; %s connections to 
this service will fail!\n"),
-                      "IPv4", "IPv6");
+          ((struct sockaddr_in *) sctx->addrs[0])->sin_family = AF_INET;
+          ((struct sockaddr_in *) sctx->addrs[0])->sin_port = htons (port);
         }
       else
         {
           /* dual stack */
-          sctx->addrlen = sizeof (struct sockaddr_in6);
-          sctx->addr = GNUNET_malloc (sctx->addrlen);
+         sctx->addrs = GNUNET_malloc (3 * sizeof(struct sockaddr*));
+         sctx->addrlens = GNUNET_malloc (3 * sizeof (socklen_t));
+
+          sctx->addrlens[0] = sizeof (struct sockaddr_in6);
+          sctx->addrs[0] = GNUNET_malloc (sctx->addrlens[0]);
 #if HAVE_SOCKADDR_IN_SIN_LEN
-          ((struct sockaddr_in6 *) sctx->addr)->sin6_len = sctx->addrlen;
+          ((struct sockaddr_in6 *) sctx->addrs[0])->sin6_len = 
sctx->addrlen[0];
 #endif
-          ((struct sockaddr_in6 *) sctx->addr)->sin6_family = AF_INET6;
-          ((struct sockaddr_in6 *) sctx->addr)->sin6_port = htons (port);
+          ((struct sockaddr_in6 *) sctx->addrs[0])->sin6_family = AF_INET6;
+          ((struct sockaddr_in6 *) sctx->addrs[0])->sin6_port = htons (port);
+
+          sctx->addrlens[1] = sizeof (struct sockaddr_in);
+          sctx->addrs[1] = GNUNET_malloc (sctx->addrlens[1]);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+          ((struct sockaddr_in *) sctx->addrs[1])->sin_len = sctx->addrlens[1];
+#endif
+          ((struct sockaddr_in *) sctx->addrs[1])->sin_family = AF_INET;
+          ((struct sockaddr_in *) sctx->addrs[1])->sin_port = htons (port);
+
         }
     }
   sctx->maxbuf = (size_t) maxbuf;
@@ -1090,15 +1123,21 @@
   sctx->server = GNUNET_SERVER_create (tc->sched,
                                        &check_access,
                                        sctx,
-                                       sctx->addr,
-                                       sctx->addrlen,
+                                       sctx->addrs,
+                                       sctx->addrlens,
                                        sctx->maxbuf,
                                        sctx->timeout, sctx->require_found);
   if (sctx->server == NULL)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  _("Failed to start `%s' at `%s'\n"),
-                  sctx->serviceName, GNUNET_a2s (sctx->addr, sctx->addrlen));
+      i = 0;
+      while (sctx->addrs[i] != NULL)
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                     _("Failed to start `%s' at `%s'\n"),
+                     sctx->serviceName, 
+                     GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
+         i++;
+       }
       sctx->ret = GNUNET_SYSERR;
       return;
     }
@@ -1123,9 +1162,15 @@
       sctx->ready_confirm_fd = -1;
       write_pid_file (sctx, getpid ());
     }
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              _("Service `%s' runs at %s\n"),
-              sctx->serviceName, GNUNET_a2s (sctx->addr, sctx->addrlen));
+  i = 0;
+  while (sctx->addrs[i] != NULL)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                 _("Service `%s' runs at %s\n"),
+                 sctx->serviceName, 
+                 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
+      i++;
+    }
   sctx->task (sctx->task_cls, tc->sched, sctx->server, sctx->cfg);
 }
 
@@ -1295,6 +1340,7 @@
   char *loglev;
   char *logfile;
   int do_daemonize;
+  unsigned int i;
   struct GNUNET_SERVICE_Context sctx;
   struct GNUNET_CONFIGURATION_Handle *cfg;
   struct GNUNET_GETOPT_CommandLineOption service_options[] = {
@@ -1358,7 +1404,11 @@
     }
 
   GNUNET_CONFIGURATION_destroy (cfg);
-  GNUNET_free_non_null (sctx.addr);
+  i = 0;
+  while (sctx.addrs[i] != NULL)    
+    GNUNET_free (sctx.addrs[i++]);    
+  GNUNET_free_non_null (sctx.addrs);
+  GNUNET_free_non_null (sctx.addrlens);
   GNUNET_free_non_null (logfile);
   GNUNET_free (loglev);
   GNUNET_free (cfg_fn);
@@ -1402,8 +1452,8 @@
       (NULL == (sctx->server = GNUNET_SERVER_create (sched,
                                                      &check_access,
                                                      sctx,
-                                                     sctx->addr,
-                                                     sctx->addrlen,
+                                                     sctx->addrs,
+                                                     sctx->addrlens,
                                                      sctx->maxbuf,
                                                      sctx->timeout,
                                                      sctx->require_found))))
@@ -1442,10 +1492,15 @@
 void
 GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx)
 {
+  unsigned int i;
   if (NULL != sctx->server)
     GNUNET_SERVER_destroy (sctx->server);
   GNUNET_free_non_null (sctx->my_handlers);
-  GNUNET_free_non_null (sctx->addr);
+  i = 0;
+  while (sctx->addrs[i] != NULL)    
+    GNUNET_free (sctx->addrs[i++]);    
+  GNUNET_free_non_null (sctx->addrs);
+  GNUNET_free_non_null (sctx->addrlens);
   GNUNET_free_non_null (sctx->v4_denied);
   GNUNET_free_non_null (sctx->v6_denied);
   GNUNET_free_non_null (sctx->v4_allowed);

Modified: gnunet/src/util/test_client.c
===================================================================
--- gnunet/src/util/test_client.c       2010-01-15 15:24:30 UTC (rev 10014)
+++ gnunet/src/util/test_client.c       2010-01-15 16:36:30 UTC (rev 10015)
@@ -137,7 +137,13 @@
 task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct sockaddr_in sa;
+  struct sockaddr * sap[2];
+  socklen_t slens[2];
 
+  sap[0] = (struct sockaddr*) &sa;
+  slens[0] = sizeof (sa);
+  sap[1] = NULL;
+  slens[1] = 0;
   memset (&sa, 0, sizeof (sa));
 #if HAVE_SOCKADDR_IN_SIN_LEN
   sa.sin_len = sizeof (sa);
@@ -147,8 +153,8 @@
   server = GNUNET_SERVER_create (tc->sched,
                                  NULL,
                                  NULL,
-                                 (const struct sockaddr *) &sa,
-                                 sizeof (sa),
+                                 sap,
+                                slens,
                                  1024,
                                  GNUNET_TIME_relative_multiply
                                  (GNUNET_TIME_UNIT_MILLISECONDS, 10000),

Modified: gnunet/src/util/test_server.c
===================================================================
--- gnunet/src/util/test_server.c       2010-01-15 15:24:30 UTC (rev 10014)
+++ gnunet/src/util/test_server.c       2010-01-15 16:36:30 UTC (rev 10015)
@@ -232,7 +232,13 @@
 {
   struct sockaddr_in sa;
   struct GNUNET_MessageHeader msg;
+  struct sockaddr * sap[2];
+  socklen_t slens[2];
 
+  sap[0] = (struct sockaddr*) &sa;
+  slens[0] = sizeof (sa);
+  sap[1] = NULL;
+  slens[1] = 0;
   sched = tc->sched;
   memset (&sa, 0, sizeof (sa));
 #if HAVE_SOCKADDR_IN_SIN_LEN
@@ -243,8 +249,8 @@
   server = GNUNET_SERVER_create (tc->sched,
                                  NULL,
                                  NULL,
-                                 (const struct sockaddr *) &sa,
-                                 sizeof (sa),
+                                 sap,
+                                slens,
                                  1024,
                                  GNUNET_TIME_relative_multiply
                                  (GNUNET_TIME_UNIT_MILLISECONDS, 250),

Modified: gnunet/src/util/test_server_disconnect.c
===================================================================
--- gnunet/src/util/test_server_disconnect.c    2010-01-15 15:24:30 UTC (rev 
10014)
+++ gnunet/src/util/test_server_disconnect.c    2010-01-15 16:36:30 UTC (rev 
10015)
@@ -174,7 +174,13 @@
 task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct sockaddr_in sa;
+  struct sockaddr * sap[2];
+  socklen_t slens[2];
 
+  sap[0] = (struct sockaddr*) &sa;
+  slens[0] = sizeof (sa);
+  sap[1] = NULL;
+  slens[1] = 0;
   sched = tc->sched;
   memset (&sa, 0, sizeof (sa));
 #if HAVE_SOCKADDR_IN_SIN_LEN
@@ -185,8 +191,8 @@
   server = GNUNET_SERVER_create (tc->sched,
                                  NULL,
                                  NULL,
-                                 (const struct sockaddr *) &sa,
-                                 sizeof (sa),
+                                 sap,
+                                slens,
                                  1024,
                                  GNUNET_TIME_relative_multiply
                                  (GNUNET_TIME_UNIT_MILLISECONDS, 250),

Modified: gnunet/src/util/test_server_with_client.c
===================================================================
--- gnunet/src/util/test_server_with_client.c   2010-01-15 15:24:30 UTC (rev 
10014)
+++ gnunet/src/util/test_server_with_client.c   2010-01-15 16:36:30 UTC (rev 
10015)
@@ -158,7 +158,13 @@
 task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct sockaddr_in sa;
+  struct sockaddr * sap[2];
+  socklen_t slens[2];
 
+  sap[0] = (struct sockaddr*) &sa;
+  slens[0] = sizeof (sa);
+  sap[1] = NULL;
+  slens[1] = 0;
   sched = tc->sched;
   memset (&sa, 0, sizeof (sa));
 #if HAVE_SOCKADDR_IN_SIN_LEN
@@ -169,8 +175,8 @@
   server = GNUNET_SERVER_create (tc->sched,
                                  NULL,
                                  NULL,
-                                 (const struct sockaddr *) &sa,
-                                 sizeof (sa),
+                                 sap,
+                                slens,
                                  1024,
                                  GNUNET_TIME_relative_multiply
                                  (GNUNET_TIME_UNIT_MILLISECONDS, 250),

Modified: gnunet/src/util/test_service.c
===================================================================
--- gnunet/src/util/test_service.c      2010-01-15 15:24:30 UTC (rev 10014)
+++ gnunet/src/util/test_service.c      2010-01-15 16:36:30 UTC (rev 10015)
@@ -76,15 +76,16 @@
   return sizeof (struct GNUNET_MessageHeader);
 }
 
+
 static void
 ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
   struct GNUNET_CLIENT_Connection *client;
 
+  GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service confirmed running\n");
   sched = tc->sched;
-  GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
   client = GNUNET_CLIENT_connect (tc->sched, "test_service", cfg);
   GNUNET_assert (client != NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,





reply via email to

[Prev in Thread] Current Thread [Next in Thread]