acl  3.5.3.0
acl_vbuf.h
浏览该文件的文档.
1 #ifndef ACL_VBUF_INCLUDE_H
2 #define ACL_VBUF_INCLUDE_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include "acl_define.h"
9 
10 typedef struct ACL_VBUF ACL_VBUF;
11 typedef int (*ACL_VBUF_GET_READY_FN) (ACL_VBUF *);
12 typedef int (*ACL_VBUF_PUT_READY_FN) (ACL_VBUF *);
13 typedef int (*ACL_VBUF_SPACE_FN) (ACL_VBUF *, ssize_t);
14 
15 struct ACL_VBUF {
16  unsigned char *data; /* variable-length buffer */
17  unsigned char *ptr; /* read/write position */
18  ssize_t len; /* buffer length */
19  ssize_t cnt; /* bytes left to read/write */
20  unsigned flags; /* status, see below */
21  ACL_FILE_HANDLE fd;
22 #if defined(_WIN32) || defined(_WIN64)
23  ACL_FILE_HANDLE hmap;
24 #endif
25  ACL_VBUF_GET_READY_FN get_ready; /* read buffer empty action */
26  ACL_VBUF_PUT_READY_FN put_ready; /* write buffer full action */
27  ACL_VBUF_SPACE_FN space; /* request for buffer space */
28  /* void *ctx; */
29 };
30 
31  /*
32  * Typically, an application will embed a VBUF structure into a larger
33  * structure that also contains application-specific members. This approach
34  * gives us the best of both worlds. The application can still use the
35  * generic VBUF primitives for reading and writing VBUFs. The macro below
36  * transforms a pointer from VBUF structure to the structure that contains
37  * it.
38  */
39 #define ACL_VBUF_TO_APPL(vbuf_ptr,app_type,vbuf_member) \
40  ((app_type *) (((char *) (vbuf_ptr)) - offsetof(app_type,vbuf_member)))
41 
42  /*
43  * Buffer status management.
44  */
45 #define ACL_VBUF_FLAG_ERR (1<<0) /* some I/O error */
46 #define ACL_VBUF_FLAG_EOF (1<<1) /* end of data */
47 #define ACL_VBUF_FLAG_TIMEOUT (1<<2) /* timeout error */
48 #define ACL_VBUF_FLAG_BAD \
49  (ACL_VBUF_FLAG_ERR | ACL_VBUF_FLAG_EOF | ACL_VBUF_FLAG_TIMEOUT)
50 #define ACL_VBUF_FLAG_FIXED (1<<3) /* fixed-size buffer */
51 
52 #define acl_vbuf_error(v) ((v)->flags & ACL_VBUF_FLAG_BAD)
53 #define acl_vbuf_eof(v) ((v)->flags & ACL_VBUF_FLAG_EOF)
54 #define acl_vbuf_timeout(v) ((v)->flags & ACL_VBUF_FLAG_TIMEOUT)
55 #define acl_vbuf_clearerr(v) ((v)->flags &= ~ACL_VBUF_FLAG_BAD)
56 
57  /*
58  * Buffer I/O-like operations and results.
59  */
60 #define ACL_VBUF_GET(v) ((v)->cnt < 0 ? ++(v)->cnt, \
61  (int) *(v)->ptr++ : acl_vbuf_get(v))
62 
63 #define ACL_VBUF_PUT(v,c) ((v)->cnt > 0 ? --(v)->cnt, \
64  (int) (*(v)->ptr++ = (c)) : acl_vbuf_put((v),(c)))
65 
66 #define ACL_VBUF_SPACE(v,n) ((v)->space((v),(n)))
67 
68 #define ACL_VBUF_CHARAT(v, offset) ((int) (v).data[offset])
69 
70 #define ACL_VBUF_EOF (-1) /* no more space or data */
71 
72 ACL_API int acl_vbuf_get(ACL_VBUF *);
73 ACL_API int acl_vbuf_put(ACL_VBUF *, int);
74 ACL_API int acl_vbuf_unget(ACL_VBUF *, int);
75 ACL_API int acl_vbuf_read(ACL_VBUF *, char *, int);
76 ACL_API int acl_vbuf_write(ACL_VBUF *, const char *, int);
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif
ACL_FILE_HANDLE fd
Definition: acl_vbuf.h:21
int(* ACL_VBUF_SPACE_FN)(ACL_VBUF *, ssize_t)
Definition: acl_vbuf.h:13
int(* ACL_VBUF_PUT_READY_FN)(ACL_VBUF *)
Definition: acl_vbuf.h:12
ACL_API int acl_vbuf_get(ACL_VBUF *)
int(* ACL_VBUF_GET_READY_FN)(ACL_VBUF *)
Definition: acl_vbuf.h:11
unsigned char * data
Definition: acl_vbuf.h:16
ssize_t len
Definition: acl_vbuf.h:18
ssize_t cnt
Definition: acl_vbuf.h:19
ACL_VBUF_PUT_READY_FN put_ready
Definition: acl_vbuf.h:26
ACL_API int acl_vbuf_read(ACL_VBUF *, char *, int)
ACL_API int acl_vbuf_put(ACL_VBUF *, int)
unsigned char * ptr
Definition: acl_vbuf.h:17
unsigned flags
Definition: acl_vbuf.h:20
ACL_VBUF_SPACE_FN space
Definition: acl_vbuf.h:27
ACL_API int acl_vbuf_unget(ACL_VBUF *, int)
ACL_API int acl_vbuf_write(ACL_VBUF *, const char *, int)
ACL_VBUF_GET_READY_FN get_ready
Definition: acl_vbuf.h:25