Annotation of embedaddon/lighttpd/src/chunk.h, revision 1.1.1.2

1.1       misho       1: #ifndef _CHUNK_H_
                      2: #define _CHUNK_H_
1.1.1.2 ! misho       3: #include "first.h"
1.1       misho       4: 
                      5: #include "buffer.h"
                      6: #include "array.h"
                      7: 
                      8: typedef struct chunk {
1.1.1.2 ! misho       9:        enum { MEM_CHUNK, FILE_CHUNK } type;
1.1       misho      10: 
                     11:        buffer *mem; /* either the storage of the mem-chunk or the read-ahead buffer */
                     12: 
                     13:        struct {
                     14:                /* filechunk */
                     15:                buffer *name; /* name of the file */
                     16:                off_t  start; /* starting offset in the file */
                     17:                off_t  length; /* octets to send from the starting offset */
                     18: 
                     19:                int    fd;
                     20:                struct {
                     21:                        char   *start; /* the start pointer of the mmap'ed area */
                     22:                        size_t length; /* size of the mmap'ed area */
                     23:                        off_t  offset; /* start is <n> octet away from the start of the file */
                     24:                } mmap;
                     25: 
                     26:                int is_temp; /* file is temporary and will be deleted if on cleanup */
                     27:        } file;
                     28: 
1.1.1.2 ! misho      29:        /* the size of the chunk is either:
        !            30:         * - mem-chunk: buffer_string_length(chunk::mem)
        !            31:         * - file-chunk: chunk::file.length
        !            32:         */
        !            33:        off_t  offset; /* octets sent from this chunk */
1.1       misho      34: 
                     35:        struct chunk *next;
                     36: } chunk;
                     37: 
                     38: typedef struct {
                     39:        chunk *first;
                     40:        chunk *last;
                     41: 
                     42:        chunk *unused;
                     43:        size_t unused_chunks;
                     44: 
1.1.1.2 ! misho      45:        off_t bytes_in, bytes_out;
1.1       misho      46: 
1.1.1.2 ! misho      47:        array *tempdirs;
        !            48:        unsigned int upload_temp_file_size;
        !            49:        unsigned int tempdir_idx;
1.1       misho      50: } chunkqueue;
                     51: 
                     52: chunkqueue *chunkqueue_init(void);
1.1.1.2 ! misho      53: void chunkqueue_set_tempdirs_default (array *tempdirs, unsigned int upload_temp_file_size);
        !            54: void chunkqueue_append_file(chunkqueue *cq, buffer *fn, off_t offset, off_t len); /* copies "fn" */
        !            55: void chunkqueue_append_file_fd(chunkqueue *cq, buffer *fn, int fd, off_t offset, off_t len); /* copies "fn" */
        !            56: void chunkqueue_append_mem(chunkqueue *cq, const char *mem, size_t len); /* copies memory */
        !            57: void chunkqueue_append_buffer(chunkqueue *cq, buffer *mem); /* may reset "mem" */
        !            58: void chunkqueue_prepend_buffer(chunkqueue *cq, buffer *mem); /* may reset "mem" */
        !            59: void chunkqueue_append_chunkqueue(chunkqueue *cq, chunkqueue *src);
        !            60: 
        !            61: struct server; /*(declaration)*/
        !            62: int chunkqueue_append_mem_to_tempfile(struct server *srv, chunkqueue *cq, const char *mem, size_t len);
        !            63: 
        !            64: /* functions to handle buffers to read into: */
        !            65: /* return a pointer to a buffer in *mem with size *len;
        !            66:  *  it should be at least min_size big, and use alloc_size if
        !            67:  *  new memory is allocated.
        !            68:  * modifying the chunkqueue invalidates the memory area.
        !            69:  * should always be followed by chunkqueue_get_memory(),
        !            70:  *  even if nothing was read.
        !            71:  * pass 0 for min_size/alloc_size for default values
        !            72:  */
        !            73: void chunkqueue_get_memory(chunkqueue *cq, char **mem, size_t *len, size_t min_size, size_t alloc_size);
        !            74: /* append first len bytes of the memory queried with
        !            75:  * chunkqueue_get_memory to the chunkqueue
        !            76:  */
        !            77: void chunkqueue_use_memory(chunkqueue *cq, size_t len);
        !            78: 
        !            79: /* mark first "len" bytes as written (incrementing chunk offsets)
        !            80:  * and remove finished chunks
        !            81:  */
        !            82: void chunkqueue_mark_written(chunkqueue *cq, off_t len);
        !            83: 
        !            84: void chunkqueue_remove_finished_chunks(chunkqueue *cq);
        !            85: 
        !            86: void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len);
        !            87: struct server;
        !            88: int chunkqueue_steal_with_tempfiles(struct server *srv, chunkqueue *dest, chunkqueue *src, off_t len);
        !            89: 
        !            90: off_t chunkqueue_length(chunkqueue *cq);
        !            91: void chunkqueue_free(chunkqueue *cq);
        !            92: void chunkqueue_reset(chunkqueue *cq);
1.1       misho      93: 
1.1.1.2 ! misho      94: int chunkqueue_is_empty(chunkqueue *cq);
1.1       misho      95: 
                     96: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>