kore

a fork of the worlds most advanced web framework
Log | Files | Refs | README | LICENSE

commit ac6fcf8981ee4abc4ad60fd66385e9f72d4a97ee
parent 570f9ac9860b0f34e43ea3ba0bf8d099a5739bfe
Author: Joris Vink <joris@coders.se>
Date:   Mon,  9 Jul 2018 10:00:38 +0000

deal with sendfile() in newer linux kernels.

Diffstat:
Msrc/linux.c | 12+++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/linux.c b/src/linux.c @@ -276,13 +276,15 @@ kore_platform_proctitle(char *title) int kore_platform_sendfile(struct connection *c, struct netbuf *nb) { - size_t len; - ssize_t sent; off_t smin; + ssize_t sent; + size_t len, prevoff; + prevoff = nb->fd_off; smin = nb->fd_len - nb->fd_off; len = MIN(SENDFILE_PAYLOAD_MAX, smin); +resend: sent = sendfile(c->fd, nb->file_ref->fd, &nb->fd_off, len); if (sent == -1) { if (errno == EAGAIN) { @@ -290,12 +292,12 @@ kore_platform_sendfile(struct connection *c, struct netbuf *nb) return (KORE_RESULT_OK); } - if (errno == EINTR) - return (KORE_RESULT_OK); - return (KORE_RESULT_ERROR); } + if (nb->fd_off - prevoff != (size_t)len) + goto resend; + if (sent == 0 || nb->fd_off == nb->fd_len) { net_remove_netbuf(&(c->send_queue), nb); c->snb = NULL;