Nginx source code to learn simple data types

Source: Internet
Author: User

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 OS

Where:

  • 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.