Browse Source

[core] http_chunk_append_file_ref_range()

http_chunk_append_file_ref() and http_chunk_append_file_ref_range()
to take stat_cache_entry ref and append FILE_CHUNK
master
Glenn Strauss 3 months ago
parent
commit
9078cc4ce8
2 changed files with 38 additions and 0 deletions
  1. +34
    -0
      src/http_chunk.c
  2. +4
    -0
      src/http_chunk.h

+ 34
- 0
src/http_chunk.c View File

@ -92,6 +92,26 @@ static int http_chunk_append_read_fd_range(request_st * const r, const buffer *
return (rd >= 0) ? 0 : -1;
}
void http_chunk_append_file_ref_range(request_st * const r, stat_cache_entry * const sce, const off_t offset, const off_t len) {
chunkqueue * const cq = &r->write_queue;
if (r->resp_send_chunked)
http_chunk_len_append(cq, (uintmax_t)len);
const buffer * const fn = &sce->name;
const int fd = sce->fd;
chunkqueue_append_file_fd(cq, fn, fd, offset, len);
if (fd >= 0) {
chunk * const d = cq->last;
d->file.ref = sce;
d->file.refchg = stat_cache_entry_refchg;
stat_cache_entry_refchg(sce, 1);
}
if (r->resp_send_chunked)
chunkqueue_append_mem(cq, CONST_STR_LEN("\r\n"));
}
void http_chunk_append_file_fd_range(request_st * const r, const buffer * const fn, const int fd, const off_t offset, const off_t len) {
chunkqueue * const cq = &r->write_queue;
@ -145,6 +165,20 @@ int http_chunk_append_file_fd(request_st * const r, const buffer * const fn, con
return rc;
}
int http_chunk_append_file_ref(request_st * const r, stat_cache_entry * const sce) {
const off_t sz = sce->st.st_size;
if (sz > 32768 || !r->resp_send_chunked) {
http_chunk_append_file_ref_range(r, sce, 0, sz);
return 0;
}
/*(read small files into memory)*/
const buffer * const fn = &sce->name;
const int fd = sce->fd;
int rc = (0 != sz) ? http_chunk_append_read_fd_range(r,fn,fd,0,sz) : 0;
return rc;
}
static int http_chunk_append_to_tempfile(request_st * const r, const char * const mem, const size_t len) {
chunkqueue * const cq = &r->write_queue;
log_error_st * const errh = r->conf.errh;


+ 4
- 0
src/http_chunk.h View File

@ -6,6 +6,8 @@
#include "buffer.h"
#include "chunk.h"
struct stat_cache_entry; /* declaration */
int http_chunk_append_mem(request_st *r, const char * mem, size_t len); /* copies memory */
int http_chunk_append_buffer(request_st *r, buffer *mem); /* may reset "mem" */
int http_chunk_decode_append_mem(request_st * const r, const char * const mem, const size_t len);
@ -13,8 +15,10 @@ int http_chunk_decode_append_buffer(request_st * const r, buffer * const mem); /
int http_chunk_transfer_cqlen(request_st *r, chunkqueue *src, size_t len);
int http_chunk_append_file(request_st *r, const buffer *fn); /* copies "fn" */
int http_chunk_append_file_fd(request_st *r, const buffer *fn, int fd, off_t sz);
int http_chunk_append_file_ref(request_st *r, struct stat_cache_entry *sce); /* copies "fn" */
int http_chunk_append_file_range(request_st *r, const buffer *fn, off_t offset, off_t len); /* copies "fn" */
void http_chunk_append_file_fd_range(request_st *r, const buffer *fn, int fd, off_t offset, off_t len); /* copies "fn" */
void http_chunk_append_file_ref_range(request_st *r, struct stat_cache_entry *sce, off_t offset, off_t len); /* copies "fn" */
void http_chunk_close(request_st *r);
#endif

Loading…
Cancel
Save