gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (ec2725b5 -> 7c5b14ac)


From: gnunet
Subject: [libmicrohttpd] branch master updated (ec2725b5 -> 7c5b14ac)
Date: Thu, 04 Nov 2021 14:16:11 +0100

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from ec2725b5 test_str_token{,s}_remove: fixed comments
     new 61b997d9 MHD_uint32_to_strx(): rewritten for readability and minor 
optimization
     new 7c5b14ac Doxy: finally clarified how to work with callbacks

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/microhttpd.h    | 42 ++++++++++++++++++++++++++++++++++--------
 src/microhttpd/connection.c |  6 ++++++
 src/microhttpd/daemon.c     | 15 ++++++++-------
 src/microhttpd/mhd_str.c    | 28 +++++++++++++++-------------
 4 files changed, 63 insertions(+), 28 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 9fece2e5..3f285eb5 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -2349,12 +2349,27 @@ typedef enum MHD_Result
 
 
 /**
- * A client has requested the given url using the given method
- * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT,
- * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc).  The callback
- * must call MHD callbacks to provide content to give back to the
- * client and return an HTTP status code (i.e. #MHD_HTTP_OK,
- * #MHD_HTTP_NOT_FOUND, etc.).
+ * A client has requested the given @a url using the given @a method
+ * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, #MHD_HTTP_METHOD_DELETE,
+ * #MHD_HTTP_METHOD_POST, etc).
+ *
+ * The callback must call MHD function MHD_queue_response() to provide content
+ * to give back to the client and return an HTTP status code
+ * (i.e. #MHD_HTTP_OK, #MHD_HTTP_NOT_FOUND, etc.). The response can be created
+ * in this callback or prepared in advance.
+ * As soon as response is provided this callback will not be called anymore
+ * for the current request.
+ * Alternatively, callback may call MHD_suspend_connection() to temporarily
+ * suspend data processing for this connection.
+ * For each HTTP request this callback is called several times:
+ * * after request headers are fully received and decoded,
+ * * for each received part of request body (optional, if request has body),
+ * * when request is fully received.
+ * If response is provided before request is fully received, the rest
+ * of the request is discarded and connection is automatically closed
+ * after sending response.
+ * If the request is fully received, but response hasn't been provided and
+ * connection is not suspended, the callback can be called again immediately.
  *
  * @param cls argument given together with the function
  *        pointer when the handler was registered with MHD
@@ -2386,6 +2401,8 @@ typedef enum MHD_Result
  * @return #MHD_YES if the connection was handled successfully,
  *         #MHD_NO if the socket must be closed due to a serious
  *         error while handling the request
+ *
+ * @sa #MHD_queue_response()
  */
 typedef enum MHD_Result
 (*MHD_AccessHandlerCallback)(void *cls,
@@ -3162,12 +3179,18 @@ MHD_lookup_connection_value_n (struct MHD_Connection 
*connection,
  * Queue a response to be transmitted to the client (as soon as
  * possible but after #MHD_AccessHandlerCallback returns).
  *
+ * For any active connection this function must be called
+ * only by #MHD_AccessHandlerCallback callback.
+ * For suspended connection this function can be called at any moment. Response
+ * will be sent as soon as connection is resumed.
+ *
  * @param connection the connection identifying the client
  * @param status_code HTTP status code (i.e. #MHD_HTTP_OK)
  * @param response response to transmit
  * @return #MHD_NO on error (i.e. reply already sent),
  *         #MHD_YES on success or if message has been queued
  * @ingroup response
+ * @sa #MHD_AccessHandlerCallback
  */
 _MHD_EXTERN enum MHD_Result
 MHD_queue_response (struct MHD_Connection *connection,
@@ -3176,8 +3199,9 @@ MHD_queue_response (struct MHD_Connection *connection,
 
 
 /**
- * Suspend handling of network data for a given connection.  This can
- * be used to dequeue a connection from MHD's event loop for a while.
+ * Suspend handling of network data for a given connection.
+ * This can be used to dequeue a connection from MHD's event loop
+ * (not applicable to thread-per-connection!) for a while.
  *
  * If you use this API in conjunction with an "internal" socket polling,
  * you must set the option #MHD_USE_ITC to ensure that a resumed
@@ -3199,6 +3223,8 @@ MHD_queue_response (struct MHD_Connection *connection,
  * resume all connections before stopping the daemon.
  *
  * @param connection the connection to suspend
+ *
+ * @sa #MHD_AccessHandlerCallback
  */
 _MHD_EXTERN void
 MHD_suspend_connection (struct MHD_Connection *connection);
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index eef0f5d3..a068bfe4 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -4920,12 +4920,18 @@ MHD_set_connection_option (struct MHD_Connection 
*connection,
  * Queue a response to be transmitted to the client (as soon as
  * possible but after #MHD_AccessHandlerCallback returns).
  *
+ * For any active connection this function must be called
+ * only by #MHD_AccessHandlerCallback callback.
+ * For suspended connection this function can be called at any moment. Response
+ * will be sent as soon as connection is resumed.
+ *
  * @param connection the connection identifying the client
  * @param status_code HTTP status code (i.e. #MHD_HTTP_OK)
  * @param response response to transmit
  * @return #MHD_NO on error (i.e. reply already sent),
  *         #MHD_YES on success or if message has been queued
  * @ingroup response
+ * @sa #MHD_AccessHandlerCallback
  */
 enum MHD_Result
 MHD_queue_response (struct MHD_Connection *connection,
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 0ff7bffc..32334621 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -3126,14 +3126,13 @@ internal_suspend_connection_ (struct MHD_Connection 
*connection)
 
 
 /**
- * Suspend handling of network data for a given connection.  This can
- * be used to dequeue a connection from MHD's event loop (external
- * select, internal select or thread pool; not applicable to
- * thread-per-connection!) for a while.
+ * Suspend handling of network data for a given connection.
+ * This can be used to dequeue a connection from MHD's event loop
+ * (not applicable to thread-per-connection!) for a while.
  *
- * If you use this API in conjunction with a internal select or a
- * thread pool, you must set the option #MHD_USE_ITC to
- * ensure that a resumed connection is immediately processed by MHD.
+ * If you use this API in conjunction with an "internal" socket polling,
+ * you must set the option #MHD_USE_ITC to ensure that a resumed
+ * connection is immediately processed by MHD.
  *
  * Suspended connections continue to count against the total number of
  * connections allowed (per daemon, as well as per IP, if such limits
@@ -3155,6 +3154,8 @@ internal_suspend_connection_ (struct MHD_Connection 
*connection)
  * daemon's select()/poll()/etc.
  *
  * @param connection the connection to suspend
+ *
+ * @sa #MHD_AccessHandlerCallback
  */
 void
 MHD_suspend_connection (struct MHD_Connection *connection)
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index 0526a1a5..6c07a574 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -1203,25 +1203,27 @@ MHD_uint32_to_strx (uint32_t val,
                     char *buf,
                     size_t buf_size)
 {
-  char *chr; /**< pointer to the current printed digit */
-  int digit_pos = 7; /** zero-based, digit position in @a 'val' */
+  size_t o_pos = 0; /**< position of the output character */
+  int digit_pos = 8; /** zero-based, digit position in @a 'val' */
   int digit;
 
-  chr = buf;
-  digit = (int) (((val) >> (4 * digit_pos)) & 0xf);
-
   /* Skip leading zeros */
-  while ((0 == digit) && (0 != digit_pos))
-    digit = (int) (((val) >> (4 * --digit_pos)) & 0xf);
+  do
+  {
+    digit_pos--;
+    digit = (int) (val >> 28);
+    val <<= 4;
+  } while ((0 == digit) && (0 != digit_pos));
 
-  while (0 != buf_size)
+  while (o_pos < buf_size)
   {
-    *chr = (digit <= 9) ? ('0' + (char) digit) : ('A' + (char) digit - 10);
-    chr++;
-    buf_size--;
+    buf[o_pos++] = (digit <= 9) ? ('0' + (char) digit) :
+                   ('A' + (char) digit - 10);
     if (0 == digit_pos)
-      return (size_t) (chr - buf);
-    digit = (int) (((val) >> (4 * --digit_pos)) & 0xf);
+      return o_pos;
+    digit_pos--;
+    digit = (int) (val >> 28);
+    val <<= 4;
   }
   return 0; /* The buffer is too small */
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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