Klaus Demo nginx / 9b4a1d0
use variable for often used field Igor Sysoev 11 years ago
1 changed file(s) with 15 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
1414 void
1515 ngx_event_acceptex(ngx_event_t *rev)
1616 {
17 ngx_listening_t *ls;
1718 ngx_connection_t *c;
1819
1920 c = rev->data;
21 ls = c->listening;
2022
2123 c->log->handler = ngx_accept_log_error;
2224
2426
2527 if (rev->ovlp.error) {
2628 ngx_log_error(NGX_LOG_CRIT, c->log, rev->ovlp.error,
27 "AcceptEx() %V failed", &c->listening->addr_text);
29 "AcceptEx() %V failed", &ls->addr_text);
2830 return;
2931 }
3032
3133 /* SO_UPDATE_ACCEPT_CONTEXT is required for shutdown() to work */
3234
3335 if (setsockopt(c->fd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
34 (char *) &c->listening->fd, sizeof(ngx_socket_t))
36 (char *) &ls->fd, sizeof(ngx_socket_t))
3537 == -1)
3638 {
3739 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
4244 }
4345
4446 ngx_getacceptexsockaddrs(c->buffer->pos,
45 c->listening->post_accept_buffer_size,
46 c->listening->socklen + 16,
47 c->listening->socklen + 16,
47 ls->post_accept_buffer_size,
48 ls->socklen + 16,
49 ls->socklen + 16,
4850 &c->local_sockaddr, &c->local_socklen,
4951 &c->sockaddr, &c->socklen);
5052
51 if (c->listening->post_accept_buffer_size) {
53 if (ls->post_accept_buffer_size) {
5254 c->buffer->last += rev->available;
53 c->buffer->end = c->buffer->start
54 + c->listening->post_accept_buffer_size;
55 c->buffer->end = c->buffer->start + ls->post_accept_buffer_size;
56
5557 } else {
5658 c->buffer = NULL;
5759 }
5860
59 if (c->listening->addr_ntop) {
60 c->addr_text.data = ngx_pnalloc(c->pool,
61 c->listening->addr_text_max_len);
61 if (ls->addr_ntop) {
62 c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len);
6263 if (c->addr_text.data == NULL) {
6364 /* TODO: close socket */
6465 return;
6566 }
6667
6768 c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->addr_text.data,
68 c->listening->addr_text_max_len, 0);
69 ls->addr_text_max_len, 0);
6970 if (c->addr_text.len == 0) {
7071 /* TODO: close socket */
7172 return;
7273 }
7374 }
7475
75 ngx_event_post_acceptex(c->listening, 1);
76 ngx_event_post_acceptex(ls, 1);
7677
7778 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1);
7879
79 c->listening->handler(c);
80 ls->handler(c);
8081
8182 return;
8283