Simple data types
Download nginx 1.0.14 source code.
After the nginx code is unbound, the following directories are generated in the src directory:
Core event HTTP Mail MISC OSWhere:
- Core: This directory stores the core module code, which is also the ingress of the nginx service.
- HTTP: HTTP core module code. nginx is the core module of the Web/HTTP Proxy Server Runtime.
- Mail: Mail core module code. nginx is used as the core module for POP3, IMAP, and SMTP Proxy Server Runtime (not in our research scope)
- Event: Nginx encapsulation of event processing logic
- OS: Nginx encapsulates the Abstract Logic of each platform
- Misc: Some utils of nginx, which defines the logic of some peripheral modules of test and Profiler
To facilitate understanding of the entire structure, we have created a sub-directory named demo under the src directory to store some of the code used for learning. For example, our current chapter is
Basic data type. The src directory tree structure is:
── Core
── Demo
── Event
│ ── Modules
── HTTP
│ ── Modules
│ ── Perl
├ ── Mail
── Misc
── OS
── Unix
The core/ngx_config.h directory defines the ing of basic data types, most of which are mapped to the Data Types of C language.
typedef intptr_t ngx_int_t;typedef uintptr_t ngx_uint_t;typedef intptr_t ngx_flag_t;
Ngx_int_t and nginx_flag_t are mapped to intptr_t, and ngx_uint_t are mapped to uintptr_t.
Create a file 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;}
Compile:
gcc -I ../../objs/ -I ../os/unix/ basic_types_int.c -o basic_types_int ./basic_types_int
Test result: 90
Note that you need to compile the downloaded nginx source code before compiling this file (because the target file under objs needs to be compiled at this time), which is very simple. Required during installation
Depending on the software./configure, make.