improve conn_send_file
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
1 parent
b0bed67434
commit
de6bd1bf92
2 files changed
+6
-3
No files matched your search
+5
-2
@@ -62,13 +62,16 @@ static void conn_send(struct uh_connection *conn, const void *data, ssize_t len)
|
||||
ev_io_start(conni->srv->loop, &conni->iow);
|
||||
}
|
||||
|
||||
static void conn_send_file(struct uh_connection *conn, const char *path, size_t offset, size_t len)
|
||||
static void conn_send_file(struct uh_connection *conn, const char *path, size_t offset, ssize_t len)
|
||||
{
|
||||
struct uh_connection_internal *conni = (struct uh_connection_internal *)conn;
|
||||
size_t min = 8192;
|
||||
struct stat st;
|
||||
int fd;
|
||||
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
uh_log_err("open: %s\n", strerror(errno));
|
||||
@@ -85,7 +88,7 @@ static void conn_send_file(struct uh_connection *conn, const char *path, size_t
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
st.st_size -= offset;
|
||||
|
||||
if (len == 0 || len > st.st_size)
|
||||
if (len < 0 || len > st.st_size)
|
||||
len = st.st_size;
|
||||
|
||||
/* If the file is not greater than 8K, then append it to the HTTP head, send once */
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ struct uh_connection {
|
||||
*/
|
||||
void (*done)(struct uh_connection *conn);
|
||||
void (*send)(struct uh_connection *conn, const void *data, ssize_t len);
|
||||
void (*send_file)(struct uh_connection *conn, const char *path, size_t offset, size_t len);
|
||||
void (*send_file)(struct uh_connection *conn, const char *path, size_t offset, ssize_t len);
|
||||
void (*printf)(struct uh_connection *conn, const char *format, ...);
|
||||
void (*vprintf)(struct uh_connection *conn, const char *format, va_list arg);
|
||||
void (*send_status_line)(struct uh_connection *conn, int code, const char *extra_headers);
|
||||
|
||||
Reference in new issue
Block a user