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
|
|
|
|
2017-08-09 02:51:32 +00:00
|
|
|
#ifdef _AIX /*(AIX might #define mmap mmap64)*/
|
|
|
|
#include "sys-mmap.h"
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2019-11-25 06:54:08 +00:00
|
|
|
struct log_error_st; /*(declaration)*/
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
typedef struct chunk {
|
2018-11-07 05:36:52 +00:00
|
|
|
struct chunk *next;
|
2015-02-08 12:37:10 +00:00
|
|
|
enum { MEM_CHUNK, FILE_CHUNK } type;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2018-11-07 05:36:52 +00:00
|
|
|
buffer *mem; /* either the storage of the mem-chunk or the name of the file */
|
|
|
|
|
|
|
|
/* 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 */
|
2005-09-14 08:00:33 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
/* filechunk */
|
2005-10-24 11:36:22 +00:00
|
|
|
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;
|
2018-11-07 05:36:52 +00:00
|
|
|
int is_temp; /* file is temporary and will be deleted if on cleanup */
|
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;
|
|
|
|
} file;
|
2005-02-20 14:27:00 +00:00
|
|
|
} chunk;
|
|
|
|
|
2020-01-08 05:26:12 +00:00
|
|
|
typedef struct chunkqueue {
|
2005-02-20 14:27:00 +00:00
|
|
|
chunk *first;
|
|
|
|
chunk *last;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2015-11-07 12:51:14 +00:00
|
|
|
off_t bytes_in, bytes_out;
|
2005-11-01 07:50:08 +00:00
|
|
|
|
2019-11-16 01:26:54 +00:00
|
|
|
const array *tempdirs;
|
2019-03-16 05:39:59 +00:00
|
|
|
off_t 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;
|
|
|
|
|
2019-10-09 03:31:34 +00:00
|
|
|
__attribute_returns_nonnull__
|
2018-11-07 04:35:09 +00:00
|
|
|
buffer * chunk_buffer_acquire(void);
|
2019-10-09 03:31:34 +00:00
|
|
|
|
2018-11-07 04:35:09 +00:00
|
|
|
void chunk_buffer_release(buffer *b);
|
|
|
|
|
|
|
|
void chunkqueue_chunk_pool_clear(void);
|
|
|
|
void chunkqueue_chunk_pool_free(void);
|
|
|
|
|
2019-10-09 03:31:34 +00:00
|
|
|
__attribute_returns_nonnull__
|
2005-02-20 14:27:00 +00:00
|
|
|
chunkqueue *chunkqueue_init(void);
|
2019-10-09 03:31:34 +00:00
|
|
|
|
2018-11-18 04:50:12 +00:00
|
|
|
void chunkqueue_set_chunk_size (size_t sz);
|
2017-01-24 02:01:58 +00:00
|
|
|
void chunkqueue_set_tempdirs_default_reset (void);
|
2019-11-16 01:26:54 +00:00
|
|
|
void chunkqueue_set_tempdirs_default (const array *tempdirs, off_t upload_temp_file_size);
|
2020-01-18 03:18:30 +00:00
|
|
|
void chunkqueue_set_tempdirs(chunkqueue * restrict cq, const array * restrict tempdirs, off_t upload_temp_file_size);
|
|
|
|
void chunkqueue_append_file(chunkqueue * restrict cq, const buffer * restrict fn, off_t offset, off_t len); /* copies "fn" */
|
|
|
|
void chunkqueue_append_file_fd(chunkqueue * restrict cq, const buffer * restrict fn, int fd, off_t offset, off_t len); /* copies "fn" */
|
|
|
|
void chunkqueue_append_mem(chunkqueue * restrict cq, const char * restrict mem, size_t len); /* copies memory */
|
|
|
|
void chunkqueue_append_mem_min(chunkqueue * restrict cq, const char * restrict mem, size_t len); /* copies memory */
|
|
|
|
void chunkqueue_append_buffer(chunkqueue * restrict cq, buffer * restrict mem); /* may reset "mem" */
|
|
|
|
void chunkqueue_append_chunkqueue(chunkqueue * restrict cq, chunkqueue * restrict src);
|
2015-02-08 19:10:36 +00:00
|
|
|
|
2019-10-09 03:31:34 +00:00
|
|
|
__attribute_returns_nonnull__
|
2018-11-12 05:29:55 +00:00
|
|
|
buffer * chunkqueue_prepend_buffer_open_sz(chunkqueue *cq, size_t sz);
|
2019-10-09 03:31:34 +00:00
|
|
|
|
|
|
|
__attribute_returns_nonnull__
|
2018-10-27 02:03:31 +00:00
|
|
|
buffer * chunkqueue_prepend_buffer_open(chunkqueue *cq);
|
2019-10-09 03:31:34 +00:00
|
|
|
|
2018-10-27 02:03:31 +00:00
|
|
|
void chunkqueue_prepend_buffer_commit(chunkqueue *cq);
|
2019-10-09 03:31:34 +00:00
|
|
|
|
|
|
|
__attribute_returns_nonnull__
|
2018-11-12 05:29:55 +00:00
|
|
|
buffer * chunkqueue_append_buffer_open_sz(chunkqueue *cq, size_t sz);
|
2019-10-09 03:31:34 +00:00
|
|
|
|
|
|
|
__attribute_returns_nonnull__
|
2018-10-27 18:01:58 +00:00
|
|
|
buffer * chunkqueue_append_buffer_open(chunkqueue *cq);
|
2019-10-09 03:31:34 +00:00
|
|
|
|
2018-10-27 18:01:58 +00:00
|
|
|
void chunkqueue_append_buffer_commit(chunkqueue *cq);
|
2018-10-27 02:03:31 +00:00
|
|
|
|
2020-01-18 03:18:30 +00:00
|
|
|
int chunkqueue_append_mem_to_tempfile(chunkqueue * restrict cq, const char * restrict mem, size_t len, struct log_error_st * const restrict errh);
|
2016-05-25 20:45:09 +00:00
|
|
|
|
2015-02-08 19:10:36 +00:00
|
|
|
/* functions to handle buffers to read into: */
|
2018-11-13 02:51:25 +00:00
|
|
|
/* obtain/reserve memory in chunkqueue at least len (input) size,
|
|
|
|
* return pointer to memory with len (output) available for use
|
2015-02-08 19:10:36 +00:00
|
|
|
* modifying the chunkqueue invalidates the memory area.
|
|
|
|
* should always be followed by chunkqueue_get_memory(),
|
|
|
|
* even if nothing was read.
|
2018-11-13 02:51:25 +00:00
|
|
|
* pass 0 in len for mem at least half of chunk_buf_sz
|
2015-02-08 19:10:36 +00:00
|
|
|
*/
|
2019-10-09 03:31:34 +00:00
|
|
|
__attribute_returns_nonnull__
|
2020-01-18 03:18:30 +00:00
|
|
|
char * chunkqueue_get_memory(chunkqueue * restrict cq, size_t * restrict len);
|
2018-11-13 02:51:25 +00:00
|
|
|
/* commit len bytes of mem obtained from chunkqueue_get_memory() */
|
2020-01-18 03:18:30 +00:00
|
|
|
void chunkqueue_use_memory(chunkqueue * restrict cq, chunk *ckpt, 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);
|
|
|
|
|
2020-01-18 03:18:30 +00:00
|
|
|
void chunkqueue_steal(chunkqueue * restrict dest, chunkqueue * restrict src, off_t len);
|
|
|
|
int chunkqueue_steal_with_tempfiles(chunkqueue * restrict dest, chunkqueue * restrict src, off_t len, struct log_error_st * const restrict errh);
|
2005-09-08 10:00:32 +00:00
|
|
|
|
2020-01-18 03:18:30 +00:00
|
|
|
int chunkqueue_open_file_chunk(chunkqueue * restrict cq, struct log_error_st * const restrict errh);
|
2016-12-21 11:00:32 +00:00
|
|
|
|
2019-07-14 07:37:06 +00:00
|
|
|
void chunkqueue_compact_mem(chunkqueue *cq, size_t clen);
|
|
|
|
|
2019-06-05 03:18:23 +00:00
|
|
|
__attribute_pure__
|
2015-02-08 19:10:36 +00:00
|
|
|
off_t chunkqueue_length(chunkqueue *cq);
|
2019-06-05 03:18:23 +00:00
|
|
|
|
2015-02-08 19:10:36 +00:00
|
|
|
void chunkqueue_free(chunkqueue *cq);
|
|
|
|
void chunkqueue_reset(chunkqueue *cq);
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2019-06-05 03:18:23 +00:00
|
|
|
__attribute_pure__
|
2017-10-09 04:41:06 +00:00
|
|
|
static inline int chunkqueue_is_empty(const chunkqueue *cq);
|
|
|
|
static inline int chunkqueue_is_empty(const chunkqueue *cq) {
|
|
|
|
return NULL == cq->first;
|
|
|
|
}
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
#endif
|