3.8.1 VBUF, VSTRING和VSTREAM结构体
2016-04-07 10:11
746 查看
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.hVSTRING封装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
相关文章推荐
- VB洗牌算法产生随机数组
- 吾将上下而求索 VB 小小小
- 路漫漫其修远兮···VB 来15个数尝尝咸淡
- VB 控件随窗体缩放
- vbs 脚本2
- vbs脚本
- VB 动态数组,文件读写
- 2014 .04 .06 navbar
- VBOX中的Ubuntu的安装和配置
- AB是一家?VAO与VBO
- VBA 复制工作簿内容
- 安装Orcale VBox虚拟机必须注意的问题
- VBS脚本常用经典代码收集
- VB中的排序问题 15个
- VB病毒
- Excel vba使用正则表达式处理联通官网导出的通话详单
- 关于vb 多任意数字大小排列问题
- VB.OCR.汉明距离
- How to play .rmvb files in Ubuntu
- VB 2010中Excel文件处理的一个奇怪问题