5 #ifdef _AIX /*(AIX might #define mmap mmap64)*/
12 typedef struct chunk
{
14 enum { MEM_CHUNK
, FILE_CHUNK
} type
;
16 buffer
*mem
; /* either the storage of the mem-chunk or the name of the file */
18 /* the size of the chunk is either:
19 * - mem-chunk: buffer_string_length(chunk::mem)
20 * - file-chunk: chunk::file.length
22 off_t offset
; /* octets sent from this chunk */
26 off_t start
; /* starting offset in the file */
27 off_t length
; /* octets to send from the starting offset */
30 int is_temp
; /* file is temporary and will be deleted if on cleanup */
32 char *start
; /* the start pointer of the mmap'ed area */
33 size_t length
; /* size of the mmap'ed area */
34 off_t offset
; /* start is <n> octet away from the start of the file */
43 off_t bytes_in
, bytes_out
;
46 off_t upload_temp_file_size
;
47 unsigned int tempdir_idx
;
50 buffer
* chunk_buffer_acquire(void);
51 void chunk_buffer_release(buffer
*b
);
53 void chunkqueue_chunk_pool_clear(void);
54 void chunkqueue_chunk_pool_free(void);
56 chunkqueue
*chunkqueue_init(void);
57 void chunkqueue_set_chunk_size (size_t sz
);
58 void chunkqueue_set_tempdirs_default_reset (void);
59 void chunkqueue_set_tempdirs_default (array
*tempdirs
, off_t upload_temp_file_size
);
60 void chunkqueue_set_tempdirs(chunkqueue
*cq
, array
*tempdirs
, off_t upload_temp_file_size
);
61 void chunkqueue_append_file(chunkqueue
*cq
, buffer
*fn
, off_t offset
, off_t len
); /* copies "fn" */
62 void chunkqueue_append_file_fd(chunkqueue
*cq
, buffer
*fn
, int fd
, off_t offset
, off_t len
); /* copies "fn" */
63 void chunkqueue_append_mem(chunkqueue
*cq
, const char *mem
, size_t len
); /* copies memory */
64 void chunkqueue_append_mem_min(chunkqueue
*cq
, const char * mem
, size_t len
); /* copies memory */
65 void chunkqueue_append_buffer(chunkqueue
*cq
, buffer
*mem
); /* may reset "mem" */
66 void chunkqueue_append_chunkqueue(chunkqueue
*cq
, chunkqueue
*src
);
68 buffer
* chunkqueue_prepend_buffer_open_sz(chunkqueue
*cq
, size_t sz
);
69 buffer
* chunkqueue_prepend_buffer_open(chunkqueue
*cq
);
70 void chunkqueue_prepend_buffer_commit(chunkqueue
*cq
);
71 buffer
* chunkqueue_append_buffer_open_sz(chunkqueue
*cq
, size_t sz
);
72 buffer
* chunkqueue_append_buffer_open(chunkqueue
*cq
);
73 void chunkqueue_append_buffer_commit(chunkqueue
*cq
);
75 struct server
; /*(declaration)*/
76 int chunkqueue_append_mem_to_tempfile(struct server
*srv
, chunkqueue
*cq
, const char *mem
, size_t len
);
78 /* functions to handle buffers to read into: */
79 /* obtain/reserve memory in chunkqueue at least len (input) size,
80 * return pointer to memory with len (output) available for use
81 * modifying the chunkqueue invalidates the memory area.
82 * should always be followed by chunkqueue_get_memory(),
83 * even if nothing was read.
84 * pass 0 in len for mem at least half of chunk_buf_sz
86 char * chunkqueue_get_memory(chunkqueue
*cq
, size_t *len
);
87 /* commit len bytes of mem obtained from chunkqueue_get_memory() */
88 void chunkqueue_use_memory(chunkqueue
*cq
, size_t len
);
90 /* mark first "len" bytes as written (incrementing chunk offsets)
91 * and remove finished chunks
93 void chunkqueue_mark_written(chunkqueue
*cq
, off_t len
);
95 void chunkqueue_remove_finished_chunks(chunkqueue
*cq
);
97 void chunkqueue_steal(chunkqueue
*dest
, chunkqueue
*src
, off_t len
);
99 int chunkqueue_steal_with_tempfiles(struct server
*srv
, chunkqueue
*dest
, chunkqueue
*src
, off_t len
);
101 int chunkqueue_open_file_chunk(struct server
*srv
, chunkqueue
*cq
);
103 off_t
chunkqueue_length(chunkqueue
*cq
);
104 void chunkqueue_free(chunkqueue
*cq
);
105 void chunkqueue_reset(chunkqueue
*cq
);
107 static inline int chunkqueue_is_empty(const chunkqueue
*cq
);
108 static inline int chunkqueue_is_empty(const chunkqueue
*cq
) {
109 return NULL
== cq
->first
;