【Nginx】基本数据结构
整型的封裝
typedef intptr_t ngx_int _t;//有符號整型
typedef uintptr_t ngx_uint_t;//無符號整型
字符串的封裝
typedef struct {size_t len;u_char *data; }ngx_str_t;鏈表容器的封裝
typedef struct ngx_list_part_s ngx_list_part_t; //鏈表結點 struct ngx_list_part_s {void *elts;//數組的起始地址ngx_uint_t nelts;//數組中已經使用的元素個數,必須小于nallocngx_list_part_t *next;// };typedef struct {ngx_list_part_t *last;ngx_list_part_t part;size_t size;//ngx_list_part_t中元素的大小上限ngx_uint_t nalloc;//每個ngx_list_part數組的容量ngx_pool_t *pool;//鏈表中管理內存分配的內存池對象 }ngx_list_t;對于鏈表,Nginx提供的接口包括:
//pool為內存池對象,size是結點中數組的每個元素的大小,n是數組中可容納元素的個數,即結點大小為n*size
ngx_list_t *ngx_list_create(ngx_pool_t *pool,ngx_uint_t n,size_t size);
//初始化一個已有的鏈表
static ngx_inline ngx_int_t ngx_list_init(ngx_list_t *list,ngx_pool_t *pool,ngx_uint_t n,size_t size);
//添加新的元素
void *ngx_list_push(ngx_list_t *list);
ngx_table_elt_t數據成員
typedef struct
{
??? ngx_uint_t hash;
??? ngx_str_t key;
??? ngx_str_t value;
??? u_char *lowcase_key;
}ngx_table_elt_t;
ngx_table_elt_t常用于http頭部。
ngx_buf_t數據結構
緩沖區ngx_buf_t是Nginx處理大數據的關鍵數據結構,它既應用于內存數據也應用于磁盤數據。
ngx_chain_t數據結構
ngx_chain_t是與ngx_buf_t配合使用的鏈表數據結構。
typedef struct ngx_chain_s ngx_chain_t;
struct ngx_chain_s
{
ngx_buf_t *buf;
ngx_chain_t *next;
};
?
?
?
?
?
?
轉載于:https://www.cnblogs.com/ljygoodgoodstudydaydayup/p/3826304.html
總結
以上是生活随笔為你收集整理的【Nginx】基本数据结构的全部內容,希望文章能夠幫你解決所遇到的問題。