From fc740649843584f23cf47f09c673e0e1e425de64 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 19 Jul 2020 16:19:18 +0000 Subject: [PATCH] fixed a bug in handling sendfile in mio.c --- mio/lib/http-fil.c | 2 +- mio/lib/mio.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/mio/lib/http-fil.c b/mio/lib/http-fil.c index a1c4f73..352d46f 100644 --- a/mio/lib/http-fil.c +++ b/mio/lib/http-fil.c @@ -490,7 +490,7 @@ static int file_state_send_contents_to_client (file_state_t* file_state) if (1 /*mio_dev_sck_sendfileok(file_state->client->sck)*/) { - if (lim > 0xFFFF) lim = 0xFFFF; /* TODO: change this... */ + if (lim > 0x7FFF0000) lim = 0x7FFF0000; /* TODO: change this... */ if (file_state_sendfile_to_client(file_state, file_state->cur_offset, lim) <= -1) return -1; file_state->cur_offset += lim; } diff --git a/mio/lib/mio.c b/mio/lib/mio.c index f1e3f77..26cf1b9 100644 --- a/mio/lib/mio.c +++ b/mio/lib/mio.c @@ -468,13 +468,20 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int else if (x == 0) { /* keep the left-over */ - MIO_MEMMOVE (q->ptr, uptr, urem); + if (!q->sendfile) MIO_MEMMOVE (q->ptr, uptr, urem); q->len = urem; break; } else { - uptr += ulen; + if (q->sendfile) + { + ((wq_sendfile_data_t*)(q->ptr))->foff += ulen; + } + else + { + uptr += ulen; + } urem -= ulen; if (urem <= 0) @@ -1720,7 +1727,6 @@ static int __dev_sendfile (mio_dev_t* dev, mio_syshnd_t in_fd, mio_foff_t foff, return 1; /* written immediately and called on_write callback. but this line will never be reached */ enqueue_data: -printf ("queueing sendfiel...\n"); return __enqueue_pending_sendfile(dev, len, urem, uoff, in_fd, tmout, wrctx, MIO_NULL); enqueue_completed_write: