code simplification via new extended libgnunetcurl API
This commit is contained in:
parent
ad45e5ab7a
commit
5fd6a25c6d
@ -38,9 +38,9 @@ static struct GNUNET_CURL_Context *ctx;
|
|||||||
static struct GNUNET_SCHEDULER_Task *timeout_task;
|
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
|
* Result of the testcases, #GNUNET_OK on success
|
||||||
@ -160,29 +160,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.
|
* The testcase failed, return with an error code.
|
||||||
*
|
*
|
||||||
@ -413,70 +390,12 @@ do_shutdown (void *cls)
|
|||||||
is->task = NULL;
|
is->task = NULL;
|
||||||
}
|
}
|
||||||
GNUNET_free (is);
|
GNUNET_free (is);
|
||||||
if (NULL != ctx_task)
|
|
||||||
{
|
|
||||||
GNUNET_SCHEDULER_cancel (ctx_task);
|
|
||||||
ctx_task = NULL;
|
|
||||||
}
|
|
||||||
if (NULL != ctx)
|
if (NULL != ctx)
|
||||||
{
|
{
|
||||||
GNUNET_CURL_fini (ctx);
|
GNUNET_CURL_fini (ctx);
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
}
|
}
|
||||||
}
|
GNUNET_CURL_gnunet_rc_destroy (rc);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -504,12 +423,10 @@ run (void *cls)
|
|||||||
|
|
||||||
is = GNUNET_new (struct InterpreterState);
|
is = GNUNET_new (struct InterpreterState);
|
||||||
is->commands = commands;
|
is->commands = commands;
|
||||||
|
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
|
||||||
ctx = GNUNET_CURL_init (&trigger_context_task,
|
&rc);
|
||||||
NULL);
|
rc = GNUNET_CURL_gnunet_rc_create (ctx);
|
||||||
GNUNET_assert (NULL != ctx);
|
GNUNET_assert (NULL != ctx);
|
||||||
ctx_task = GNUNET_SCHEDULER_add_now (&context_task,
|
|
||||||
ctx);
|
|
||||||
is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
|
is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
|
||||||
is);
|
is);
|
||||||
timeout_task
|
timeout_task
|
||||||
|
@ -47,16 +47,16 @@ static struct GNUNET_CURL_Context *ctx;
|
|||||||
*/
|
*/
|
||||||
static struct TALER_EXCHANGE_Handle *exchange;
|
static struct TALER_EXCHANGE_Handle *exchange;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context for running the CURL event loop.
|
||||||
|
*/
|
||||||
|
static struct GNUNET_CURL_RescheduleContext *rc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task run on timeout.
|
* Task run on timeout.
|
||||||
*/
|
*/
|
||||||
static struct GNUNET_SCHEDULER_Task *timeout_task;
|
static struct GNUNET_SCHEDULER_Task *timeout_task;
|
||||||
|
|
||||||
/**
|
|
||||||
* Task that runs the main event loop.
|
|
||||||
*/
|
|
||||||
static struct GNUNET_SCHEDULER_Task *ctx_task;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Result of the testcases, #GNUNET_OK on success
|
* Result of the testcases, #GNUNET_OK on success
|
||||||
*/
|
*/
|
||||||
@ -2147,10 +2147,10 @@ do_shutdown (void *cls)
|
|||||||
GNUNET_CURL_fini (ctx);
|
GNUNET_CURL_fini (ctx);
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
}
|
}
|
||||||
if (NULL != ctx_task)
|
if (NULL != rc)
|
||||||
{
|
{
|
||||||
GNUNET_SCHEDULER_cancel (ctx_task);
|
GNUNET_CURL_gnunet_rc_destroy (rc);
|
||||||
ctx_task = NULL;
|
rc = NULL;
|
||||||
}
|
}
|
||||||
if (NULL != timeout_task)
|
if (NULL != timeout_task)
|
||||||
{
|
{
|
||||||
@ -2194,77 +2194,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.
|
* Main function that will be run by the scheduler.
|
||||||
*
|
*
|
||||||
@ -2510,11 +2439,10 @@ run (void *cls)
|
|||||||
is = GNUNET_new (struct InterpreterState);
|
is = GNUNET_new (struct InterpreterState);
|
||||||
is->commands = commands;
|
is->commands = commands;
|
||||||
|
|
||||||
ctx = GNUNET_CURL_init (&trigger_context_task,
|
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
|
||||||
NULL);
|
&rc);
|
||||||
|
rc = GNUNET_CURL_gnunet_rc_create (ctx);
|
||||||
GNUNET_assert (NULL != ctx);
|
GNUNET_assert (NULL != ctx);
|
||||||
ctx_task = GNUNET_SCHEDULER_add_now (&context_task,
|
|
||||||
ctx);
|
|
||||||
exchange = TALER_EXCHANGE_connect (ctx,
|
exchange = TALER_EXCHANGE_connect (ctx,
|
||||||
"http://localhost:8081",
|
"http://localhost:8081",
|
||||||
&cert_cb, is,
|
&cert_cb, is,
|
||||||
|
@ -51,9 +51,9 @@ struct TestClosure
|
|||||||
struct GNUNET_CURL_Context *ctx;
|
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
|
* 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
|
* 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);
|
GNUNET_free (tc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
tc->ctx = GNUNET_CURL_init (&run_bt,
|
tc->ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
|
||||||
tc);
|
&tc->rc);
|
||||||
|
tc->rc = GNUNET_CURL_gnunet_rc_create (tc->ctx);
|
||||||
if (NULL == tc->ctx)
|
if (NULL == tc->ctx)
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
@ -869,16 +798,16 @@ libtaler_plugin_wire_test_done (void *cls)
|
|||||||
struct TALER_WIRE_Plugin *plugin = cls;
|
struct TALER_WIRE_Plugin *plugin = cls;
|
||||||
struct TestClosure *tc = plugin->cls;
|
struct TestClosure *tc = plugin->cls;
|
||||||
|
|
||||||
if (NULL != tc->bt)
|
|
||||||
{
|
|
||||||
GNUNET_SCHEDULER_cancel (tc->bt);
|
|
||||||
tc->bt = NULL;
|
|
||||||
}
|
|
||||||
if (NULL != tc->ctx)
|
if (NULL != tc->ctx)
|
||||||
{
|
{
|
||||||
GNUNET_CURL_fini (tc->ctx);
|
GNUNET_CURL_fini (tc->ctx);
|
||||||
tc->ctx = NULL;
|
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->currency);
|
||||||
GNUNET_free_non_null (tc->bank_uri);
|
GNUNET_free_non_null (tc->bank_uri);
|
||||||
GNUNET_free (tc);
|
GNUNET_free (tc);
|
||||||
|
Loading…
Reference in New Issue
Block a user