5 /* How the IO layer works:
7 * Start by getting an io_glue object. Then define its
8 * datasource via io_obj_setp_buffer or io_obj_setp_cb. Before
9 * using the io_glue object be sure to call io_glue_commit_types().
10 * After that data can be read via the io_glue->readcb() method.
19 #include <sys/types.h>
21 /* #define BBSIZ 1096 */
23 #define IO_FAKE_SEEK 1<<0L
24 #define IO_TEMP_SEEK 1<<1L
27 typedef union { int i; void *p; } iorp;
29 typedef enum { FDSEEK, FDNOSEEK, BUFFER, CBSEEK, CBNOSEEK, BUFCHAIN } io_type;
37 /* Callbacks we give out */
39 typedef ssize_t(*readp) (struct _io_glue *ig, void *buf, size_t count);
40 typedef ssize_t(*writep)(struct _io_glue *ig, const void *buf, size_t count);
41 typedef off_t (*seekp) (struct _io_glue *ig, off_t offset, int whence);
42 typedef void (*closep)(struct _io_glue *ig);
43 typedef ssize_t(*sizep) (struct _io_glue *ig);
47 /* Callbacks we get */
49 typedef ssize_t(*readl) (int fd, void *buf, size_t count);
50 typedef ssize_t(*writel)(int fd, const void *buf, size_t count);
51 typedef off_t (*seekl) (int fd, off_t offset, int whence);
52 typedef ssize_t(*sizel) (int fd);
54 extern char *io_type_names[];
57 typedef struct _io_blink {
60 size_t len; /* How large is this buffer = BBZIS for now */
61 struct _io_blink *next;
62 struct _io_blink *prev;
66 /* Structures that describe callback interfaces */
84 off_t offset; /* Offset of the source - not used */
85 off_t length; /* Total length of chain in bytes */
86 io_blink *head; /* Start of chain */
87 io_blink *tail; /* End of chain */
88 off_t tfill; /* End of stream in last link */
89 io_blink *cp; /* Current element of list */
90 off_t cpos; /* Offset within the current */
91 off_t gpos; /* Global position in stream */
95 /* Structures to describe data sources */
103 io_type type; /* Must be first parameter */
104 char *name; /* Data source name */
110 io_type type; /* Must be first parameter */
111 char *name; /* Data source name */
112 void *p; /* Callback data */
125 typedef struct _io_glue {
127 int flags; /* Flags */
128 void *exdata; /* Pair specific data */
136 void io_obj_setp_buffer (io_obj *io, void *p, size_t len);
137 void io_obj_setp_cb (io_obj *io, void *p, readl readcb, writel writecb, seekl seekcb);
138 void io_glue_commit_types(io_glue *ig);
139 void io_glue_gettypes (io_glue *ig, int reqmeth);
143 io_glue *io_new_fd(int fd);
144 io_glue *io_new_bufchain();
145 size_t io_slurp(io_glue *ig, unsigned char **c);
146 void io_glue_DESTROY(io_glue *ig);
148 #endif /* _IOLAYER_H_ */