Nginx 이벤트 처리 중의 connection 과 read, write 이벤트 의 연결

1657 단어
/*********************************************************************
 * 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
 * *******************************************************************/

Nginx 이벤트 처리 중의 connection 과 read, write 이벤트 의 연결:
Nginx 코드 에서 rev = c - > read 를 자주 볼 수 있 습 니 다.ngx_handle_read_event(rev, 0);이런 조작, 그렇다면 rev 는 무엇 일 까?
재 ngxepoll_add_이벤트 중의 ngxconnection_t *c = ev->data;중의 ev - > data 는 또 어떤 내용 입 니까?
사실 이 모든 것 은 ngxevent_process_init 에서 흔적 을 찾 았 습 니 다. 이 함수 에서 cycle 전역 구조의 read 를 진행 하 였 습 니 다.events、write_이벤트, connections 의 공간의 생 성 및 이 세 가지 관계.
이 세 구조의 생 성 코드:
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_이벤트, connections 의 관련, 이 세 가 지 는 cycle 의 아래 표 시 는 연 결 된 이벤트 와 연결 에 대응 하 는 fd 등 정 보 를 나타 내 는데 이런 정 보 는 후기 에 직접 사 용 됩 니 다.
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);

좋은 웹페이지 즐겨찾기