1
0
Fork 0

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.
This commit is contained in:
Xavier Del Campo Romero 2023-09-07 16:01:37 +02:00
parent f9e3516f50
commit 6c7faa7f90
Signed by untrusted user: xavi
GPG Key ID: 84FF3612A9BF43F2
1 changed files with 1 additions and 1 deletions

2
http.c
View File

@ -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))