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 enum { FDSEEK, FDNOSEEK, BUFFER, CBSEEK, CBNOSEEK, BUFCHAIN } io_type;
33 typedef struct i_io_glue_t i_io_glue_t;
35 /* compatibility for now */
36 typedef i_io_glue_t io_glue;
38 /* Callbacks we give out */
40 typedef ssize_t(*readp) (io_glue *ig, void *buf, size_t count);
41 typedef ssize_t(*writep)(io_glue *ig, const void *buf, size_t count);
42 typedef off_t (*seekp) (io_glue *ig, off_t offset, int whence);
43 typedef void (*closep)(io_glue *ig);
44 typedef ssize_t(*sizep) (io_glue *ig);
46 typedef void (*closebufp)(void *p);
49 /* Callbacks we get */
51 typedef ssize_t(*readl) (void *p, void *buf, size_t count);
52 typedef ssize_t(*writel)(void *p, const void *buf, size_t count);
53 typedef off_t (*seekl) (void *p, off_t offset, int whence);
54 typedef void (*closel)(void *p);
55 typedef void (*destroyl)(void *p);
56 typedef ssize_t(*sizel) (void *p);
58 extern char *io_type_names[];
62 /* Structures to describe data sources */
70 io_type type; /* Must be first parameter */
71 char *name; /* Data source name */
74 closebufp closecb; /* free memory mapped segment or decrement refcount */
79 io_type type; /* Must be first parameter */
80 char *name; /* Data source name */
81 void *p; /* Callback data */
98 int flags; /* Flags */
99 void *exdata; /* Pair specific data */
107 void io_glue_commit_types(io_glue *ig);
108 void io_glue_gettypes (io_glue *ig, int reqmeth);
112 io_glue *io_new_fd(int fd);
113 io_glue *io_new_bufchain(void);
114 io_glue *io_new_buffer(char *data, size_t len, closebufp closecb, void *closedata);
115 io_glue *io_new_cb(void *p, readl readcb, writel writecb, seekl seekcb, closel closecb, destroyl destroycb);
116 size_t io_slurp(io_glue *ig, unsigned char **c);
117 void io_glue_DESTROY(io_glue *ig);
119 #define i_io_type(ig) ((ig)->source.ig_type)
121 #endif /* _IOLAYER_H_ */