handling replies continuously from server
[oweals/gnunet.git] / src / util / test_service.c
index 92aefc63f942193deb81ae92bf506c46f2297791..55472497210227a89b57f4657ed0c16a00ed01b1 100644 (file)
@@ -49,10 +49,20 @@ static struct GNUNET_CLIENT_Connection *client;
 static void
 do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_CLIENT_disconnect (client);
-  client = NULL;
-  GNUNET_SERVICE_stop (sctx);
-  sctx = NULL;
+  if (NULL != client)
+  {
+    GNUNET_CLIENT_disconnect (client);
+    client = NULL;
+  }
+  if (NULL != sctx)
+  {
+    GNUNET_SERVICE_stop (sctx);
+    sctx = NULL;
+  }
+  else
+  {
+    GNUNET_SCHEDULER_shutdown ();
+  }
 }
 
 
@@ -64,6 +74,7 @@ build_msg (void *cls, size_t size, void *buf)
   if (size < sizeof (struct GNUNET_MessageHeader))
   {
     /* timeout */
+    GNUNET_break (0);
     GNUNET_SCHEDULER_add_now (&do_stop, NULL);
     ok = 1;
     return 0;
@@ -99,12 +110,11 @@ static void
 recv_cb (void *cls, struct GNUNET_SERVER_Client *sc,
          const struct GNUNET_MessageHeader *message)
 {
+  if (NULL == message)
+    return;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n");
   GNUNET_SERVER_receive_done (sc, GNUNET_OK);
-  if (sctx != NULL)
-    GNUNET_SCHEDULER_add_now (&do_stop, NULL);
-  else
-    GNUNET_SCHEDULER_shutdown ();
+  GNUNET_SCHEDULER_add_now (&do_stop, NULL);
   ok = 0;
 }
 
@@ -268,7 +278,6 @@ main (int argc, char *argv[])
                     NULL);
   ret += check ();
   ret += check ();
-
   // FIXME
 #ifndef MINGW
   s = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
@@ -291,7 +300,6 @@ main (int argc, char *argv[])
     ret += check6 ();
   }
   ret += check_start_stop ();
-
   return ret;
 }