3.8.1 VBUF, VSTRING和VSTREAM结构体
来源:互联网 发布:ubuntu caffe 安装 编辑:程序博客网 时间:2024/06/01 18:20
postfix定义了VSTRING和VSTREAM“层次结构”,用来操作字符串与流:
struct VBUF { int flags; /* status, see below */ unsigned char *data; /*variable-length buffer */ ssize_t len; /*buffer length */ ssize_t cnt; /*bytes left to read/write */ unsigned char *ptr; /*read/write position */ VBUF_GET_READY_FN get_ready; /*read buffer empty action */ VBUF_PUT_READY_FN put_ready; /*write buffer full action */ VBUF_SPACE_FN space; /*request for buffer space */};
VBUF结构体是VSTRING和VSTREAM的基石。VSTRING和VSTREAM均包含VBUF指针。
flags:错误信息标志。
data :内容指针。
len :缓冲区长度。
cnt :剩余读写数据量。
ptr:读写位置指针。
get_ready、put_ready,space:读、写、扩容回调函数接口。
/util/vstring.h
VSTRING封装VBUF结构体,加上了最大长度限制字段。
/* *We can't allow bare VBUFs in the interface, because VSTRINGs have a *specific initialization and destruction sequence. */typedef struct VSTRING { VBUF vbuf; ssize_t maxlen;} VSTRING;
/util/vstream.htypedef struct VSTREAM { VBUF buf; /* generic intelligentbuffer */ int fd; /* file handle, no 256 limit */ VSTREAM_RW_FN read_fn; /*buffer fill action */ VSTREAM_RW_FN write_fn; /*buffer fill action */ ssize_t req_bufsize; /*requested read/write buffer size */ void *context; /* application context */ off_t offset; /* cached seek info*/ char *path; /* give it at leasttry */ int read_fd; /* read channel(double-buffered) */ int write_fd; /* write channel(double-buffered) */ VBUF read_buf; /* read buffer(double-buffered) */ VBUF write_buf; /* write buffer(double-buffered) */ pid_t pid; /* vstream_popen/close()*/ VSTREAM_WAITPID_FN waitpid_fn; /*vstream_popen/close() */ int timeout; /* read/write timout */ VSTREAM_JMP_BUF *jbuf; /*exception handling */ struct timeval iotime; /*time of last fill/flush */ struct timeval time_limit; /*read/write time limit */} VSTREAM;
VSTREAM结构体共定义了3个VBUF缓冲区和两个回调函数接口。
VSTREAM封装比较特殊的是postfix根据自身需要定义的timeout和jbuf字段。
timeout字段定义流操作的超时值,比如需要为smtp会话设置超时。
postfix用sigsetjmp来做异常处理。VSTREAM_JMP_BUF即jmp_buf或sigjmp_buf:
#ifdef NO_SIGSETJMP#define VSTREAM_JMP_BUF jmp_buf#else#define VSTREAM_JMP_BUF sigjmp_buf#endif
0 0
- 3.8.1 VBUF, VSTRING和VSTREAM结构体
- fork1.1 tast_struct 结构体和thread_info结构体
- sizeof和结构体
- 结构体和指针
- 结构体和联合体
- 结构体和联合体
- 结构体和指针
- 结构体和类
- 联合和结构体
- sizeof 和 结构体
- 结构体和类
- typedef和结构体
- 结构体和类
- 结构体和函数
- 指针和结构体
- 类和结构体
- 结构体和联合体
- 结构体和类
- 3.8 postfix字符串与流
- 生成螺旋矩阵(方阵、矩阵)
- 匿名内部类
- android开发判断手机网络连接状态
- 主流操作系统、浏览器DNS缓存时间
- 3.8.1 VBUF, VSTRING和VSTREAM结构体
- MSDE 2000
- What are Groups for Office 365?
- 让boost property_tree支持中文路径
- JDBC中关于Connection, PreparedStatement, ResultSet是否关闭的一些思考
- 用MFC实现静态文本超链接的方法 及静态文本颜色
- 从头认识多线程-1.2 共享变量与线程安全简介
- 构建之法学习心得(需求分析,IT行业的创新)
- android NDK开发(转)