gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r27944 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r27944 - in gnunet/src: include util
Date: Fri, 12 Jul 2013 00:18:17 +0200

Author: grothoff
Date: 2013-07-12 00:18:17 +0200 (Fri, 12 Jul 2013)
New Revision: 27944

Modified:
   gnunet/src/include/gnunet_server_lib.h
   gnunet/src/util/server.c
Log:
-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)

Modified: gnunet/src/include/gnunet_server_lib.h
===================================================================
--- gnunet/src/include/gnunet_server_lib.h      2013-07-11 22:08:03 UTC (rev 
27943)
+++ gnunet/src/include/gnunet_server_lib.h      2013-07-11 22:18:17 UTC (rev 
27944)
@@ -297,7 +297,53 @@
                                   struct GNUNET_TIME_Relative timeout);
 
 
+
 /**
+ * Return user context associated with the given client.
+ * Note: you should probably use the macro (call without the underscore).
+ *
+ * @param client client to query
+ * @param size number of bytes in user context struct (for verification only)
+ * @return pointer to user context
+ */
+void *
+GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client,
+                                       size_t size);
+
+
+/**
+ * Set user context to be associated with the given client.
+ * Note: you should probably use the macro (call without the underscore).
+ *
+ * @param client client to query
+ * @param ptr pointer to user context
+ * @param size number of bytes in user context struct (for verification only)
+ */
+void 
+GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
+                                       void *ptr,
+                                       size_t size);
+
+
+/**
+ * Return user context associated with the given client.
+ *
+ * @param client client to query
+ * @param type expected return type (i.e. 'struct Foo')
+ * @return pointer to user context of type 'type *'.
+ */
+#define GNUNET_SERVER_client_get_user_context(client,type) (type *) 
GNUNET_SERVER_client_get_user_context_ (client, sizeof (type))
+
+/**
+ * Set user context to be associated with the given client.
+ *
+ * @param client client to query
+ * @param ptr pointer to user context
+ */
+#define GNUNET_SERVER_client_set_user_context(client,value) 
GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value))
+
+
+/**
  * Disable the warning the server issues if a message is not acknowledged
  * in a timely fashion.  Use this call if a client is intentionally delayed
  * for a while.  Only applies to the current message.

Modified: gnunet/src/util/server.c
===================================================================
--- gnunet/src/util/server.c    2013-07-11 22:08:03 UTC (rev 27943)
+++ gnunet/src/util/server.c    2013-07-11 22:18:17 UTC (rev 27944)
@@ -239,6 +239,12 @@
   struct GNUNET_CONNECTION_Handle *connection;
 
   /**
+   * User context value, manipulated using
+   * 'GNUNET_SERVER_client_{get/set}_user_context' functions.
+   */
+  void *user_context;
+
+  /**
    * ID of task used to restart processing.
    */
   GNUNET_SCHEDULER_TaskIdentifier restart_task;
@@ -286,6 +292,12 @@
   unsigned int suspended;
 
   /**
+   * Last size given when user context was initialized; used for
+   * sanity check.
+   */
+  size_t user_context_size;
+
+  /**
    * Are we currently in the "process_client_buffer" function (and
    * will hence restart the receive job on exit if suspended == 0 once
    * we are done?).  If this is set, then "receive_done" will
@@ -327,18 +339,43 @@
 };
 
 
+
 /**
- * Scheduler says our listen socket is ready.  Process it!
+ * Return user context associated with the given client.
+ * Note: you should probably use the macro (call without the underscore).
  *
- * @param cls handle to our server for which we are processing the listen
- *        socket
- * @param tc reason why we are running right now
+ * @param client client to query
+ * @param size number of bytes in user context struct (for verification only)
+ * @return pointer to user context
  */
-static void
-process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext 
*tc);
+void *
+GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client,
+                                       size_t size)
+{
+  GNUNET_assert (size == client->user_context_size);
+  return client->user_context;
+}
 
 
 /**
+ * Set user context to be associated with the given client.
+ * Note: you should probably use the macro (call without the underscore).
+ *
+ * @param client client to query
+ * @param ptr pointer to user context
+ * @param size number of bytes in user context struct (for verification only)
+ */
+void 
+GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
+                                       void *ptr,
+                                       size_t size)
+{
+  client->user_context_size = size;
+  client->user_context = ptr;
+}
+
+
+/**
  * Scheduler says our listen socket is ready.  Process it!
  *
  * @param cls handle to our server for which we are processing the listen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]