-cleaning up client api to test for service availability
[oweals/gnunet.git] / src / arm / arm_monitor_api.c
index 685f1c334c0f4af2d3089c96c7199a0a982dce95..f8d41e7908f0161c0519e36cfa222fbc2ed0321e 100644 (file)
@@ -156,6 +156,7 @@ init_timeout_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Init message timed out\n");
 
+  h->init_timeout_task_id = GNUNET_SCHEDULER_NO_TASK;
   reconnect_arm_monitor_later (h);
 }
 
@@ -221,7 +222,7 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h)
     LOG (GNUNET_ERROR_TYPE_DEBUG,
           "arm_api, GNUNET_CLIENT_connect returned NULL\n");
     if (NULL != h->service_status)
-      h->service_status (h->cls, h, NULL, GNUNET_ARM_SERVICE_STOPPED);
+      h->service_status (h->cls, NULL, GNUNET_ARM_SERVICE_STOPPED);
     return GNUNET_SYSERR;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -268,7 +269,6 @@ GNUNET_ARM_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg,
 
 /**
  * Disconnect from the ARM service (if connected) and destroy the context.
- * Don't call inside a callback!
  *
  * @param h the handle that was being used
  */
@@ -345,15 +345,15 @@ monitor_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
          "Received response from ARM for service `%s': %u\n",
          (const char *) &res[1], ntohs (msg->type));
     status = (enum GNUNET_ARM_ServiceStatus) ntohl (res->status);
-    if ((NULL != h->service_status))
-      h->service_status (h->cls, h, (const char *) &res[1], status);
+    GNUNET_CLIENT_receive (h->monitor, &monitor_notify_handler, h,
+                           GNUNET_TIME_UNIT_FOREVER_REL);
+    if (NULL != h->service_status)
+      h->service_status (h->cls, (const char *) &res[1], status);
     break;
   default:
     reconnect_arm_monitor_later (h);
     return;
   }
-  GNUNET_CLIENT_receive (h->monitor, &monitor_notify_handler, h,
-      GNUNET_TIME_UNIT_FOREVER_REL);
 }