Association of connection and read and write events in Nginx event processing, nginxconnection

Source: Internet
Author: User

Association of connection and read and write events in Nginx event processing, nginxconnection

/********************************************************************* * Author  : Samson * Date    : 07/08/2015 * Test platform: *              gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 *              GNU bash, 4.3.11(1)-release (x86_64-pc-linux-gnu)  * Nginx version: *              Nginx 1.6.2 *              Nginx 1.8.0 * *******************************************************************/

Association between connection and read and write events in Nginx event processing:


In Nginx code, we often see rev = c-> read; ngx_handle_read_event (rev, 0); what is rev?

In ngx_epoll_add_event, What Is ev-> data in ngx_connection_t * c = ev-> data?


In fact, all these traces are found in ngx_event_process_init. In this function, the read_events, write_events, and connections spaces of the cycle global structure are generated and the associations between the three.

Code generated for the three structures:

Cycle-> connections = ngx_alloc (sizeof (ngx_connection_t) * cycle-> connection_n, cycle-> log );


Cycle-> read_events = ngx_alloc (sizeof (ngx_event_t) * cycle-> connection_n, cycle-> log );


Cycle-> write_events = ngx_alloc (sizeof (ngx_event_t) * cycle-> connection_n, cycle-> log );


// Associations of read_events, write_events, and connections. The subscript of the three in cycle is equal to that of a connection event and the fd of the connection, this information will be used directly later.

C = cycle-> connections;

I = cycle-> connection_n;

Next = NULL;


Do {

I --;


C [I]. data = next;

C [I]. read = & cycle-> read_events [I];

C [I]. write = & cycle-> write_events [I];

C [I]. fd = (ngx_socket_t)-1;


Next = & c [I];


# If (NGX_THREADS)

C [I]. lock = 0;

# Endif

} While (I );


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.