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.