diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-07-25 11:41:46 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-07-25 11:41:46 +0300 |
commit | 5d497ac69913da3efd489e9443b25ca76d57c2bb (patch) | |
tree | 15ee0bcbcd4f723b81b323989132b4d30ba3f18e /src/examples | |
parent | 66066283bd3733b168db454dd9297ba4262e407d (diff) | |
download | libmicrohttpd-5d497ac69913da3efd489e9443b25ca76d57c2bb.tar.gz libmicrohttpd-5d497ac69913da3efd489e9443b25ca76d57c2bb.zip |
Updated chunked_example.c
Diffstat (limited to 'src/examples')
-rw-r--r-- | src/examples/chunked_example.c | 22 |
1 files changed, 20 insertions, 2 deletions
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 | |||
30 | callback (void *cls, | 30 | callback (void *cls, |
31 | uint64_t pos, | 31 | uint64_t pos, |
32 | char *buf, | 32 | char *buf, |
33 | size_t max) | 33 | size_t buf_size) |
34 | { | 34 | { |
35 | return MHD_CONTENT_READER_END_OF_STREAM; | 35 | static const char response_data[] = "<html><head><title>Simple response</title></head>" \ |
36 | "<body>Simple response text</body></html>"; | ||
37 | static const uint64_t response_size = (sizeof(response_data)/sizeof(char)) - 1; | ||
38 | size_t size_to_copy; | ||
39 | |||
40 | /* Note: 'pos' will never exceed size of transmitted data. */ | ||
41 | /* You can use 'pos == response_size' in next check. */ | ||
42 | if (pos >= response_size) | ||
43 | { /* Whole response was sent. Signal end of response. */ | ||
44 | return MHD_CONTENT_READER_END_OF_STREAM; | ||
45 | } | ||
46 | |||
47 | if (buf_size < (response_size - pos) ) | ||
48 | size_to_copy = buf_size; | ||
49 | else | ||
50 | size_to_copy = response_size - pos; | ||
51 | |||
52 | memcpy (buf, response_data + pos, size_to_copy); | ||
53 | return size_to_copy; | ||
36 | } | 54 | } |
37 | 55 | ||
38 | 56 | ||