aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-02-01 12:49:17 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-02-01 12:49:17 +0000
commit173616fa2120be705164536d8bd391f6588da11b (patch)
tree1aa91c8030e4bb367c13f7346c83f8cea6eeca3b /src
parentc4b94034c6affa4fbb18acc63cb9402a53f30461 (diff)
downloadgnunet-173616fa2120be705164536d8bd391f6588da11b.tar.gz
gnunet-173616fa2120be705164536d8bd391f6588da11b.zip
GNUNET_TRANSPORT_get_hello() to call its callback asynchronously
Diffstat (limited to 'src')
-rw-r--r--src/transport/transport_api.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index 520d8fc49..62f8604fb 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -181,6 +181,11 @@ struct GNUNET_TRANSPORT_GetHelloHandle
181 GNUNET_TRANSPORT_HelloUpdateCallback rec; 181 GNUNET_TRANSPORT_HelloUpdateCallback rec;
182 182
183 /** 183 /**
184 * Task for calling the HelloUpdateCallback when we already have a HELLO
185 */
186 GNUNET_SCHEDULER_TaskIdentifier notify_task;
187
188 /**
184 * Closure for rec. 189 * Closure for rec.
185 */ 190 */
186 void *rec_cls; 191 void *rec_cls;
@@ -1262,6 +1267,27 @@ GNUNET_TRANSPORT_check_neighbour_connected (struct GNUNET_TRANSPORT_Handle *hand
1262 return GNUNET_NO; 1267 return GNUNET_NO;
1263} 1268}
1264 1269
1270
1271/**
1272 * Task to call the HelloUpdateCallback of the GetHelloHandle
1273 *
1274 * @param cls the GetHelloHandle
1275 * @param tc the scheduler task context
1276 */
1277static void
1278call_hello_update_cb_async (void *cls,
1279 const struct GNUNET_SCHEDULER_TaskContext *tc)
1280{
1281 struct GNUNET_TRANSPORT_GetHelloHandle *ghh = cls;
1282
1283 GNUNET_assert (NULL != ghh->handle->my_hello);
1284 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != ghh->notify_task);
1285 ghh->notify_task = GNUNET_SCHEDULER_NO_TASK;
1286 ghh->rec (ghh->rec_cls,
1287 (const struct GNUNET_MessageHeader *) ghh->handle->my_hello);
1288}
1289
1290
1265/** 1291/**
1266 * Obtain the HELLO message for this peer. 1292 * Obtain the HELLO message for this peer.
1267 * 1293 *
@@ -1286,7 +1312,8 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
1286 hwl->handle = handle; 1312 hwl->handle = handle;
1287 GNUNET_CONTAINER_DLL_insert (handle->hwl_head, handle->hwl_tail, hwl); 1313 GNUNET_CONTAINER_DLL_insert (handle->hwl_head, handle->hwl_tail, hwl);
1288 if (handle->my_hello != NULL) 1314 if (handle->my_hello != NULL)
1289 rec (rec_cls, (const struct GNUNET_MessageHeader *) handle->my_hello); 1315 hwl->notify_task = GNUNET_SCHEDULER_add_now (&call_hello_update_cb_async,
1316 hwl);
1290 return hwl; 1317 return hwl;
1291} 1318}
1292 1319
@@ -1301,6 +1328,8 @@ GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh)
1301{ 1328{
1302 struct GNUNET_TRANSPORT_Handle *handle = ghh->handle; 1329 struct GNUNET_TRANSPORT_Handle *handle = ghh->handle;
1303 1330
1331 if (GNUNET_SCHEDULER_NO_TASK != ghh->notify_task)
1332 GNUNET_SCHEDULER_cancel (ghh->notify_task);
1304 GNUNET_CONTAINER_DLL_remove (handle->hwl_head, handle->hwl_tail, ghh); 1333 GNUNET_CONTAINER_DLL_remove (handle->hwl_head, handle->hwl_tail, ghh);
1305 GNUNET_free (ghh); 1334 GNUNET_free (ghh);
1306} 1335}