root/trunk/src/chunk.h

Revision 2033, 2.6 kB (checked in by glen, 8 months ago)

- chunk.c patches from #1510

  • Property svn:eol-style set to native
Line 
1#ifndef _CHUNK_H_
2#define _CHUNK_H_
3
4#include "buffer.h"
5#include "array.h"
6
7typedef struct chunk {
8        enum { UNUSED_CHUNK, MEM_CHUNK, FILE_CHUNK } type;
9
10        buffer *mem; /* either the storage of the mem-chunk or the read-ahead buffer */
11
12        struct {
13                /* filechunk */
14                buffer *name; /* name of the file */
15                off_t  start; /* starting offset in the file */
16                off_t  length; /* octets to send from the starting offset */
17
18                int    fd;
19                struct {
20                        char   *start; /* the start pointer of the mmap'ed area */
21                        size_t length; /* size of the mmap'ed area */
22                        off_t  offset; /* start is <n> octets away from the start of the file */
23                } mmap;
24
25                int is_temp; /* file is temporary and will be deleted on cleanup */
26
27                struct {
28                        int fd;
29                        off_t length;
30                        off_t offset;
31                } copy;
32        } file;
33
34        off_t  offset; /* octets sent from this chunk
35                          the size of the chunk is either
36                          - mem-chunk: mem->used - 1
37                          - file-chunk: file.length
38                        */
39
40        struct {
41                off_t written;
42                int ret_val;
43        } async;
44
45        struct chunk *next;
46} chunk;
47
48typedef struct {
49        chunk *first;
50        chunk *last;
51
52        array *tempdirs;
53
54        int is_closed;   /* the input to this CQ is closed */
55
56        off_t  bytes_in, bytes_out;
57} chunkqueue;
58
59LI_API chunkqueue* chunkqueue_init(void);
60LI_API int chunkqueue_set_tempdirs(chunkqueue *c, array *tempdirs);
61LI_API int chunkqueue_append_file(chunkqueue *c, buffer *fn, off_t offset, off_t len);
62LI_API int chunkqueue_append_mem(chunkqueue *c, const char *mem, size_t len);
63LI_API int chunkqueue_append_buffer(chunkqueue *c, buffer *mem);
64LI_API int chunkqueue_prepend_buffer(chunkqueue *c, buffer *mem);
65
66LI_API buffer * chunkqueue_get_append_buffer(chunkqueue *c);
67LI_API buffer * chunkqueue_get_prepend_buffer(chunkqueue *c);
68LI_API chunk * chunkqueue_get_append_tempfile(chunkqueue *cq);
69LI_API int chunkqueue_steal_tempfile(chunkqueue *cq, chunk *in);
70LI_API off_t chunkqueue_steal_chunk(chunkqueue *cq, chunk *c);
71LI_API off_t chunkqueue_steal_chunks_len(chunkqueue *cq, chunk *c, off_t max_len);
72LI_API off_t chunkqueue_steal_all_chunks(chunkqueue *cq, chunkqueue *in);
73LI_API off_t chunkqueue_skip(chunkqueue *cq, off_t skip);
74LI_API void chunkqueue_remove_empty_last_chunk(chunkqueue *cq);
75
76LI_API int chunkqueue_remove_finished_chunks(chunkqueue *cq);
77
78LI_API off_t chunkqueue_length(chunkqueue *c);
79LI_API off_t chunkqueue_written(chunkqueue *c);
80LI_API void chunkqueue_free(chunkqueue *c);
81LI_API void chunkqueue_reset(chunkqueue *c);
82
83LI_API int chunkqueue_is_empty(chunkqueue *c);
84
85LI_API void chunkqueue_print(chunkqueue *cq);
86
87LI_API int chunk_is_done(chunk *c);
88LI_API void chunk_set_done(chunk *c);
89
90#endif
Note: See TracBrowser for help on using the browser.