gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r26524 - in gnunet/src: arm include regex


From: gnunet
Subject: [GNUnet-SVN] r26524 - in gnunet/src: arm include regex
Date: Wed, 20 Mar 2013 19:50:19 +0100

Author: LRN
Date: 2013-03-20 19:50:18 +0100 (Wed, 20 Mar 2013)
New Revision: 26524

Modified:
   gnunet/src/arm/arm_api.c
   gnunet/src/arm/arm_monitor_api.c
   gnunet/src/arm/gnunet-arm.c
   gnunet/src/arm/test_arm_api.c
   gnunet/src/arm/test_exponential_backoff.c
   gnunet/src/arm/test_gnunet_service_arm.c
   gnunet/src/include/gnunet_arm_service.h
   gnunet/src/regex/gnunet-regex-profiler.c
Log:
Simplify ARM alloc/connect

Modified: gnunet/src/arm/arm_api.c
===================================================================
--- gnunet/src/arm/arm_api.c    2013-03-20 18:50:12 UTC (rev 26523)
+++ gnunet/src/arm/arm_api.c    2013-03-20 18:50:18 UTC (rev 26524)
@@ -176,7 +176,7 @@
 static void
 client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg);
 
-static void
+static int
 reconnect_arm (struct GNUNET_ARM_Handle *h);
 
 static void
@@ -246,7 +246,7 @@
   }
 
   if (NULL != h->conn_status)
-    h->conn_status (h->conn_status_cls, h, GNUNET_NO, GNUNET_NO);
+    h->conn_status (h->conn_status_cls, h, GNUNET_NO);
 
   h->currently_down = GNUNET_YES;
 
@@ -286,7 +286,7 @@
   {
     h->currently_down = GNUNET_NO;
     if (NULL != h->conn_status)
-      h->conn_status (h->conn_status_cls, h, GNUNET_YES, GNUNET_NO);
+      h->conn_status (h->conn_status_cls, h, GNUNET_YES);
     h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
     GNUNET_CLIENT_receive (h->client, &client_notify_handler, h,
                            GNUNET_TIME_UNIT_FOREVER_REL);
@@ -384,7 +384,7 @@
  *
  * @param h arm handle
  */
-static void
+static int
 reconnect_arm (struct GNUNET_ARM_Handle *h)
 {
   GNUNET_assert (NULL == h->client);
@@ -395,52 +395,45 @@
     LOG (GNUNET_ERROR_TYPE_DEBUG,
           "arm_api, GNUNET_CLIENT_connect returned NULL\n");
     if (NULL != h->conn_status)
-      h->conn_status (h->conn_status_cls, h, GNUNET_NO, GNUNET_YES);
-    return;
+      h->conn_status (h->conn_status_cls, h, GNUNET_SYSERR);
+    return GNUNET_SYSERR;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
         "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
   trigger_next_request (h, GNUNET_YES);
+  return GNUNET_OK;
 }
 
 
 /**
- * Set up a context for communicating with ARM.  Note that this
- * can be done even if the ARM service is not yet running.
- * Never fails.
+ * Set up a context for communicating with ARM, then
+ * start connecting to the ARM service using that context.
  *
  * @param cfg configuration to use (needed to contact ARM;
  *        the ARM service may internally use a different
  *        configuration to determine how to start the service).
- * @return context to use for further ARM operations
- */
-struct GNUNET_ARM_Handle *
-GNUNET_ARM_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  struct GNUNET_ARM_Handle *ret;
-
-  ret = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle));
-  ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
-  ret->currently_down = GNUNET_YES;
-  ret->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
-  return ret;
-}
-
-
-/**
- * Start connecting to the ARM service using the context.
- *
- * @param h ARM handle
  * @param conn_status will be called when connecting/disconnecting
  * @param cls closure for conn_status
+ * @return context to use for further ARM operations, NULL on error.
  */
-void
-GNUNET_ARM_connect (struct GNUNET_ARM_Handle *h,
+struct GNUNET_ARM_Handle *
+GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
                     GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls)
 {
+  struct GNUNET_ARM_Handle *h;
+
+  h = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle));
+  h->cfg = GNUNET_CONFIGURATION_dup (cfg);
+  h->currently_down = GNUNET_YES;
+  h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
   h->conn_status = conn_status;
   h->conn_status_cls = cls;
-  reconnect_arm (h);
+  if (GNUNET_OK != reconnect_arm (h))
+  {
+    GNUNET_free (h);
+    return NULL;
+  }
+  return h;
 }
 
 

Modified: gnunet/src/arm/arm_monitor_api.c
===================================================================
--- gnunet/src/arm/arm_monitor_api.c    2013-03-20 18:50:12 UTC (rev 26523)
+++ gnunet/src/arm/arm_monitor_api.c    2013-03-20 18:50:18 UTC (rev 26524)
@@ -88,7 +88,7 @@
 static void
 monitor_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg);
 
-static void
+static int
 reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h);
 
 /**
@@ -211,7 +211,7 @@
 }
 
 
-static void
+static int
 reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h)
 {
   GNUNET_assert (NULL == h->monitor);
@@ -220,56 +220,49 @@
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
           "arm_api, GNUNET_CLIENT_connect returned NULL\n");
-    GNUNET_CLIENT_disconnect (h->monitor);
-    h->monitor = NULL;
-    return;
+    if (NULL != h->service_status)
+      h->service_status (h->cls, h, NULL, GNUNET_ARM_SERVICE_STOPPED);
+    return GNUNET_SYSERR;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
         "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
   h->cth = GNUNET_CLIENT_notify_transmit_ready (h->monitor,
       sizeof (struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL,
       GNUNET_NO, &transmit_monitoring_init_message, h);
+  return GNUNET_OK;
 }
 
 
 /**
- * Setup a context for monitoring ARM.  Note that this
- * can be done even if the ARM service is not yet running.
- * Never fails.
+ * Setup a context for monitoring ARM, then
+ * start connecting to the ARM service for monitoring using that context.
  *
  * @param cfg configuration to use (needed to contact ARM;
  *        the ARM service may internally use a different
  *        configuration to determine how to start the service).
- * @return context to use for further ARM monitoring operations
- */
-struct GNUNET_ARM_MonitorHandle *
-GNUNET_ARM_monitor_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  struct GNUNET_ARM_MonitorHandle *ret;
-
-  ret = GNUNET_malloc (sizeof (struct GNUNET_ARM_MonitorHandle));
-  ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
-  ret->currently_down = GNUNET_YES;
-  ret->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
-  ret->init_timeout_task_id = GNUNET_SCHEDULER_NO_TASK;
-  return ret;
-}
-
-
-/**
- * Start connecting to the ARM service for monitoring using the context.
- *
- * @param h ARM monitor handle
  * @param cont callback to invoke on status updates
  * @param cont_cls closure
+ * @return context to use for further ARM monitor operations, NULL on error.
  */
-void
-GNUNET_ARM_monitor (struct GNUNET_ARM_MonitorHandle *h,
+struct GNUNET_ARM_MonitorHandle *
+GNUNET_ARM_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg,
     GNUNET_ARM_ServiceStatusCallback cont, void *cont_cls)
 {
+  struct GNUNET_ARM_MonitorHandle *h;
+
+  h = GNUNET_malloc (sizeof (struct GNUNET_ARM_MonitorHandle));
+  h->cfg = GNUNET_CONFIGURATION_dup (cfg);
+  h->currently_down = GNUNET_YES;
+  h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  h->init_timeout_task_id = GNUNET_SCHEDULER_NO_TASK;
   h->service_status = cont;
   h->cls = cont_cls;
-  reconnect_arm_monitor (h);
+  if (GNUNET_OK != reconnect_arm_monitor (h))
+  {
+    GNUNET_free (h);
+    return NULL;
+  }
+  return h;
 }
 
 
@@ -280,7 +273,7 @@
  * @param h the handle that was being used
  */
 void
-GNUNET_ARM_monitor_disconnect (struct GNUNET_ARM_MonitorHandle *handle)
+GNUNET_ARM_monitor_disconnect_and_free (struct GNUNET_ARM_MonitorHandle 
*handle)
 {
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n");
   if (NULL != handle->cth)

Modified: gnunet/src/arm/gnunet-arm.c
===================================================================
--- gnunet/src/arm/gnunet-arm.c 2013-03-20 18:50:12 UTC (rev 26523)
+++ gnunet/src/arm/gnunet-arm.c 2013-03-20 18:50:18 UTC (rev 26524)
@@ -179,7 +179,7 @@
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_ARM_disconnect_and_free (h);
-  GNUNET_ARM_monitor_disconnect (m);
+  GNUNET_ARM_monitor_disconnect_and_free (m);
   h = NULL;
   m = NULL;
   if ((end == GNUNET_YES) && (delete == GNUNET_YES))
@@ -246,14 +246,15 @@
  *
  * @param cls closure
  * @param arm handle to the ARM connection
- * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected
+ * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
+ *                  GNUNET_SYSERR on error.
  * @param error GNUNET_YES if we encountered a permanent error, and there
  *              will be no re-connection.
  */
 static void
-conn_status (void *cls, struct GNUNET_ARM_Handle *arm, unsigned char 
connected, unsigned char error)
+conn_status (void *cls, struct GNUNET_ARM_Handle *arm, char connected)
 {
-  if (GNUNET_YES == error)
+  if (GNUNET_SYSERR == connected)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Fatal error initializing ARM API.\n"));
@@ -575,13 +576,22 @@
     else
       GNUNET_free (armconfig);
   }
-  h = GNUNET_ARM_alloc (cfg);
-  m = GNUNET_ARM_monitor_alloc (cfg);
-  GNUNET_ARM_connect (h, conn_status, NULL);
-  GNUNET_ARM_monitor (m, srv_status, NULL);
-  GNUNET_SCHEDULER_add_now (action_loop, NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                               shutdown_task, NULL);
+  h = GNUNET_ARM_connect (cfg, conn_status, NULL);
+  if (NULL != h)
+  {
+    m = GNUNET_ARM_monitor (cfg, srv_status, NULL);
+    if (NULL != m)
+    {
+      GNUNET_SCHEDULER_add_now (action_loop, NULL);
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+          shutdown_task, NULL);
+    }
+    else
+    {
+      GNUNET_ARM_disconnect_and_free (h);
+      h = NULL;
+    }
+  }
 }
 
 

Modified: gnunet/src/arm/test_arm_api.c
===================================================================
--- gnunet/src/arm/test_arm_api.c       2013-03-20 18:50:12 UTC (rev 26523)
+++ gnunet/src/arm/test_arm_api.c       2013-03-20 18:50:18 UTC (rev 26524)
@@ -71,7 +71,7 @@
   GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL);
 #else
   arm_stop_cb (NULL, GNUNET_ARM_STATUS_SENT_OK, "arm", 
GNUNET_ARM_SERVICE_STOPPING);
-  arm_conn (NULL, GNUNET_NO, GNUNET_NO);
+  arm_conn (NULL, GNUNET_NO);
 #endif
 }
 
@@ -119,9 +119,9 @@
 
 
 void
-arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, unsigned char connected, 
unsigned char error)
+arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, char connected)
 {
-  if (GNUNET_YES == error)
+  if (GNUNET_SYSERR == connected)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Fatal error initializing ARM API.\n"));
@@ -129,7 +129,7 @@
     GNUNET_assert (0);
     return;
   }
-  if (connected)
+  if (GNUNET_YES == connected)
   {
     /* (1), arm connection should be established */
     FPRINTF (stderr, "%s", "Connected to ARM\n");
@@ -201,13 +201,14 @@
     else
       GNUNET_free (armconfig);
   }
-  arm = GNUNET_ARM_alloc (cfg);
-  GNUNET_ARM_connect (arm, arm_conn, NULL);
+  arm = GNUNET_ARM_connect (cfg, arm_conn, NULL);
+  if (NULL == arm)
+    return;
 #if START_ARM
   GNUNET_ARM_request_service_start (arm, "arm", 
GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL);
 #else
   arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", 
GNUNET_ARM_RESULT_STARTING);
-  arm_conn (NULL, GNUNET_YES, GNUNET_NO);
+  arm_conn (NULL, arm, GNUNET_YES);
 #endif
 }
 

Modified: gnunet/src/arm/test_exponential_backoff.c
===================================================================
--- gnunet/src/arm/test_exponential_backoff.c   2013-03-20 18:50:12 UTC (rev 
26523)
+++ gnunet/src/arm/test_exponential_backoff.c   2013-03-20 18:50:18 UTC (rev 
26524)
@@ -280,7 +280,7 @@
 trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_ARM_disconnect_and_free (arm);
-  GNUNET_ARM_monitor_disconnect (mon);
+  GNUNET_ARM_monitor_disconnect_and_free (mon);
 }
 
 
@@ -360,16 +360,25 @@
       GNUNET_free (armconfig);
   }
 
-  arm = GNUNET_ARM_alloc (cfg);
-  GNUNET_ARM_connect (arm, NULL, NULL);
-  mon = GNUNET_ARM_monitor_alloc (cfg);
-  GNUNET_ARM_monitor (mon, srv_status, NULL);
+  arm = GNUNET_ARM_connect (cfg, NULL, NULL);
+  if (NULL != arm)
+  {
+    mon = GNUNET_ARM_monitor (cfg, srv_status, NULL);
+    if (NULL != mon)
+    {
 #if START_ARM
-  GNUNET_ARM_request_service_start (arm, "arm",
-      GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_TIME_UNIT_ZERO, arm_start_cb, 
NULL);
+      GNUNET_ARM_request_service_start (arm, "arm",
+          GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_TIME_UNIT_ZERO, 
arm_start_cb, NULL);
 #else
-  arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", 
GNUNET_ARM_SERVICE_STARTING);
+      arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", 
GNUNET_ARM_SERVICE_STARTING);
 #endif
+    }
+    else
+    {
+      GNUNET_ARM_disconnect_and_free (arm);
+      arm = NULL;
+    }
+  }
 }
 
 static int

Modified: gnunet/src/arm/test_gnunet_service_arm.c
===================================================================
--- gnunet/src/arm/test_gnunet_service_arm.c    2013-03-20 18:50:12 UTC (rev 
26523)
+++ gnunet/src/arm/test_gnunet_service_arm.c    2013-03-20 18:50:18 UTC (rev 
26524)
@@ -134,8 +134,7 @@
     else
       GNUNET_free (armconfig);
   }
-  arm = GNUNET_ARM_alloc (c);
-  GNUNET_ARM_connect (arm, NULL, NULL);
+  arm = GNUNET_ARM_connect (c, NULL, NULL);
   GNUNET_ARM_request_service_start (arm, "arm",
       GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL);
 }

Modified: gnunet/src/include/gnunet_arm_service.h
===================================================================
--- gnunet/src/include/gnunet_arm_service.h     2013-03-20 18:50:12 UTC (rev 
26523)
+++ gnunet/src/include/gnunet_arm_service.h     2013-03-20 18:50:18 UTC (rev 
26524)
@@ -179,11 +179,12 @@
  * Function called whenever we connect to or disconnect from ARM.
  *
  * @param cls closure
- * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected
+ * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
+ *                  GNUNET_SYSERR if there was an error.
  * @param error GNUNET_YES if we encountered a permanent error, and there
  *              will be no re-connection.
  */
-typedef void (*GNUNET_ARM_ConnectionStatusCallback) (void *cls, struct 
GNUNET_ARM_Handle *arm, unsigned char connected, unsigned char error);
+typedef void (*GNUNET_ARM_ConnectionStatusCallback) (void *cls, struct 
GNUNET_ARM_Handle *arm, char connected);
 
 
 /**
@@ -217,28 +218,18 @@
 
 
 /**
- * Setup a context for communicating with ARM.  Note that this
- * can be done even if the ARM service is not yet running.
- * Never fails.
+ * Set up a context for communicating with ARM, then
+ * start connecting to the ARM service using that context.
  *
  * @param cfg configuration to use (needed to contact ARM;
  *        the ARM service may internally use a different
  *        configuration to determine how to start the service).
- * @return context to use for further ARM operations
+ * @param conn_status will be called when connecting/disconnecting
+ * @param cls closure for conn_status
+ * @return context to use for further ARM operations, NULL on error.
  */
 struct GNUNET_ARM_Handle *
-GNUNET_ARM_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg);
-
-/**
- * Start connecting to the ARM service using the context.
- * @param conn_status called when we (dis)connect from/to ARM.
- *        It's also called on connection errors.
- * @param cls closure for conn_status
- *
- * @param h ARM handle
- */
-void
-GNUNET_ARM_connect (struct GNUNET_ARM_Handle *h,
+GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
     GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls);
 
 
@@ -321,27 +312,18 @@
 
 
 /**
- * Setup a context for monitoring ARM.  Note that this
- * can be done even if the ARM service is not yet running.
- * Never fails.
+ * Setup a context for monitoring ARM, then
+ * start connecting to the ARM service for monitoring using that context.
  *
  * @param cfg configuration to use (needed to contact ARM;
  *        the ARM service may internally use a different
  *        configuration to determine how to start the service).
- * @return context to use for further ARM monitor operations
- */
-struct GNUNET_ARM_MonitorHandle *
-GNUNET_ARM_monitor_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg);
-
-/**
- * Start connecting to the ARM service for monitoring using the context.
- *
- * @param h ARM monitor handle
  * @param cont callback to invoke on status updates
  * @param cont_cls closure
+ * @return context to use for further ARM monitor operations, NULL on error.
  */
-void
-GNUNET_ARM_monitor (struct GNUNET_ARM_MonitorHandle *h,
+struct GNUNET_ARM_MonitorHandle *
+GNUNET_ARM_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg,
     GNUNET_ARM_ServiceStatusCallback cont, void *cont_cls);
 
 
@@ -352,7 +334,7 @@
  * @param h the handle that was being used
  */
 void
-GNUNET_ARM_monitor_disconnect (struct GNUNET_ARM_MonitorHandle *h);
+GNUNET_ARM_monitor_disconnect_and_free (struct GNUNET_ARM_MonitorHandle *h);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */

Modified: gnunet/src/regex/gnunet-regex-profiler.c
===================================================================
--- gnunet/src/regex/gnunet-regex-profiler.c    2013-03-20 18:50:12 UTC (rev 
26523)
+++ gnunet/src/regex/gnunet-regex-profiler.c    2013-03-20 18:50:18 UTC (rev 
26524)
@@ -1006,8 +1006,7 @@
 {
   struct RegexPeer *peer = cls;
 
-  peer->arm_handle = GNUNET_ARM_alloc (cfg);
-  GNUNET_ARM_connect (peer->arm_handle, NULL, NULL);
+  peer->arm_handle = GNUNET_ARM_connect (cfg, NULL, NULL);
 
   return peer->arm_handle;
 }




reply via email to

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