Skip to content

Instantly share code, notes, and snippets.

@JeOam
Created December 15, 2015 09:59
Show Gist options
  • Save JeOam/fca30ae150a6f8f03475 to your computer and use it in GitHub Desktop.
Save JeOam/fca30ae150a6f8f03475 to your computer and use it in GitHub Desktop.
Nginx 数据结构和方法
@JeOam
Copy link
Author

JeOam commented Dec 15, 2015

ngx_chain_t 是与 ngx_buf_t 配合使用的链表数据结构

typedef struct ngx_chain_s ngx_chain_t;
struct ngx_chain_s{
        ngx_buf_t *buf;  // 指向当前的 ngx_buf_t 缓冲区
        ngx_chain_t *next;  // 指向下一个ngx_chain_t。如果这是最后一个ngx_chain_t,则需要把next置为NULL。
}; 

在向用户发送 HTTP 包体时,就要传入 ngx_chain_t 链表对象,注意,如果是最后一个 ngx_chain_t,那么必须将 next 置为 NULL,否则永远不会发送成功,而且这个请求将一直不会结束(Nginx框架的要求)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment