Skip to content

Commit

Permalink
Improve the file response performance
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Jan 2, 2021
1 parent f32ae11 commit 805b158
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/buffer
Submodule buffer updated 1 files
+5 −2 buffer.c
5 changes: 5 additions & 0 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ 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);

fstat(conni->file.fd, &st);

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);
}

Expand Down

0 comments on commit 805b158

Please sign in to comment.