1 #ifndef RH_CHUNK_H
 2 #define RH_CHUNK_H
 3 
 4 #include <sys/types.h>
 5 #include <sys/uio.h>
 6 #include "queue.h"
 7         
 8 #ifndef RH_CHUNK_IOVEC_SZ
 9 # define RH_CHUNK_IOVEC_SZ      32
10 #endif
11 
12 TAILQ_HEAD(rh_chunk_list, rh_chunk_entry);
13 
14 typedef struct rh_chunk rh_chunk_t;
15 
16 struct rh_chunk {
17         struct rh_chunk_list    list;
18         size_t                  size_in;
19         size_t                  size_out;
20 };
21 
22 enum rh_chunk_entry_type {
23         RH_CHUNK_ENTRY_UNKNOWN = 0,
24         RH_CHUNK_ENTRY_IOVEC,
25         RH_CHUNK_ENTRY_FILE
26 };
27 
28 struct rh_chunk_entry {
29         TAILQ_ENTRY(rh_chunk_entry)             list;
30         enum rh_chunk_entry_type                type;
31 
32         union {
33                 struct rh_chunk_entry_iovec     *iovec;
34                 struct rh_chunk_entry_file      *file;
35         }       data;
36 };
37 
38 struct rh_chunk_entry_iovec {
39         struct iovec    vec[RH_CHUNK_IOVEC_SZ];
40         unsigned short  offset;
41         unsigned short  used;
42         size_t          size;
43         
44         void            (*cb[RH_CHUNK_IOVEC_SZ])(void *);
45         void            *cb_arg[RH_CHUNK_IOVEC_SZ];
46 };
47 
48 struct rh_chunk_entry_file {
49         int             fd;
50         size_t          size;
51         off_t           offset;
52 
53         void            (*cb)(void *);
54         void            *cb_arg;
55 };
56 
57 void rh_chunk_init (struct rh_chunk *);
58 void rh_chunk_destroy (struct rh_chunk *);
59 void rh_chunk_reset   (struct rh_chunk *);
60 
61 int rh_chunk_done (rh_chunk_t *chunk);
62 
63 int rh_chunk_append_uint (struct rh_chunk *chunk, size_t len);
64 
65 int rh_chunk_append_buffer (struct rh_chunk *, void *, size_t,
66                 void (*)(void *), void *);
67 
68 #define RH_CHUNK_APPEND_CONST(_chunk,_str)      \
69         rh_chunk_append_buffer ((_chunk),       \
70         (_str), sizeof((_str))-1, NULL, 0 )
71 
72 int rh_chunk_append_file  (struct rh_chunk *,
73                 int fd, off_t offset, size_t size,
74                 void (*)(void *), void *);
75 
76 ssize_t rh_chunk_write (rh_chunk_t *chunk, int fd);
77 
78 #endif /* RH_CHUNK_H */


syntax highlighted by Code2HTML, v. 0.9.1