diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-09-07 16:01:37 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-09-07 16:01:37 +0200 |
| commit | 6c7faa7f9063aca15345c9aeb95d651a5fe983f9 (patch) | |
| tree | 6a24cc498535126824bd7a347ae2d3026b4568c4 /http.c | |
| parent | f9e3516f5026babdea65e4cb6bb3756f0f8dd25a (diff) | |
http.c: Use BUFSIZ instead of arbitrary value
According to C99 7.19.1p3:
BUFSIZ is a macro that expands to an integer constant expression that is
the size of the buffer used by the setbuf function.
In other words, this means BUFSIZ is the most optimal length for a
buffer that reads a file into memory in chunks using fread(3).
Note: the number of bytes sent to the client might be less than BUFSIZ,
so this would act as a bottleneck, no matter how large the buffer passed
to fread(3) is.
Diffstat (limited to 'http.c')
| -rw-r--r-- | http.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -644,7 +644,7 @@ static int write_body_file(struct http_ctx *const h, bool *const close) struct write_ctx *const w = &h->wctx; const struct http_response *const r = &w->r; const unsigned long long left = r->n - w->n; - char buf[1024]; + char buf[BUFSIZ]; const size_t rem = left > sizeof buf ? sizeof buf : left; if (!fread(buf, 1, rem, r->f)) |
