简单的数据类型
下载nginx 1.0.14源码。
解开nginx的代码后,在src目录下发现有如下的几个目录
core event http mail misc os其中 :
- core : 该目录存放core module的代码,也是nginx服务的入口
- http : http core module 的代码,nginx作为web/http proxy server运行时的核心模块
- mail : mail core module 的代码,nginx作为pop3/imap/smtp proxy server运行时的核心模块 ( 不在我们本次研究范围内 )
- event : nginx 自身对事件处理逻辑的封装
- os : nginx对各个平台抽象逻辑的封装
- misc : nginx 的一些utils,定义了test和profiler的一些外围模块的逻辑
├── core
├── demo
├── event
│ └── modules
├── http
│ └── modules
│ └── perl
├── mail
├── misc
└── os
└── unix
在 core/ngx_config.h 目录里面定义了基本的数据类型的映射,大部分都映射到c语言自身的数据类型
typedef intptr_t ngx_int_t; typedef uintptr_t ngx_uint_t; typedef intptr_t ngx_flag_t;
其中 ngx_int_t, nginx_flag_t, 都映射为 intptr_t; ngx_uint_t映射为 uintptr_t
新建文件 basic_types_int.c
#include <stdio.h>
#include "../core/ngx_config.h"
int main()
{
ngx_uint_t x;
ngx_int_t y;
x = 100;
y = -10;
printf ("%d + %d = %d\n", x, y, x + y);
return 0;
}
编译
:
gcc -I ../../objs/ -I ../os/unix/ basic_types_int.c -o basic_types_int ./basic_types_int
测试结果为:90
注意在编译此文件前需要把下载下来的nginx源码进行编译(因为此时需要编译后的objs下的目标文件),很简单。在安装必须的
依赖软件后./configure,make即可。