'In-depth understanding of Nginx' notes: ngx_event_pipe_s structure

WBOY
Release: 2016-07-30 13:30:57
Original
1100 people have browsed it

ngx_event_pipe_s

<code><span>typedef</span><span>struct</span> ngx_event_pipe_s  ngx_event_pipe_t;

<span>// 处理接收自上游的包体的回调函数原型</span><span>typedef</span> ngx_int_t (*ngx_event_pipe_input_filter_pt)(ngx_event_pipe_t *p,
                                                    ngx_buf_t *buf);

<span>// 向下游发送响应的回调函数原型</span><span>typedef</span> ngx_int_t (*ngx_event_pipe_output_filter_pt)(<span>void</span> *data,
                                                     ngx_chain_t *chain);



<span>struct</span> ngx_event_pipe_s {
     <span>// Nginx与上游服务器之间的连接</span>
    ngx_connection_t  *upstream;

    <span>// Nginx与下游客户端之间的连接</span>
    ngx_connection_t  *downstream;

     <span>/* 直接接收自上游服务器的缓冲区链表,保存的是未经任何处理的数据。这个链表是逆序的,后接受的响应插在链表头处 */</span>
    ngx_chain_t       *free_raw_bufs;

    <span>// 表示接收到的上游响应缓冲区,其数据是经过input_filter处理的</span>
    ngx_chain_t       *in;

    <span>// 指向刚收到的一个缓冲区</span>
    ngx_chain_t      **last_in;

     <span>// 保存着将要发给客户端的缓冲区链表。在写入临时文件成功时,会把in中的缓冲区添加到out中</span>
    ngx_chain_t       *out;

    <span>// 等待释放的缓冲区</span>
    ngx_chain_t       *<span>free</span>;

    <span>// 表示上次调用ngx_http_output_filter函数发送响应时没有发送完的缓冲区链表</span>
    ngx_chain_t       *busy;

    <span>/*
     * the input filter i.e. that moves HTTP/1.1 chunks
     * from the raw bufs to an incoming chain
     */</span><span>// 处理接收到的、来自上游服务器的数据</span>
    ngx_event_pipe_input_filter_pt    input_filter;

    <span>// 用于input_filter的的参数,一般是ngx_http_request_t的地址</span><span>void</span>                             *input_ctx;

     <span>// 向下游发送响应的函数</span>
    ngx_event_pipe_output_filter_pt   output_filter;

    <span>// output_filter的参数,指向ngx_http_request_t</span><span>void</span>                             *output_ctx;

     <span>// 1:表示当前已读取到上游的响应</span><span>unsigned</span>           read:<span>1</span>;

    <span>// 1:启用文件缓存</span><span>unsigned</span>           cacheable:<span>1</span>;

    <span>// 1:表示接收上游响应时,一次只能接收一个ngx_buf_t缓冲区</span><span>unsigned</span>           single_buf:<span>1</span>;

    <span>// 1:一旦不再接收上游包体,将尽可能地释放缓冲区</span><span>unsigned</span>           free_bufs:<span>1</span>;

    <span>// 1:表示Nginx与上游交互已经结束</span><span>unsigned</span>           upstream_done:<span>1</span>;

    <span>// 1:Nginx与上游服务器的连接出现错误</span><span>unsigned</span>           upstream_error:<span>1</span>;

    <span>// 1:表示与上游服务器的连接已关闭</span><span>unsigned</span>           upstream_eof:<span>1</span>;

    <span>/* 1:表示暂时阻塞读取上游响应的的流程。此时会先调用ngx_event_pipe_write_to_downstream
    函数发送缓冲区中的数据给下游,从而腾出缓冲区空间,再调用ngx_event_pipe_read_upstream
    函数读取上游信息 */</span><span>unsigned</span>           upstream_blocked:<span>1</span>;

    <span>// 1:与下游的交互已结束</span><span>unsigned</span>           downstream_done:<span>1</span>;

    <span>// 1:与下游的连接出现错误</span><span>unsigned</span>           downstream_error:<span>1</span>;

    <span>// 1:复用临时文件。它是由ngx_http_upstream_conf_t中的同名成员赋值的</span><span>unsigned</span>           cyclic_temp_file:<span>1</span>;

     <span>// 已分配的缓冲区数据</span>
    ngx_int_t          allocated;

    <span>// 记录了接收上游响应的内存缓冲区大小,bufs.size表示每个内存缓冲区大小,bufs.num表示最多可以有num个缓冲区</span>
    ngx_bufs_t         bufs;

    <span>// 用于设置、比较缓冲区链表中的ngx_buf_t结构体的tag标志位</span>
    ngx_buf_tag_t      tag;

     <span>/* busy缓冲区中待发送响应长度的最大值,当到达busy_size时,必须等待busy缓冲区发送了足够的数据,
     才能继续发送out和in中的内容 */</span>
    ssize_t            busy_size;

     <span>// 已经接收到来自上游响应包体的长度</span>
    off_t              read_length;
    off_t              length;

     <span>// 表示临时文件的最大长度</span>
    off_t              max_temp_file_size;

    <span>// 表示一次写入文件时数据的最大长度</span>
    ssize_t            temp_file_write_size;

     <span>// 读取上游响应的超时时间</span>
    ngx_msec_t         read_timeout;

    <span>// 向下游发送响应的超时时间</span>
    ngx_msec_t         send_timeout;

    <span>// 向下游发送响应时,TCP连接中设置的send_lowat“水位”</span>
    ssize_t            send_lowat;

     <span>// 连接池</span>
    ngx_pool_t        *pool;

    <span>// 日志</span>
    ngx_log_t         *<span>log</span>;

     <span>// 表示在接收上游服务器响应头部阶段,已经读取到响应包体</span>
    ngx_chain_t       *preread_bufs;

    <span>// 表示在接收上游服务器响应头部阶段,已经读取到响应包体长度</span>
    size_t             preread_size;

    <span>// 用于缓存文件</span>
    ngx_buf_t         *buf_to_file;
    size_t             limit_rate;
    time_t             start_sec;

     <span>// 存放上游响应的临时文件</span>
    ngx_temp_file_t   *temp_file;

     <span>// 已使用的ngx_buf_t缓冲区数目</span><span>/* STUB */</span><span>int</span>     num;
};
</code>
Copy after login

Copyright Statement: Pain is just in your mind.

The above introduces the ngx_event_pipe_s structure of the notes of "In-depth Understanding of Nginx", including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template