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