【Nginx】核心模块ngx_events_module
它的实现非常easy。以下是该模块的定义:
ngx_module_t ngx_events_module = {
NGX_MODULE_V1,
&ngx_events_module_ctx, /* module context */
ngx_events_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};
// 定义了怎样处理感兴趣的配置项
static ngx_command_t ngx_events_commands[] = {
{
ngx_string("events"), /* 仅仅对events块配置项感兴趣 */
NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
ngx_events_block, /* 解析配置项的函数 */
0,
0,
NULL
},
ngx_null_command
};
通用接口ngx_events_module_ctx定义例如以下:
static ngx_core_module_t ngx_events_module_ctx = {
ngx_string("events"),
NULL, /* create_conf */
ngx_event_init_conf /* init_conf */
};
这是由于ngx_events_module并不解析配置项參数,仅仅是在events块配置项出现后调用各个事件模块去解析events内的配置项,所以它自己并不须要实现create_conf方法和init_conf方法。
typedef struct {
ngx_str_t *name; // 事件模块名字
// 解析配置项之前调用,创建存储配置项參数的结构体
void *(*create_conf)(ngx_cycle_t *cycle);
// 解析完配置项后的回调函数
char *(*init_conf)(ngx_cycle_t *cycle, void *conf);
// 每一个事件模块须要实现的10个抽象方法
ngx_event_actions_t actions;
} ngx_event_module_t; // 事件模块通用接口
这个指针放在了ngx_events_module核心模块创建的指针数组中,例如以下图所看到的:
static char *
ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *rv;
void ***ctx;
ngx_uint_t i;
ngx_conf_t pcf;
ngx_event_module_t *m;
ngx_event_max_module = 0;
for (i = 0; ngx_modules[i]; i++)
{
if (ngx_modules[i]->type != NGX_EVENT_MODULE)
continue;
/* 1.初始化全部事件模块的ctx_index成员
* 该成员表明了该模块在同样类型模块中的顺序。这会决定以后载入各事件模块的顺序
*/
ngx_modules[i]->ctx_index = ngx_event_max_module++;
}
/* 分配一个存放指针的空间 */
ctx = ngx_pcalloc(cf->pool, sizeof(void *));
/* 2.ngx_event_max_module等于事件模块个数 */
*ctx = ngx_pcalloc(cf->pool, ngx_event_max_module * sizeof(void *));
*(void **) conf = ctx; /* conf指向存储參数的结构体 */
for (i = 0; ngx_modules[i]; i++)
{
if (ngx_modules[i]->type != NGX_EVENT_MODULE)
continue;
m = ngx_modules[i]->ctx; /* 得到事件模块的通用接口 */
if (m->create_conf)
/* 3.调用全部事件模块的通用接口ngx_event_module_t中的create_conf方法 */
(*ctx)[ngx_modules[i]->ctx_index] = m->create_conf(cf->cycle);
}
pcf = *cf;
cf->ctx = ctx;
cf->module_type = NGX_EVENT_MODULE;
cf->cmd_type = NGX_EVENT_CONF;
/* 4.针对全部事件模块调用各自的解析配置文件的方法
* 当发现对应配置项后。就调用模块中ngx_command_t数组中的方法
*/
rv = ngx_conf_parse(cf, NULL); /* cf中保存有读到的配置项參数 */
*cf = pcf;
for (i = 0; ngx_modules[i]; i++)
{
if (ngx_modules[i]->type != NGX_EVENT_MODULE)
continue;
m = ngx_modules[i]->ctx;
if (m->init_conf)
/* 5.解析完配置项后,调用每一个模块的init_conf方法对配置參数进行整合 */
rv = m->init_conf(cf->cycle, (*ctx)[ngx_modules[i]->ctx_index]);
}
return NGX_CONF_OK;
}
事件驱动机制很多其它的工作是在ngx_event_core_module模块中完毕,下次再写。
【Nginx】核心模块ngx_events_module的更多相关文章
- Nginx事件管理之核心模块ngx_events_module
1. ngx_events_module核心模块的功能介绍 ngx_events_module 模式是一个核心模块,它的功能如下: 定义新的事件类型 定义每个事件模块都需要实现的ngx_event_m ...
- nginx核心模块常用指令
默认启动Nginx时,使用的配置文件是: 安装路径/conf/nginx.conf 文件,可以在启动nginx的时候,通过-c来指定要读取的配置文件 常见的配置文件有如下几个: nginx.conf: ...
- Nginx核心模块内置变量
本文根据Nginx官网整理了Nginx的ngx_http_core_module模块的内置变量,可与Apache做对比参考.随后做了一次测试观察各变量的值,并附上测试结果. 1.变量列表 $arg_n ...
- Nginx核心模块
error_log 语法:error_log file [ debug | info | notice | warn | error | crit ]默认值:${prefix}/logs/error. ...
- 高性能Web服务器Nginx的配置与部署研究(7)核心模块之主模块的非测试常用指令
1. error_log 含义:指定存储错误日志的文件 语法:error_log <file> [debug|info|notice|warn|error|crit] 缺省:${prefi ...
- Nginx核心流程及模块介绍
Nginx核心流程及模块介绍 1. Nginx简介以及特点 Nginx简介: Nginx (engine x) 是一个高性能的web服务器和反向代理服务器,也是一个IMAP/POP3/SMTP服务器 ...
- 【Nginx】Nginx事件模块
一.事件处理框架概述 事件处理框架所要解决的问题是如何收集.管理.分发事件.事件以网络事件和定时器事件为主,而网络事件中以TCP网络事件为主.事件处理框架需要在不同的操作系统内核中选择一种事件驱动机制 ...
- nginx -- handler模块(100%)
handler模块简介 相信大家在看了前一章的模块概述以后,都对nginx的模块有了一个基本的认识.基本上作为第三方开发者最可能开发的就是三种类型的模块,即handler,filter和load-ba ...
- (转)nginx 常用模块整理
原文:http://blog.51cto.com/arm2012/1977090 1. 性能相关配置 worker_processes number | auto: worker进程的数量:通常应该为 ...
随机推荐
- 【UOJ UNR #1】火车管理 可持久化线段树
用可持久化线段树维护每个站的第一辆车和每个站的前一次更新的位置即可. #include<iostream> #include<cstring> #include<cstd ...
- D - Interesting Calculator 【数值型BFS+优先队列】
There is an interesting calculator. It has 3 rows of buttons. Row 1: button 0, 1, 2, 3, ..., 9. Pres ...
- 35、Django实战第35天:完善点击数/ 收藏数
点击数--课程 当我们进入一个课程的详情页的时候,点击数+1 当我们点击“我要学习”的时候,该课程的学习人数+1 点击数--教师 当我们进入一个讲师的详情页的时候,点击数+1 点击数--机构 当我们进 ...
- IO 概括
# 一.概览 Java 的 I/O 大概可以分成以下几类: - 磁盘操作:File- 字节操作:InputStream 和 OutputStream- 字符操作:Reader 和 Writer- 对象 ...
- inline select
- httpd访问网络配置httpd_can_network_connect
检查网络访问的配置 getsebool -a | grep httpd_can_network_connect 如结果如下 httpd_can_network_connect --> off 则 ...
- Tomcat线程池实现
目前市场上常用的开源Java Web容器有Tomcat.Resin和Jetty.其中Resin从V3.0后需要购买才能用于商业目的,而其他两种则是纯开源的.可以分别从他们的网站上下载最新的二进制包和源 ...
- 【二维莫队】【二维分块】bzoj2639 矩形计算
<法一>二维莫队,对n和m分别分块后,对块从上到下从左到右依次编号,询问以左上角所在块编号为第一关键字,以右下角标号为第二关键字排序,转移时非常厉害. O(q*n*sqrt(n)). #i ...
- 【分块】bzoj2724 [Violet 6]蒲公英
分块,离散化,预处理出: ①前i块中x出现的次数(差分): ②第i块到第j块中的众数是谁,出现了多少次. 询问的时候,对于整块的部分直接获得答案:对于零散的部分,暴力统计每个数出现的次数,加上差分的结 ...
- apk打包
1.在导航栏中选择Builder->Generate Signed Apk 2.新建点击Creat new... 3.注意路径后面写apk的名字(这个名字将会显示在手机软件的下方)