aboutsummaryrefslogtreecommitdiff
path: root/src/core/test_core_api_send_to_self.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2011-01-05 16:29:04 +0000
committerNathan S. Evans <evans@in.tum.de>2011-01-05 16:29:04 +0000
commit40199d8739a6aa36b279b31aa7532b66a5c8b735 (patch)
tree2c0c214ff248e68291c7619f93eda61b4b1e6451 /src/core/test_core_api_send_to_self.c
parent2cc08175418aec5a9a21e67b6f631e14c7ebbfff (diff)
downloadgnunet-40199d8739a6aa36b279b31aa7532b66a5c8b735.tar.gz
gnunet-40199d8739a6aa36b279b31aa7532b66a5c8b735.zip
make testcase end more gracefully
Diffstat (limited to 'src/core/test_core_api_send_to_self.c')
-rw-r--r--src/core/test_core_api_send_to_self.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c
index bf2697eec..e8121e327 100644
--- a/src/core/test_core_api_send_to_self.c
+++ b/src/core/test_core_api_send_to_self.c
@@ -36,9 +36,16 @@
36static int ret; 36static int ret;
37 37
38/** 38/**
39 * Handle to the cleanup task.
40 */
41GNUNET_SCHEDULER_TaskIdentifier die_task;
42
43static struct GNUNET_PeerIdentity myself;
44
45/**
39 * The handle to core 46 * The handle to core
40 */ 47 */
41static struct GNUNET_CORE_Handle *core_handle; 48struct GNUNET_CORE_Handle *core;
42 49
43/** 50/**
44 * Function scheduled as very last function, cleans up after us 51 * Function scheduled as very last function, cleans up after us
@@ -46,23 +53,26 @@ static struct GNUNET_CORE_Handle *core_handle;
46static void 53static void
47cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tskctx) 54cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tskctx)
48{ 55{
49 GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); 56 die_task = GNUNET_SCHEDULER_NO_TASK;
50 57
51 if (core_handle != NULL) 58 if (core != NULL)
52 { 59 {
53 GNUNET_CORE_disconnect (core_handle); 60 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting core.\n");
54 core_handle = NULL; 61 GNUNET_CORE_disconnect (core);
62 core = NULL;
55 } 63 }
56}
57
58static struct GNUNET_PeerIdentity myself;
59 64
60struct GNUNET_CORE_Handle *core; 65 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
66}
61 67
62static int 68static int
63receive(void* cls, const struct GNUNET_PeerIdentity* other, const struct GNUNET_MessageHeader* message, const struct GNUNET_TRANSPORT_ATS_Information* atsi) 69receive(void* cls, const struct GNUNET_PeerIdentity* other, const struct GNUNET_MessageHeader* message, const struct GNUNET_TRANSPORT_ATS_Information* atsi)
64{ 70{
71 if (die_task != GNUNET_SCHEDULER_NO_TASK)
72 GNUNET_SCHEDULER_cancel(die_task);
65 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received message from peer %s\n", GNUNET_i2s(other)); 73 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received message from peer %s\n", GNUNET_i2s(other));
74 GNUNET_SCHEDULER_add_now(&cleanup, NULL);
75 ret = 0;
66 return GNUNET_OK; 76 return GNUNET_OK;
67} 77}
68 78
@@ -139,7 +149,7 @@ run (void *cls,
139 init, 149 init,
140 connect_cb, 150 connect_cb,
141 NULL, NULL, NULL, 0, NULL, 0, handlers); 151 NULL, NULL, NULL, 0, NULL, 0, handlers);
142 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); 152 die_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), &cleanup, cls);
143} 153}
144 154
145/** 155/**