aboutsummaryrefslogtreecommitdiff
path: root/src/util/server.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-11 22:18:17 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-11 22:18:17 +0000
commit57be99113715a6023164633556ea1de50ceae6e1 (patch)
treebe1c6003207ec50b17483267f21ad10cbc85d976 /src/util/server.c
parent4f0cfaff0e3e5cc0c59801279714cb0467fc0385 (diff)
downloadgnunet-57be99113715a6023164633556ea1de50ceae6e1.tar.gz
gnunet-57be99113715a6023164633556ea1de50ceae6e1.zip
-adding API to associated user context with a server's client to avoid ugly hacks, such as linked list searches and casting pointers to integers (thanks to Peter-Vogginger for forcing me to fix this)
Diffstat (limited to 'src/util/server.c')
-rw-r--r--src/util/server.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/src/util/server.c b/src/util/server.c
index f62bf8539..6dbb5dc23 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -239,6 +239,12 @@ struct GNUNET_SERVER_Client
239 struct GNUNET_CONNECTION_Handle *connection; 239 struct GNUNET_CONNECTION_Handle *connection;
240 240
241 /** 241 /**
242 * User context value, manipulated using
243 * 'GNUNET_SERVER_client_{get/set}_user_context' functions.
244 */
245 void *user_context;
246
247 /**
242 * ID of task used to restart processing. 248 * ID of task used to restart processing.
243 */ 249 */
244 GNUNET_SCHEDULER_TaskIdentifier restart_task; 250 GNUNET_SCHEDULER_TaskIdentifier restart_task;
@@ -286,6 +292,12 @@ struct GNUNET_SERVER_Client
286 unsigned int suspended; 292 unsigned int suspended;
287 293
288 /** 294 /**
295 * Last size given when user context was initialized; used for
296 * sanity check.
297 */
298 size_t user_context_size;
299
300 /**
289 * Are we currently in the "process_client_buffer" function (and 301 * Are we currently in the "process_client_buffer" function (and
290 * will hence restart the receive job on exit if suspended == 0 once 302 * will hence restart the receive job on exit if suspended == 0 once
291 * we are done?). If this is set, then "receive_done" will 303 * we are done?). If this is set, then "receive_done" will
@@ -327,15 +339,40 @@ struct GNUNET_SERVER_Client
327}; 339};
328 340
329 341
342
330/** 343/**
331 * Scheduler says our listen socket is ready. Process it! 344 * Return user context associated with the given client.
345 * Note: you should probably use the macro (call without the underscore).
332 * 346 *
333 * @param cls handle to our server for which we are processing the listen 347 * @param client client to query
334 * socket 348 * @param size number of bytes in user context struct (for verification only)
335 * @param tc reason why we are running right now 349 * @return pointer to user context
336 */ 350 */
337static void 351void *
338process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 352GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client,
353 size_t size)
354{
355 GNUNET_assert (size == client->user_context_size);
356 return client->user_context;
357}
358
359
360/**
361 * Set user context to be associated with the given client.
362 * Note: you should probably use the macro (call without the underscore).
363 *
364 * @param client client to query
365 * @param ptr pointer to user context
366 * @param size number of bytes in user context struct (for verification only)
367 */
368void
369GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
370 void *ptr,
371 size_t size)
372{
373 client->user_context_size = size;
374 client->user_context = ptr;
375}
339 376
340 377
341/** 378/**