diff options
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 | ||