forked from xavi/libweb
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:
parent
f9e3516f50
commit
6c7faa7f90
2
http.c
2
http.c
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue