[core] set chunkqueue tempdirs at startup
[lighttpd.git] / src / chunk.h
blob651da5619c5cb376809adbba48aaa9b4ef53871c
1 #ifndef _CHUNK_H_
2 #define _CHUNK_H_
3 #include "first.h"
5 #include "buffer.h"
6 #include "array.h"
8 typedef struct chunk {
9 enum { MEM_CHUNK, FILE_CHUNK } type;
11 buffer *mem; /* either the storage of the mem-chunk or the read-ahead buffer */
13 struct {
14 /* filechunk */
15 buffer *name; /* name of the file */
16 off_t start; /* starting offset in the file */
17 off_t length; /* octets to send from the starting offset */
19 int fd;
20 struct {
21 char *start; /* the start pointer of the mmap'ed area */
22 size_t length; /* size of the mmap'ed area */
23 off_t offset; /* start is <n> octet away from the start of the file */
24 } mmap;
26 int is_temp; /* file is temporary and will be deleted if on cleanup */
27 } file;
29 /* the size of the chunk is either:
30 * - mem-chunk: buffer_string_length(chunk::mem)
31 * - file-chunk: chunk::file.length
33 off_t offset; /* octets sent from this chunk */
35 struct chunk *next;
36 } chunk;
38 typedef struct {
39 chunk *first;
40 chunk *last;
42 chunk *unused;
43 size_t unused_chunks;
45 off_t bytes_in, bytes_out;
47 array *tempdirs;
48 unsigned int upload_temp_file_size;
49 unsigned int tempdir_idx;
50 } chunkqueue;
52 chunkqueue *chunkqueue_init(void);
53 void chunkqueue_set_tempdirs_default (array *tempdirs, unsigned int upload_temp_file_size);
54 void chunkqueue_append_file(chunkqueue *cq, buffer *fn, off_t offset, off_t len); /* copies "fn" */
55 void chunkqueue_append_file_fd(chunkqueue *cq, buffer *fn, int fd, off_t offset, off_t len); /* copies "fn" */
56 void chunkqueue_append_mem(chunkqueue *cq, const char *mem, size_t len); /* copies memory */
57 void chunkqueue_append_buffer(chunkqueue *cq, buffer *mem); /* may reset "mem" */
58 void chunkqueue_prepend_buffer(chunkqueue *cq, buffer *mem); /* may reset "mem" */
59 void chunkqueue_append_chunkqueue(chunkqueue *cq, chunkqueue *src);
61 struct server; /*(declaration)*/
62 int chunkqueue_append_mem_to_tempfile(struct server *srv, chunkqueue *cq, const char *mem, size_t len);
64 /* functions to handle buffers to read into: */
65 /* return a pointer to a buffer in *mem with size *len;
66 * it should be at least min_size big, and use alloc_size if
67 * new memory is allocated.
68 * modifying the chunkqueue invalidates the memory area.
69 * should always be followed by chunkqueue_get_memory(),
70 * even if nothing was read.
71 * pass 0 for min_size/alloc_size for default values
73 void chunkqueue_get_memory(chunkqueue *cq, char **mem, size_t *len, size_t min_size, size_t alloc_size);
74 /* append first len bytes of the memory queried with
75 * chunkqueue_get_memory to the chunkqueue
77 void chunkqueue_use_memory(chunkqueue *cq, size_t len);
79 /* mark first "len" bytes as written (incrementing chunk offsets)
80 * and remove finished chunks
82 void chunkqueue_mark_written(chunkqueue *cq, off_t len);
84 void chunkqueue_remove_finished_chunks(chunkqueue *cq);
86 void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len);
87 struct server;
88 int chunkqueue_steal_with_tempfiles(struct server *srv, chunkqueue *dest, chunkqueue *src, off_t len);
90 off_t chunkqueue_length(chunkqueue *cq);
91 void chunkqueue_free(chunkqueue *cq);
92 void chunkqueue_reset(chunkqueue *cq);
94 int chunkqueue_is_empty(chunkqueue *cq);
96 #endif