The Association of Connection and read and write events in Nginx event processing

Source: Internet
Author: User

/********************************************************************* * 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

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.