2005-02-20 14:27:00 +00:00
|
|
|
#ifndef _CHUNK_H_
|
|
|
|
#define _CHUNK_H_
|
|
|
|
|
|
|
|
#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 {
|
|
|
|
enum { UNUSED_CHUNK, 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
|
|
|
|
|
|
|
off_t offset; /* octets sent from this chunk
|
|
|
|
the size of the chunk is either
|
2005-10-24 11:36:22 +00:00
|
|
|
- mem-chunk: mem->used - 1
|
|
|
|
- file-chunk: file.length
|
|
|
|
*/
|
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
|
|
|
|
2005-11-01 07:50:08 +00:00
|
|
|
array *tempdirs;
|
|
|
|
|
2005-09-14 08:00:33 +00:00
|
|
|
off_t bytes_in, bytes_out;
|
2005-02-20 14:27:00 +00:00
|
|
|
} chunkqueue;
|
|
|
|
|
|
|
|
chunkqueue *chunkqueue_init(void);
|
2005-11-01 07:50:08 +00:00
|
|
|
int chunkqueue_set_tempdirs(chunkqueue *c, array *tempdirs);
|
2005-02-20 14:27:00 +00:00
|
|
|
int chunkqueue_append_file(chunkqueue *c, buffer *fn, off_t offset, off_t len);
|
|
|
|
int chunkqueue_append_mem(chunkqueue *c, const char *mem, size_t len);
|
|
|
|
int chunkqueue_append_buffer(chunkqueue *c, buffer *mem);
|
2006-09-21 08:03:40 +00:00
|
|
|
int chunkqueue_append_buffer_weak(chunkqueue *c, buffer *mem);
|
2005-02-20 14:27:00 +00:00
|
|
|
int chunkqueue_prepend_buffer(chunkqueue *c, buffer *mem);
|
|
|
|
|
|
|
|
buffer * chunkqueue_get_append_buffer(chunkqueue *c);
|
|
|
|
buffer * chunkqueue_get_prepend_buffer(chunkqueue *c);
|
2005-09-26 08:53:58 +00:00
|
|
|
chunk * chunkqueue_get_append_tempfile(chunkqueue *cq);
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2005-09-08 10:00:32 +00:00
|
|
|
int chunkqueue_remove_finished_chunks(chunkqueue *cq);
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
off_t chunkqueue_length(chunkqueue *c);
|
|
|
|
off_t chunkqueue_written(chunkqueue *c);
|
|
|
|
void chunkqueue_free(chunkqueue *c);
|
|
|
|
void chunkqueue_reset(chunkqueue *c);
|
|
|
|
|
|
|
|
int chunkqueue_is_empty(chunkqueue *c);
|
|
|
|
|
|
|
|
#endif
|