diff options
| -rw-r--r-- | src/bank-lib/test_bank_api.c | 95 | ||||
| -rw-r--r-- | src/exchange-lib/test_exchange_api.c | 92 | ||||
| -rw-r--r-- | src/wire/plugin_wire_test.c | 91 | 
3 files changed, 26 insertions, 252 deletions
diff --git a/src/bank-lib/test_bank_api.c b/src/bank-lib/test_bank_api.c index b92cf5a5..7d1bebb8 100644 --- a/src/bank-lib/test_bank_api.c +++ b/src/bank-lib/test_bank_api.c @@ -38,9 +38,9 @@ static struct GNUNET_CURL_Context *ctx;  static struct GNUNET_SCHEDULER_Task *timeout_task;  /** - * Task that runs the main event loop. + * Context for running the main loop with GNUnet's SCHEDULER API.   */ -static struct GNUNET_SCHEDULER_Task *ctx_task; +static struct GNUNET_CURL_RescheduleContext *rc;  /**   * Result of the testcases, #GNUNET_OK on success @@ -161,29 +161,6 @@ struct InterpreterState  /** - * Task that runs the context's event loop with the GNUnet scheduler. - * - * @param cls unused - */ -static void -context_task (void *cls); - - -/** - * Run the context task, the working set has changed. - * - * @param cls NULL - */ -static void -trigger_context_task (void *cls) -{ -  GNUNET_SCHEDULER_cancel (ctx_task); -  ctx_task = GNUNET_SCHEDULER_add_now (&context_task, -                                       NULL); -} - - -/**   * The testcase failed, return with an error code.   *   * @param is interpreter state to clean up @@ -413,70 +390,12 @@ do_shutdown (void *cls)      is->task = NULL;    }    GNUNET_free (is); -  if (NULL != ctx_task) -  { -    GNUNET_SCHEDULER_cancel (ctx_task); -    ctx_task = NULL; -  }    if (NULL != ctx)    {      GNUNET_CURL_fini (ctx);      ctx = NULL;    } -} - - -/** - * Task that runs the context's event loop with the GNUnet scheduler. - * - * @param cls unused - */ -static void -context_task (void *cls) -{ -  long timeout; -  int max_fd; -  fd_set read_fd_set; -  fd_set write_fd_set; -  fd_set except_fd_set; -  struct GNUNET_NETWORK_FDSet *rs; -  struct GNUNET_NETWORK_FDSet *ws; -  struct GNUNET_TIME_Relative delay; - -  ctx_task = NULL; -  GNUNET_CURL_perform (ctx); -  max_fd = -1; -  timeout = -1; -  FD_ZERO (&read_fd_set); -  FD_ZERO (&write_fd_set); -  FD_ZERO (&except_fd_set); -  GNUNET_CURL_get_select_info (ctx, -                               &read_fd_set, -                               &write_fd_set, -                               &except_fd_set, -                               &max_fd, -                               &timeout); -  if (timeout >= 0) -    delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, -                                           timeout); -  else -    delay = GNUNET_TIME_UNIT_FOREVER_REL; -  rs = GNUNET_NETWORK_fdset_create (); -  GNUNET_NETWORK_fdset_copy_native (rs, -                                    &read_fd_set, -                                    max_fd + 1); -  ws = GNUNET_NETWORK_fdset_create (); -  GNUNET_NETWORK_fdset_copy_native (ws, -                                    &write_fd_set, -                                    max_fd + 1); -  ctx_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, -                                          delay, -                                          rs, -                                          ws, -                                          &context_task, -                                          cls); -  GNUNET_NETWORK_fdset_destroy (rs); -  GNUNET_NETWORK_fdset_destroy (ws); +  GNUNET_CURL_gnunet_rc_destroy (rc);  } @@ -504,12 +423,10 @@ run (void *cls)    is = GNUNET_new (struct InterpreterState);    is->commands = commands; - -  ctx = GNUNET_CURL_init (&trigger_context_task, -                          NULL); +  ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, +                          &rc); +  rc = GNUNET_CURL_gnunet_rc_create (ctx);    GNUNET_assert (NULL != ctx); -  ctx_task = GNUNET_SCHEDULER_add_now (&context_task, -                                       ctx);    is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,                                         is);    timeout_task diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c index 1ab09c9c..e48c59b2 100644 --- a/src/exchange-lib/test_exchange_api.c +++ b/src/exchange-lib/test_exchange_api.c @@ -48,14 +48,14 @@ static struct GNUNET_CURL_Context *ctx;  static struct TALER_EXCHANGE_Handle *exchange;  /** - * Task run on timeout. + * Context for running the CURL event loop.   */ -static struct GNUNET_SCHEDULER_Task *timeout_task; +static struct GNUNET_CURL_RescheduleContext *rc;  /** - * Task that runs the main event loop. + * Task run on timeout.   */ -static struct GNUNET_SCHEDULER_Task *ctx_task; +static struct GNUNET_SCHEDULER_Task *timeout_task;  /**   * Result of the testcases, #GNUNET_OK on success @@ -2147,10 +2147,10 @@ do_shutdown (void *cls)      GNUNET_CURL_fini (ctx);      ctx = NULL;    } -  if (NULL != ctx_task) +  if (NULL != rc)    { -    GNUNET_SCHEDULER_cancel (ctx_task); -    ctx_task = NULL; +    GNUNET_CURL_gnunet_rc_destroy (rc); +    rc = NULL;    }    if (NULL != timeout_task)    { @@ -2195,77 +2195,6 @@ cert_cb (void *cls,  /** - * Task that runs the context's event loop with the GNUnet scheduler. - * - * @param cls unused - */ -static void -context_task (void *cls) -{ -  long timeout; -  int max_fd; -  fd_set read_fd_set; -  fd_set write_fd_set; -  fd_set except_fd_set; -  struct GNUNET_NETWORK_FDSet *rs; -  struct GNUNET_NETWORK_FDSet *ws; -  struct GNUNET_TIME_Relative delay; - -  ctx_task = NULL; -  GNUNET_CURL_perform (ctx); -  max_fd = -1; -  timeout = -1; -  FD_ZERO (&read_fd_set); -  FD_ZERO (&write_fd_set); -  FD_ZERO (&except_fd_set); -  GNUNET_CURL_get_select_info (ctx, -                               &read_fd_set, -                               &write_fd_set, -                               &except_fd_set, -                               &max_fd, -                               &timeout); -  if (timeout >= 0) -    delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, -                                           timeout); -  else -    delay = GNUNET_TIME_UNIT_FOREVER_REL; -  rs = GNUNET_NETWORK_fdset_create (); -  GNUNET_NETWORK_fdset_copy_native (rs, -                                    &read_fd_set, -                                    max_fd + 1); -  ws = GNUNET_NETWORK_fdset_create (); -  GNUNET_NETWORK_fdset_copy_native (ws, -                                    &write_fd_set, -                                    max_fd + 1); -  ctx_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, -                                          delay, -                                          rs, -                                          ws, -                                          &context_task, -                                          cls); -  GNUNET_NETWORK_fdset_destroy (rs); -  GNUNET_NETWORK_fdset_destroy (ws); -} - - -/** - * Run the context task, the working set has changed. - * - * @param cls NULL - */ -static void -trigger_context_task (void *cls) -{ -  if (NULL == ctx) -    return; -  if (NULL != ctx_task) -    GNUNET_SCHEDULER_cancel (ctx_task); -  ctx_task = GNUNET_SCHEDULER_add_now (&context_task, -                                       NULL); -} - - -/**   * Main function that will be run by the scheduler.   *   * @param cls closure @@ -2510,11 +2439,10 @@ run (void *cls)    is = GNUNET_new (struct InterpreterState);    is->commands = commands; -  ctx = GNUNET_CURL_init (&trigger_context_task, -                          NULL); +  ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, +                          &rc); +  rc = GNUNET_CURL_gnunet_rc_create (ctx);    GNUNET_assert (NULL != ctx); -  ctx_task = GNUNET_SCHEDULER_add_now (&context_task, -                                       ctx);    exchange = TALER_EXCHANGE_connect (ctx,                                       "http://localhost:8081",                                       &cert_cb, is, diff --git a/src/wire/plugin_wire_test.c b/src/wire/plugin_wire_test.c index 07072f27..da24a49b 100644 --- a/src/wire/plugin_wire_test.c +++ b/src/wire/plugin_wire_test.c @@ -51,9 +51,9 @@ struct TestClosure    struct GNUNET_CURL_Context *ctx;    /** -   * Handle to the bank task, or NULL. +   * Scheduler context for running the @e ctx.     */ -  struct GNUNET_SCHEDULER_Task *bt; +  struct GNUNET_CURL_RescheduleContext *rc;    /**     * Number of the account that the exchange has at the bank for @@ -132,78 +132,6 @@ struct TALER_WIRE_ExecuteHandle  }; -/** - * Task that runs the bank's context's event loop with the GNUnet - * scheduler. - * - * @param cls our `struct TestClosure` - */ -static void -context_task (void *cls) -{ -  struct TestClosure *tc = cls; -  long timeout; -  int max_fd; -  fd_set read_fd_set; -  fd_set write_fd_set; -  fd_set except_fd_set; -  struct GNUNET_NETWORK_FDSet *rs; -  struct GNUNET_NETWORK_FDSet *ws; -  struct GNUNET_TIME_Relative delay; - -  tc->bt = NULL; -  GNUNET_CURL_perform (tc->ctx); -  max_fd = -1; -  timeout = -1; -  FD_ZERO (&read_fd_set); -  FD_ZERO (&write_fd_set); -  FD_ZERO (&except_fd_set); -  GNUNET_CURL_get_select_info (tc->ctx, -                               &read_fd_set, -                               &write_fd_set, -                               &except_fd_set, -                               &max_fd, -                               &timeout); -  if (timeout >= 0) -    delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, -                                           timeout); -  else -    delay = GNUNET_TIME_UNIT_FOREVER_REL; -  rs = GNUNET_NETWORK_fdset_create (); -  GNUNET_NETWORK_fdset_copy_native (rs, -                                    &read_fd_set, -                                    max_fd + 1); -  ws = GNUNET_NETWORK_fdset_create (); -  GNUNET_NETWORK_fdset_copy_native (ws, -                                    &write_fd_set, -                                    max_fd + 1); -  tc->bt = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, -                                        delay, -                                        rs, -                                        ws, -                                        &context_task, -                                        tc); -  GNUNET_NETWORK_fdset_destroy (rs); -  GNUNET_NETWORK_fdset_destroy (ws); -} - - -/** - * Run the bank task now. - * - * @param cls context for which we should initiate running the task - */ -static void -run_bt (void *cls) -{ -  struct TestClosure *tc = cls; - -  if (NULL != tc->bt) -    GNUNET_SCHEDULER_cancel (tc->bt); -  tc->bt = GNUNET_SCHEDULER_add_now (&context_task, -                                     tc); -} -  /**   * Round amount DOWN to the amount that can be transferred via the wire @@ -832,8 +760,9 @@ libtaler_plugin_wire_test_init (void *cls)        GNUNET_free (tc);        return NULL;      } -    tc->ctx = GNUNET_CURL_init (&run_bt, -                                tc); +    tc->ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, +                                &tc->rc); +    tc->rc = GNUNET_CURL_gnunet_rc_create (tc->ctx);      if (NULL == tc->ctx)      {        GNUNET_break (0); @@ -869,16 +798,16 @@ libtaler_plugin_wire_test_done (void *cls)    struct TALER_WIRE_Plugin *plugin = cls;    struct TestClosure *tc = plugin->cls; -  if (NULL != tc->bt) -  { -    GNUNET_SCHEDULER_cancel (tc->bt); -    tc->bt = NULL; -  }    if (NULL != tc->ctx)    {      GNUNET_CURL_fini (tc->ctx);      tc->ctx = NULL;    } +  if (NULL != tc->rc) +  { +    GNUNET_CURL_gnunet_rc_destroy (tc->rc); +    tc->rc = NULL; +  }    GNUNET_free_non_null (tc->currency);    GNUNET_free_non_null (tc->bank_uri);    GNUNET_free (tc);  | 
