IO 流(stream), LIB-ZC

LIB-ZC 支持IO 流(stream), 其 STRUCT 类型是 zstream_t

数据结构

#define zvar_stream_rbuf_size           4096
#define zvar_stream_wbuf_size           4096

struct zstream_t {
    int read_wait_timeout;
    int write_wait_timeout;
    void *ioctx;
    zstream_engine_t *engine;
    short int read_buf_p1;
    short int read_buf_p2;
    short int write_buf_len;
    unsigned short int error:1;
    unsigned short int eof:1;
    unsigned char read_buf[zvar_stream_rbuf_size];
    unsigned char write_buf[zvar_stream_wbuf_size];
};

函数: 基本操作

zstream_t *zstream_open_fd(int fd);

创建; 根据文件描述符 fd 创建, fd 一般是 socket

zstream_t *zstream_open_ssl(SSL *ssl);

创建; 根据 ssl 创建

zstream_t *zstream_open_file(const char *pathname, const char *mode);

创建; 打开本地文件; 返回 0: 失败; mode: "r", "r+", "w", "w+", "a", "a+"

除非了解使用本方法的有点, 否则不推荐使用, 建议使用标准 C 库的 FILE

zstream_t *zstream_open_destination(const char *destination, int timeout);

创建; 打开地址 destination; 返回 0: 失败; timeout: 超时; destination: 目标地址, 参考 zconnect

int zstream_close(zstream_t *fp, zbool_t release);

京ICP备18054515号-2 eli960@qq.com qq: 1537212398