/********************************************************************* * Author:samson * date:07/08/2015 * Test PL Atform: * 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 * *******************************************************************/
Connection and read, write events associated with Nginx event handling:
Rev = c->read;ngx_handle_read_event (rev, 0) is often seen in Nginx code, so what is rev?
What is the ev->data in ngx_connection_t *c = ev->data; in ngx_epoll_add_event?
In fact, all this is found in the ngx_event_process_init, in this function, the cycle of the global structure of the read_events, write_events, connections the generation of space and the correlation between the three.
The generated code for these 3 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);
Read_events, write_events, connections, the three in the cycle of the subscript equal to the expression is a connected event and connection of the corresponding FD information, which will be directly used in the later time
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 NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The Association of Connection and read and write events in Nginx event processing