[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libmicrohttpd] branch master updated: Furthermore extended
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libmicrohttpd] branch master updated: Furthermore extended chunked_example.c to illustrate situation with parameter provided for content callback. |
Date: |
Wed, 26 Jul 2017 14:41:02 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
The following commit(s) were added to refs/heads/master by this push:
new bb169963 Furthermore extended chunked_example.c to illustrate
situation with parameter provided for content callback.
bb169963 is described below
commit bb1699636bcc51526f2cd7ba268ae500d6a54a96
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Wed Jul 26 15:37:53 2017 +0300
Furthermore extended chunked_example.c to illustrate situation with
parameter provided for content callback.
---
src/examples/chunked_example.c | 41 +++++++++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/src/examples/chunked_example.c b/src/examples/chunked_example.c
index 3cd008df..d8c2b7a7 100644
--- a/src/examples/chunked_example.c
+++ b/src/examples/chunked_example.c
@@ -26,6 +26,11 @@
#include "platform.h"
#include <microhttpd.h>
+struct responseContentCallbackParam
+{
+ const char *response_data;
+ size_t response_size;
+};
static ssize_t
callback (void *cls,
@@ -33,14 +38,13 @@ callback (void *cls,
char *buf,
size_t buf_size)
{
- static const char response_data[] = "<html><head><title>Simple
response</title></head>" \
- "<body>Simple response text</body></html>";
- static const uint64_t response_size = (sizeof(response_data)/sizeof(char)) -
1;
size_t size_to_copy;
+ struct responseContentCallbackParam * const param =
+ (struct responseContentCallbackParam *)cls;
/* Note: 'pos' will never exceed size of transmitted data. */
- /* You can use 'pos == response_size' in next check. */
- if (pos >= response_size)
+ /* You can use 'pos == param->response_size' in next check. */
+ if (pos >= param->response_size)
{ /* Whole response was sent. Signal end of response. */
return MHD_CONTENT_READER_END_OF_STREAM;
}
@@ -54,12 +58,12 @@ callback (void *cls,
}
* End of pseudo code. */
- if (buf_size < (response_size - pos) )
+ if (buf_size < (param->response_size - pos))
size_to_copy = buf_size;
else
- size_to_copy = response_size - pos;
+ size_to_copy = param->response_size - pos;
- memcpy (buf, response_data + pos, size_to_copy);
+ memcpy (buf, param->response_data + pos, size_to_copy);
/* Pseudo code. *
if (error_preparing_response)
@@ -73,6 +77,14 @@ callback (void *cls,
return size_to_copy;
}
+void
+free_callback_param(void *cls)
+{
+ free(cls);
+}
+
+static const char simple_response_text[] = "<html><head><title>Simple
response</title></head>"
+ "<body>Simple response
text</body></html>";
static int
@@ -84,6 +96,7 @@ ahc_echo (void *cls,
const char *upload_data, size_t *upload_data_size, void **ptr)
{
static int aptr;
+ struct responseContentCallbackParam * callback_param;
struct MHD_Response *response;
int ret;
@@ -95,12 +108,20 @@ ahc_echo (void *cls,
*ptr = &aptr;
return MHD_YES;
}
+
+ callback_param = malloc (sizeof(struct responseContentCallbackParam));
+ if (NULL == callback_param)
+ return MHD_NO; /* Not enough memory. */
+
+ callback_param->response_data = simple_response_text;
+ callback_param->response_size = (sizeof(simple_response_text)/sizeof(char))
- 1;
+
*ptr = NULL; /* reset when done */
response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
1024,
&callback,
- NULL,
- NULL);
+ callback_param,
+ &free_callback_param);
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
MHD_destroy_response (response);
return ret;
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [libmicrohttpd] branch master updated: Furthermore extended chunked_example.c to illustrate situation with parameter provided for content callback.,
gnunet <=