diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-05-18 13:30:07 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-05-18 13:44:45 +0300 |
commit | 84905a4df0448257e846e97eeed8a4d4f3e275bc (patch) | |
tree | 0a16d6016a1cd2917a1ca9853190b287180e06f2 | |
parent | f5b873553831a9721b5d59c335b5217ec817ce48 (diff) | |
download | libmicrohttpd-84905a4df0448257e846e97eeed8a4d4f3e275bc.tar.gz libmicrohttpd-84905a4df0448257e846e97eeed8a4d4f3e275bc.zip |
http_chunked_compression example: clarify and improve readability
-rw-r--r-- | src/examples/http_chunked_compression.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/examples/http_chunked_compression.c b/src/examples/http_chunked_compression.c index 7ccd535e..6c55ef5f 100644 --- a/src/examples/http_chunked_compression.c +++ b/src/examples/http_chunked_compression.c | |||
@@ -88,30 +88,32 @@ read_cb (void *cls, uint64_t pos, char *mem, size_t size) | |||
88 | struct Holder *holder = cls; | 88 | struct Holder *holder = cls; |
89 | void *src; | 89 | void *src; |
90 | void *buf; | 90 | void *buf; |
91 | ssize_t ret; | ||
91 | src = malloc (size); | 92 | src = malloc (size); |
92 | if (NULL == src) | 93 | if (NULL == src) |
93 | return MHD_CONTENT_READER_END_WITH_ERROR; | 94 | return MHD_CONTENT_READER_END_WITH_ERROR; |
94 | size = fread (src, 1, size, holder->file); | 95 | ret = fread (src, 1, size, holder->file); |
95 | if ((ssize_t) size < 0) | 96 | if (ret < 0) |
96 | { | 97 | { |
97 | size = MHD_CONTENT_READER_END_WITH_ERROR; | 98 | ret = MHD_CONTENT_READER_END_WITH_ERROR; |
98 | goto done; | 99 | goto done; |
99 | } | 100 | } |
100 | if (0 == size) | 101 | if (0 == size) |
101 | { | 102 | { |
102 | size = MHD_CONTENT_READER_END_OF_STREAM; | 103 | ret = MHD_CONTENT_READER_END_OF_STREAM; |
103 | goto done; | 104 | goto done; |
104 | } | 105 | } |
105 | if (MHD_YES != compress_buf (&holder->stream, src, size, &pos, &buf, &size, holder->buf)) | 106 | if (MHD_YES != compress_buf (&holder->stream, src, ret, &pos, &buf, &size, holder->buf)) |
106 | size = MHD_CONTENT_READER_END_WITH_ERROR; | 107 | ret = MHD_CONTENT_READER_END_WITH_ERROR; |
107 | else | 108 | else |
108 | { | 109 | { |
109 | memcpy (mem, buf, size); | 110 | memcpy (mem, buf, size); |
111 | ret = size; | ||
110 | } | 112 | } |
111 | free (buf); /* Buf may be set even on error return. */ | 113 | free (buf); /* Buf may be set even on error return. */ |
112 | done: | 114 | done: |
113 | free (src); | 115 | free (src); |
114 | return size; | 116 | return ret; |
115 | } | 117 | } |
116 | 118 | ||
117 | static void | 119 | static void |