您的位置:首页 > 编程语言 > VB

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: