Home > Backend Development > PHP Tutorial > nginx doubly linked list ngx_queue_t

nginx doubly linked list ngx_queue_t

WBOY
Release: 2016-08-08 09:23:29
Original
1319 people have browsed it

1. Introduction

ngx_queue_t is a doubly linked list implemented in nginx. Just embed ngx_queue_t into the custom structure in which you want to use the doubly linked list. Another feature is that ngx_queue_t does not involve memory allocation.

2. Example

The following source code integrates the source code about ngx_queue_t in Chapter 7 of "In-depth Understanding of nginx". Makefile refers to http://blog.csdn.net/livelylittlefish/article/details/6586946.

#include

#include "ngx_config.h"

#include "ngx_conf_file.h"

#include "nginx.h"

#include "ngx_core.h"

#include "ngx_string.h"

#include "ngx_palloc.h"

#include "ngx_queue.h"

volatile ngx_cycle_t *ngx_cycle;

void ngx_log_error_core(ngx_uint_t level,ngx_log_t *log, ngx_err_t err,

                 const char * fmt, ...)

{

}

typedef struct {

                                                                        ngx_int_t compTestNode(const ngx_queue_t*a, const ngx_queue_t *b )

{

           TestNode*aNode = ngx_queue_data(a, TestNode, qEle);

         TestNode*bNode = ngx_queue_data(b, TestNode, qEle);           returnaNode->num > ; bNode->num;

}

int main()

{

ngx_queue_tqueueContainer;

ngx_queue_init(&queueContainer);

inti = 0;

TestNo denode[5];

                                                                                                                                        ​) {

                                                                                                                                        ngx_queue_insert_head(&queueContainer,&node[1].qEle);

   ngx_queue_insert_tail( &queueContainer,&node[2].qEle);

ngx_queue_insert_after(&queueContainer,&node[3].qEle);

ngx_queue_insert_tail(&queueContainer,&node[4].qEle);

ngx_queue_t*q;

for( q = ngx_queue_head(&queueContainer); TestNode*eleNode = ngx_queue_data(q, TestNode, qEle);

         printf("%dn" ,eleNode->num);

                                                                                                                                    

for(q = ngx_queue_head(&queueContainer);                                             *eleNode = ngx_queue_data(q, TestNode, qEle);

         printf("%dn",eleNode ->num);

                                                                                                                                                                                                                                                    

NGX_ROOT = /usr/src/nginx-1.0. 4

TARGETS = test_queue

TARGETS_C_FILE = $(TARGETS).c

CLEANUP = rm -f $(TARGETS) *.o

all: $(TARGETS)

clean:

​​​​​​​$(CLEANUP)

CORE_INCS = -I.

-I$(NGX_ROOT)/src/core

-I$(NGX_ROOT)/src/event

G -i $ (ngx_root)/src/event/modules

-i $ (ngx_root)/src/OS/UNIX

-I $ (ngx_root)/objs

ngx_palloc = $ (ngx_root)/objs/src/src/ core/ngx_palloc.o

NGX_STRING =$(NGX_ROOT)/objs/src/core/ngx_string.o

NGX_ALLOC = $(NGX_ROOT)/objs/src/os/unix/ngx_alloc.o

NGX_QUEUE =$(NGX_ROOT )/objs/src/core/ngx_queue.o

$(TARGETS): $(TARGETS_C_FILE)

                                                                                                                                                                                            NGX_QUEUE)$^ -o $@

3. Summary

1. A linked list is identified by the linked list header and does not contain user-defined related data.

The above introduces the nginx doubly linked list ngx_queue_t, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template