Nginx源码完全注释(3)ngx_list.h / ngx_list.c
列表头文件ngx_list.h
#ifndef _NGX_LIST_H_INCLUDED_
#define _NGX_LIST_H_INCLUDED_
#include <ngx_config.h>
#include <ngx_core.h>
typedef struct ngx_list_part_s ngx_list_part_t;
struct ngx_list_part_s {
void *elts;
ngx_uint_t nelts;
ngx_list_part_t *next;
};
typedef struct {
ngx_list_part_t *last;
ngx_list_part_t part;
size_t size;
ngx_uint_t nalloc;
ngx_pool_t *pool;
} ngx_list_t;
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)
{
list->part.elts = ngx_palloc(pool, n * size);
if (list->part.elts == NULL) {
return NGX_ERROR;
}
list->part.nelts = 0;
list->part.next = NULL;
list->last = &list->part;
list->size = size;
list->nalloc = n;
list->pool = pool;
return NGX_OK;
}
void *ngx_list_push(ngx_list_t *list);
#endif /* _NGX_LIST_H_INCLUDED_ */
列表源文件ngx_list.c
#include <ngx_config.h>
#include <ngx_core.h>
ngx_list_t *
ngx_list_create(ngx_pool_t *pool, ngx_uint_t n, size_t size)
{
ngx_list_t *list;
list = ngx_palloc(pool, sizeof(ngx_list_t));
if (list == NULL) {
return NULL;
}
list->part.elts = ngx_palloc(pool, n * size);
if (list->part.elts == NULL) {
return NULL;
}
list->part.nelts = 0;
list->part.next = NULL;
list->last = &list->part;
list->size = size;
list->nalloc = n;
list->pool = pool;
return list;
}
void *
ngx_list_push(ngx_list_t *l)
{
void *elt;
ngx_list_part_t *last;
last = l->last;
if (last->nelts == l->nalloc) {
last = ngx_palloc(l->pool, sizeof(ngx_list_part_t));
if (last == NULL) {
return NULL;
}
last->elts = ngx_palloc(l->pool, l->nalloc * l->size);
if (last->elts == NULL) {
return NULL;
}
last->nelts = 0;
last->next = NULL;
l->last->next = last;
l->last = last;
}
elt = (char *) last->elts + l->size * last->nelts;
last->nelts++;
return elt;
}
从上面可以看出,create 是从 pool 分配定义 list 结构的内存,分配表头节点的内存。init 是初始化已有的 list。
Reference
- http://blog.csdn.net/v_july_v/article/details/7040425
- http://www.cnblogs.com/sld666666/archive/2010/06/27/1766255.html
- http://www.cnblogs.com/jzhlin/archive/2012/06/05/Nginx_pool.html
- http://code.google.com/p/nginxsrp/wiki/NginxCodeReview#ngx的内存池
-
转载请注明来自柳大Poechant(钟超Michael)的CSDN博客:
钟超Michael的博客:Blog.CSDN.net/Poechant
钟超Michael的微博:钟超Michael的新浪微博
-
分享到:
相关推荐
ngx_sqlite 是嵌入 sqlite 数据库的 nginx 模块。通过强大的nginx server,可以使用http协议访问sqlite数据库。环境- sqlite 3- nginx-1.6.3 安装```sh $ git clone https://github.com/rryqszq4/ngx_sqlite.git...
nginx1.20.2
ngx_php功能是为nginx模块嵌入php脚本语言。别名为php-nginx-module。 特性 * 支持加载php.ini配置文件 * 支持原生php的全局变量$_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_SESSION... * 支持运行php代码...
nginx-1.18.0-2.el7.ngx.x86_64.rpm安装包(含有部署手册) nginx-1.18.0-2.el7.ngx.x86_64.rpm安装包(含有部署手册) nginx-1.18.0-2.el7.ngx.x86_64.rpm安装包(含有部署手册) nginx-1.18.0-2.el7.ngx.x86_64.rpm...
ngx_python 是为 nginx 嵌入 python 脚本的模块。环境- python 2.7.*- nginx-1.6.3 安装```sh git clone https://github.com/rryqszq4/ngx_python.git wget 'http://nginx.org/download/nginx-1.6.3.tar.gz' ...
ngx_http_dav_ext_module.so centos7 nginx 1.18 可以作为模块加载
2022年5月30日 官方当前最新稳定版本nginx 二进制rpm包 适用于x86架构centos7 rhel7版本操作系统升级安装nginx 该包开启了ipv6支持,添加了nginx-rtmp模块支持
ngx_cache_purge 是 nginx 模块,此模块可以清理 nginx 的 FastCGI、proxy、 SCGI 和 uWSGI 的缓存。配置指令(相同位置语法)fastcgi_cache_purgesyntax: fastcgi_cache_purge on|off|<method> [from all|<ip> [.....
很难找的 centos7 nginx-1.6.2-1.el7.centos.ngx.x86_64.rpm 包
nginx rpm package for centos7 nginx rpm package for centos7 nginx rpm package for centos7 nginx rpm package for centos7 nginx rpm package for centos7 nginx rpm package for centos7 nginx rpm package ...
nginx_1.7.11.3_Gryphon主要用于媒体直播服务器用,和FFmpeg+nginx+实例视频
nginx-1.20.0-1.el7.ngx.x86_64
备用nginx代理模块
lua-upstream-nginx-module, Nginx C 模块将Lua向ngx_lua公开,用于 Nginx upstreams 电子邮件名称ngx_http_lua_upstream - Nginx MODULE,用于向 Nginx upstreams公开Lua到 ngx_lua目录NAME状态概要说明函数get_...
2022年5月30日,官方当前最新稳定版本nginx 1.22.0 已经开启ipv6支持,nginx-http-flv-module模块支持 适用于x86架构的centos7 rhel7系列版本操作系统安装升级使用或者修复安全漏洞等
nginx 1.21.6 带rtmp模块,当前最新版rpm 包
linux下的nginx--rpm安装包
nginx-1.16.1-1.el6.ngx.x86_64.rpm nginx 最新版 nginx-1.16.1-1.el6.ngx.x86_64.rpm nginx 最新版
nginx-1.10.0-1.el6.ngx.x86_64.rpm 适用于redhat el6
nginx-1.8.1-1.el6.ngx.x86_64.rpm,linux下快速安装