-handle timeout better
authorChristian Grothoff <christian@grothoff.org>
Wed, 25 Apr 2012 14:45:39 +0000 (14:45 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 25 Apr 2012 14:45:39 +0000 (14:45 +0000)
src/util/test_service.c

index cd73ceee44225815b40c3b47f078b2acb61f0541..92aefc63f942193deb81ae92bf506c46f2297791 100644 (file)
@@ -44,11 +44,31 @@ static int ok = 1;
 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;
+}
+
+
 static size_t
 build_msg (void *cls, size_t size, void *buf)
 {
   struct GNUNET_MessageHeader *msg = buf;
 
+  if (size < sizeof (struct GNUNET_MessageHeader))
+  {
+    /* timeout */
+    GNUNET_SCHEDULER_add_now (&do_stop, NULL);
+    ok = 1;
+    return 0;
+  }
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected, transmitting\n");
   GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
   msg->type = htons (MY_TYPE);
@@ -75,14 +95,6 @@ ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 
-static void
-do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  GNUNET_CLIENT_disconnect (client);
-  GNUNET_SERVICE_stop (sctx);
-}
-
-
 static void
 recv_cb (void *cls, struct GNUNET_SERVER_Client *sc,
          const struct GNUNET_MessageHeader *message)