【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进程的数量:通常应该为 ...
随机推荐
- Centos7源码编译安装tengine1.5.1
安装依赖包 yum install pcre pcre-devel openssl openssl-devel gcc make zlib-devel wget -y 下载和创建用户 mkdir /t ...
- Ubuntu下安装 Phantomjs
1.安装phantomjs —-下载程序文件 wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x8 ...
- 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律
转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...
- IntelliJ IDEA 常用设置/快捷键
经常用到 IntelliJ IDEA 编写java,由于不时需要重装系统,所以Mark一下一些基本的设置选项,以便查询,这篇帖子会一直更新,只要有常用的新的设置或者快捷键 一.常用设置 显示代码行号 ...
- 多表联合查询,利用 concat 模糊搜索
select * from t1 as a join t2 as b on a.id = b.id where CONCAT(a.name,b.name) like '%测试%'
- go时间转化
将string转化为time.Time layout := "2006-01-02 15:04:05" str := "2017-11-24 15:10:22" ...
- 图像视图-ImageView
(一) 知识点: (1)imageView.setImageAlpha(Alpha):设置图片透明度 (2)在布局imageView中设置图片位置:android:scaleType="ce ...
- webservice_客户端生成工具
1. axis java -Djava.ext.dirs=lib org.apache.axis.wsdl.WSDL2Java -p com.qunar.flight.flagship.provide ...
- acitivity 和fragment 通信,使用广播来传递信息的问题
使用广播来传递信息时 如果 acitivity 给 太快给 fragment 发送广播,fragment 收不到 使用回调的方式来解决
- DataRow 数组转化成DataTable
#region 封装DataTable DataTable dt = null; if (newRows.Length > 0) { dt = newRows[0].Table.Clone(); ...