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);
45 typedef void (*closebufp)(void *p);
48 /* Callbacks we get */
50 typedef ssize_t(*readl) (int fd, void *buf, size_t count);
51 typedef ssize_t(*writel)(int fd, const void *buf, size_t count);
52 typedef off_t (*seekl) (int fd, off_t offset, int whence);
53 typedef ssize_t(*sizel) (int fd);
55 extern char *io_type_names[];
58 typedef struct _io_blink {
61 size_t len; /* How large is this buffer = BBZIS for now */
62 struct _io_blink *next;
63 struct _io_blink *prev;
67 /* Structures that describe callback interfaces */
85 off_t offset; /* Offset of the source - not used */
86 off_t length; /* Total length of chain in bytes */
87 io_blink *head; /* Start of chain */
88 io_blink *tail; /* End of chain */
89 off_t tfill; /* End of stream in last link */
90 io_blink *cp; /* Current element of list */
91 off_t cpos; /* Offset within the current */
92 off_t gpos; /* Global position in stream */
96 off_t offset; /* Offset of the source - not used */
97 off_t cpos; /* Offset within the current */
102 /* Structures to describe data sources */
110 io_type type; /* Must be first parameter */
111 char *name; /* Data source name */
114 closebufp closecb; /* free memory mapped segment or decrement refcount */
119 io_type type; /* Must be first parameter */
120 char *name; /* Data source name */
121 void *p; /* Callback data */
134 typedef struct _io_glue {
136 int flags; /* Flags */
137 void *exdata; /* Pair specific data */
145 void io_obj_setp_buffer(io_obj *io, char *p, size_t len, closebufp closecb, void *closedata);
146 void io_obj_setp_cb (io_obj *io, void *p, readl readcb, writel writecb, seekl seekcb);
147 void io_glue_commit_types(io_glue *ig);
148 void io_glue_gettypes (io_glue *ig, int reqmeth);
152 io_glue *io_new_fd(int fd);
153 io_glue *io_new_bufchain(void);
154 io_glue *io_new_buffer(char *data, size_t len, closebufp closecb, void *closedata);
155 size_t io_slurp(io_glue *ig, unsigned char **c);
156 void io_glue_DESTROY(io_glue *ig);
158 #endif /* _IOLAYER_H_ */