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) (void *p, void *buf, size_t count);
51 typedef ssize_t(*writel)(void *p, const void *buf, size_t count);
52 typedef off_t (*seekl) (void *p, off_t offset, int whence);
53 typedef void (*closel)(void *p);
54 typedef void (*destroyl)(void *p);
55 typedef ssize_t(*sizel) (void *p);
57 extern char *io_type_names[];
60 typedef struct _io_blink {
63 size_t len; /* How large is this buffer = BBZIS for now */
64 struct _io_blink *next;
65 struct _io_blink *prev;
69 /* Structures that describe callback interfaces */
87 off_t offset; /* Offset of the source - not used */
88 off_t length; /* Total length of chain in bytes */
89 io_blink *head; /* Start of chain */
90 io_blink *tail; /* End of chain */
91 off_t tfill; /* End of stream in last link */
92 io_blink *cp; /* Current element of list */
93 off_t cpos; /* Offset within the current */
94 off_t gpos; /* Global position in stream */
98 off_t offset; /* Offset of the source - not used */
99 off_t cpos; /* Offset within the current */
104 /* Structures to describe data sources */
112 io_type type; /* Must be first parameter */
113 char *name; /* Data source name */
116 closebufp closecb; /* free memory mapped segment or decrement refcount */
121 io_type type; /* Must be first parameter */
122 char *name; /* Data source name */
123 void *p; /* Callback data */
138 typedef struct _io_glue {
140 int flags; /* Flags */
141 void *exdata; /* Pair specific data */
149 void io_obj_setp_buffer(io_obj *io, char *p, size_t len, closebufp closecb, void *closedata);
150 void io_obj_setp_cb (io_obj *io, void *p, readl readcb, writel writecb, seekl seekcb);
151 void io_obj_setp_cb2 (io_obj *io, void *p, readl readcb, writel writecb, seekl seekcb, closel closecb, destroyl destroycb);
152 void io_glue_commit_types(io_glue *ig);
153 void io_glue_gettypes (io_glue *ig, int reqmeth);
157 io_glue *io_new_fd(int fd);
158 io_glue *io_new_bufchain(void);
159 io_glue *io_new_buffer(char *data, size_t len, closebufp closecb, void *closedata);
160 io_glue *io_new_cb(void *p, readl readcb, writel writecb, seekl seekcb, closel closecb, destroyl destroycb);
161 size_t io_slurp(io_glue *ig, unsigned char **c);
162 void io_glue_DESTROY(io_glue *ig);
164 #endif /* _IOLAYER_H_ */