2005-02-20 14:27:00 +00:00
|
|
|
#ifndef _CHUNK_H_
|
|
|
|
#define _CHUNK_H_
|
2016-03-19 15:14:35 +00:00
|
|
|
#include "first.h"
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
#include "buffer.h"
|
2005-11-01 07:50:08 +00:00
|
|
|
#include "array.h"
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
typedef struct chunk {
|
2015-02-08 12:37:10 +00:00
|
|
|
enum { MEM_CHUNK, FILE_CHUNK } type;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-10-24 11:36:22 +00:00
|
|
|
buffer *mem; /* either the storage of the mem-chunk or the read-ahead buffer */
|
2005-09-14 08:00:33 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
/* filechunk */
|
2005-10-24 11:36:22 +00:00
|
|
|
buffer *name; /* name of the file */
|
|
|
|
off_t start; /* starting offset in the file */
|
|
|
|
off_t length; /* octets to send from the starting offset */
|
2005-09-14 08:00:33 +00:00
|
|
|
|
|
|
|
int fd;
|
2006-10-04 13:26:23 +00:00
|
|
|
struct {
|
2005-10-24 11:36:22 +00:00
|
|
|
char *start; /* the start pointer of the mmap'ed area */
|
|
|
|
size_t length; /* size of the mmap'ed area */
|
|
|
|
off_t offset; /* start is <n> octet away from the start of the file */
|
2005-09-14 08:00:33 +00:00
|
|
|
} mmap;
|
2005-09-26 08:53:58 +00:00
|
|
|
|
2005-10-24 11:36:22 +00:00
|
|
|
int is_temp; /* file is temporary and will be deleted if on cleanup */
|
2005-09-14 08:00:33 +00:00
|
|
|
} file;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2015-08-22 16:00:59 +00:00
|
|
|
/* the size of the chunk is either:
|
|
|
|
* - mem-chunk: buffer_string_length(chunk::mem)
|
|
|
|
* - file-chunk: chunk::file.length
|
|
|
|
*/
|
|
|
|
off_t offset; /* octets sent from this chunk */
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
struct chunk *next;
|
|
|
|
} chunk;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
chunk *first;
|
|
|
|
chunk *last;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
chunk *unused;
|
2005-09-08 10:00:32 +00:00
|
|
|
size_t unused_chunks;
|
2005-09-14 08:00:33 +00:00
|
|
|
|
2015-11-07 12:51:14 +00:00
|
|
|
off_t bytes_in, bytes_out;
|
2005-11-01 07:50:08 +00:00
|
|
|
|
2015-11-07 12:51:14 +00:00
|
|
|
array *tempdirs;
|
|
|
|
unsigned int upload_temp_file_size;
|
2016-04-08 04:39:50 +00:00
|
|
|
unsigned int tempdir_idx;
|
2005-02-20 14:27:00 +00:00
|
|
|
} chunkqueue;
|
|
|
|
|
|
|
|
chunkqueue *chunkqueue_init(void);
|
2015-11-07 12:51:14 +00:00
|
|
|
void chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs, unsigned int upload_temp_file_size);
|
2015-02-08 19:10:36 +00:00
|
|
|
void chunkqueue_append_file(chunkqueue *cq, buffer *fn, off_t offset, off_t len); /* copies "fn" */
|
2016-03-30 10:39:33 +00:00
|
|
|
void chunkqueue_append_file_fd(chunkqueue *cq, buffer *fn, int fd, off_t offset, off_t len); /* copies "fn" */
|
2015-02-08 19:10:36 +00:00
|
|
|
void chunkqueue_append_mem(chunkqueue *cq, const char *mem, size_t len); /* copies memory */
|
|
|
|
void chunkqueue_append_buffer(chunkqueue *cq, buffer *mem); /* may reset "mem" */
|
|
|
|
void chunkqueue_prepend_buffer(chunkqueue *cq, buffer *mem); /* may reset "mem" */
|
|
|
|
|
2016-05-25 20:45:09 +00:00
|
|
|
struct server; /*(declaration)*/
|
|
|
|
int chunkqueue_append_mem_to_tempfile(struct server *srv, chunkqueue *cq, const char *mem, size_t len);
|
|
|
|
|
2015-02-08 19:10:36 +00:00
|
|
|
/* functions to handle buffers to read into: */
|
|
|
|
/* return a pointer to a buffer in *mem with size *len;
|
|
|
|
* it should be at least min_size big, and use alloc_size if
|
|
|
|
* new memory is allocated.
|
|
|
|
* modifying the chunkqueue invalidates the memory area.
|
|
|
|
* should always be followed by chunkqueue_get_memory(),
|
|
|
|
* even if nothing was read.
|
|
|
|
* pass 0 for min_size/alloc_size for default values
|
|
|
|
*/
|
|
|
|
void chunkqueue_get_memory(chunkqueue *cq, char **mem, size_t *len, size_t min_size, size_t alloc_size);
|
|
|
|
/* append first len bytes of the memory queried with
|
|
|
|
* chunkqueue_get_memory to the chunkqueue
|
|
|
|
*/
|
|
|
|
void chunkqueue_use_memory(chunkqueue *cq, size_t len);
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2015-08-22 16:00:59 +00:00
|
|
|
/* mark first "len" bytes as written (incrementing chunk offsets)
|
|
|
|
* and remove finished chunks
|
|
|
|
*/
|
|
|
|
void chunkqueue_mark_written(chunkqueue *cq, off_t len);
|
|
|
|
|
2015-02-08 12:37:10 +00:00
|
|
|
void chunkqueue_remove_finished_chunks(chunkqueue *cq);
|
|
|
|
|
|
|
|
void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len);
|
2015-02-08 19:10:36 +00:00
|
|
|
struct server;
|
|
|
|
int chunkqueue_steal_with_tempfiles(struct server *srv, chunkqueue *dest, chunkqueue *src, off_t len);
|
2005-09-08 10:00:32 +00:00
|
|
|
|
2015-02-08 19:10:36 +00:00
|
|
|
off_t chunkqueue_length(chunkqueue *cq);
|
|
|
|
void chunkqueue_free(chunkqueue *cq);
|
|
|
|
void chunkqueue_reset(chunkqueue *cq);
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2015-02-08 19:10:36 +00:00
|
|
|
int chunkqueue_is_empty(chunkqueue *cq);
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
#endif
|