gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated: Updated chunked_exam


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated: Updated chunked_example.c
Date: Tue, 25 Jul 2017 10:42:07 +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 5d497ac6 Updated chunked_example.c
5d497ac6 is described below

commit 5d497ac69913da3efd489e9443b25ca76d57c2bb
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Tue Jul 25 11:41:46 2017 +0300

    Updated chunked_example.c
---
 ChangeLog                      |  4 ++++
 src/examples/chunked_example.c | 22 ++++++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7e9a6f12..b4517d2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Jul 23 11:32:00 MSK 2017
+       Updated chunked_example.c to provide real illustration of usage of
+       chunked encoding. -EG
+
 Thu Jul 13 21:41:00 MSK 2017
        Restored SIGPIPE suppression in TLS mode.
        Added new value MHD_FEATURE_AUTOSUPPRESS_SIGPIPE so application could
diff --git a/src/examples/chunked_example.c b/src/examples/chunked_example.c
index 67b8c4ca..cec20910 100644
--- a/src/examples/chunked_example.c
+++ b/src/examples/chunked_example.c
@@ -30,9 +30,27 @@ static ssize_t
 callback (void *cls,
           uint64_t pos,
           char *buf,
-          size_t max)
+          size_t buf_size)
 {
-  return MHD_CONTENT_READER_END_OF_STREAM;
+  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;
+
+  /* Note: 'pos' will never exceed size of transmitted data. */
+  /* You can use 'pos == response_size' in next check. */
+  if (pos >= response_size)
+    { /* Whole response was sent. Signal end of response. */
+      return MHD_CONTENT_READER_END_OF_STREAM;
+    }
+
+  if (buf_size < (response_size - pos) )
+    size_to_copy = buf_size;
+  else
+    size_to_copy = response_size - pos;
+
+  memcpy (buf, response_data + pos, size_to_copy);
+  return size_to_copy;
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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