proper shutdown
[oweals/gnunet.git] / src / util / client.c
index 257a69b5a82e8c25bdd8e64073797c5d79658b7d..7e688059044211cebf40dcea045f51534252b4a0 100644 (file)
@@ -43,7 +43,6 @@
  */
 #define MAX_ATTEMPTS 50
 
-
 /**
  * Handle for a transmission request.
  */
@@ -272,6 +271,7 @@ do_connect (const char *service_name,
   char *unixpath;
   unsigned long long port;
 
+  sock = NULL;
 #if AF_UNIX
   if (0 == (attempt % 2))
     {
@@ -280,14 +280,19 @@ do_connect (const char *service_name,
          GNUNET_CONFIGURATION_get_value_string (cfg,
                                                 service_name,
                                                 "UNIXPATH", &unixpath)) &&
-          (0 < strlen (unixpath)))
+          (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */
        {
-         sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg,
-                                                                   unixpath);
-         GNUNET_free (unixpath);
+          sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath);
          if (sock != NULL)
-           return sock;
+           {
+#if DEBUG_CLIENT
+              GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n", unixpath);
+#endif
+              GNUNET_free(unixpath);
+              return sock;
+           }
        }
+      GNUNET_free_non_null (unixpath);
     }
 #endif
 
@@ -303,8 +308,7 @@ do_connect (const char *service_name,
                                               "HOSTNAME", &hostname)))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _
-                  ("Could not determine valid hostname and port for service `%s' from configuration.\n"),
+                  _("Could not determine valid hostname and port for service `%s' from configuration.\n"),
                   service_name);
       return NULL;
     }
@@ -332,12 +336,19 @@ do_connect (const char *service_name,
                                                                        unixpath);
              GNUNET_free (unixpath);
              if (sock != NULL)
-               return sock;
+               return sock;            
            }
        }
 #endif
+#if DEBUG_CLIENT
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+                 "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n",
+                 service_name);
+#endif
+      GNUNET_free (hostname);
       return NULL;
     }
+
   sock = GNUNET_CONNECTION_create_from_connect (cfg,
                                                 hostname,
                                                 port);
@@ -480,6 +491,9 @@ receive_helper (void *cls,
   if ((available == 0) || (conn->sock == NULL) || (errCode != 0))
     {
       /* signal timeout! */
+#if DEBUG_CLIENT
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "timeout in receive_helper, available %d, conn->sock %s, errCode %d\n", available, conn->sock == NULL ? "NULL" : "non-NULL", errCode);
+#endif
       if (NULL != (receive_handler = conn->receiver_handler))
         {
           receive_handler_cls = conn->receiver_handler_cls;
@@ -586,6 +600,9 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
     {
       GNUNET_assert (sock->in_receive == GNUNET_NO);
       sock->in_receive = GNUNET_YES;
+#if DEBUG_CLIENT
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n");
+#endif
       GNUNET_CONNECTION_receive (sock->sock,
                                  GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
                                  timeout, &receive_helper, sock);