From 805b1589f06e4eba4276cbe5d41a5246740499d2 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Sat, 2 Jan 2021 19:22:07 +0800 Subject: [PATCH] Improve the file response performance Signed-off-by: Jianhui Zhao --- src/buffer | 2 +- src/connection.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/buffer b/src/buffer index 84e1b93..1bd1b6d 160000 --- a/src/buffer +++ b/src/buffer @@ -1 +1 @@ -Subproject commit 84e1b93c110b8a886fadab0563319506edb66741 +Subproject commit 1bd1b6d192eda9e5bc24582e7ef3a4a017f9b064 diff --git a/src/connection.c b/src/connection.c index 8e8b647..3d2b452 100644 --- a/src/connection.c +++ b/src/connection.c @@ -66,6 +66,7 @@ static void conn_send_file(struct uh_connection *conn, const char *path) { struct uh_connection_internal *conni = (struct uh_connection_internal *)conn; struct stat st; + int ret; conni->file.fd = open(path, O_RDONLY); @@ -73,6 +74,10 @@ static void conn_send_file(struct uh_connection *conn, const char *path) conni->file.size = st.st_size; + /* If the file is not greater than 8K, then append it to the HTTP head, send once */ + ret = buffer_put_fd(&conni->wb, conni->file.fd, 8192, NULL); + conni->file.size -= ret; + ev_io_start(conni->srv->loop, &conni->iow); }