: This article mainly introduces the basic data structure. if you are interested in the PHP Tutorial, you can refer to it. First, it is an integer:
Src/core/ngx_config.h
typedef intptr_t ngx_int_t;typedef uintptr_t ngx_uint_t;typedef intptr_t ngx_flag_t;
It is an integer, an unsigned integer, and a bool. Intptr_t and other three types are defined as follows:
/Usr/local/include/stdint. h
/* Types for `void *' pointers. */#if __WORDSIZE == 64# ifndef __intptr_t_definedtypedef longint intptr_t;# define __intptr_t_defined# endiftypedef unsigned longint uintptr_t;#else# ifndef __intptr_t_definedtypedef int intptr_t;# define __intptr_t_defined# endiftypedef unsigned int uintptr_t;#endif
That is, the 64 system uses a long integer (8 bytes); otherwise, an integer (4 bytes) is used ).
Then the string type:
/Src/core/ngx_string.h
typedef struct { size_t len; u_char *data;} ngx_str_t;
Next, we define a bunch of string-related functions, similar to the member functions corresponding to ngx_str_t.
Function |
Description |
Ngx_string (str) |
Constructor. str points to the string ending with \ 0. |
Ngx_null_string |
Empty constructor |
Ngx_str_set (str, text) |
Text points to the string ending with \ 0 and sets it to the ngx_str_t object str |
Ngx_strncmp |
Encapsulate strncmp |
Ngx_strcmp |
Encapsulate strcmp |
... |
... |
In addition, several other types are defined by the way:
Typedefstruct {ngx_str_t key; ngx_str_t value;} ngx_keyval_t; typedefstruct {// bit field used to indicate the type and other metadata unsigned len: 28; unsigned valid: 1; unsigned no_cacheable; unsigned not_found: 1; unsigned escape: 1; u_char * data;} ngx_variable_value_t; typedefstruct {ngx_rbtree_node_t node; ngx_str_t str;} ngx_str_node_t;
I defined my own error types: (the cause is that the strerror and strerror_r functions of the system are not signal secure. Therefore, the author copied the error msg corresponding to the error code and maintained it by himself, self-built functions are easy to write and signal-safe)
Src/OS/unix/ngx_errno.h
Typedefint ngx_err_t; // Copy the description information to errstr based on the error code err. you can copy the size byte u_char * ngx_strerror (ngx_err_t err, u_char * errstr, size_t size) at most ); ngx_int_t ngx_strerror_init (void );
The error number is defined in errno. h of the system. after multiple layers are included, the final error number is defined in/usr/include/asm-generic/errno. h.
The strerror and strerror_r functions are declared in string. h.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces the basic data structure, including the content, and hope to be helpful to friends who are interested in PHP tutorials.