ptpd 源码解析_shttpd源码分析(3)几个重要数据结构

博客详细解析了shttpd中的流数据结构,包括struct stream、struct conn、union channel、struct io及const struct io_class。结构体conn包含了连接信息、shttpd上下文、远程socket地址等;union channel用于存储不同类型的通信通道信息;struct io用于记录IO缓冲区的状态;const struct io_class定义了IO操作的函数指针,实现多态调用。
摘要由CSDN通过智能技术生成

shttpd中为了简化处理将服务器与客户端之间的交互抽象成流(stream),流中包含建立的连接的信息、IO类型、IO操作方法(封装在io_class中)、最后读的字节的位置、头部长度、内容长度、流的当前状态标志等。

struct stream

1 /*2 * Data exchange stream. It is backed by some communication channel:3 * opened file, socket, etc. The 'read' and 'write' methods are4 * determined by a communication channel.5 */6 structstream {7 structconn*conn;8 union channel chan;/*Descriptor*/9 structio io;/*IO buffer*/10 conststructio_class*io_class;/*IO class*/11 intnread_last;/*Bytes last read*/12 intheaders_len;13 big_int_t content_len;14 unsignedintflags;15 #defineFLAG_HEADERS_PARSED 116 #defineFLAG_SSL_ACCEPTED 217 #defineFLAG_R 4 /* Can read in general */18 #defineFLAG_W 8 /* Can write in general */19 #defineFLAG_CLOSED 1620 #defineFLAG_DONT_CLOSE 3221 #defineFLAG_ALWAYS_READY 64 /* File, dir, user_func */22 };23

再来看看流结构中的几个结构struct co

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值