ngx_http_wait_request_handler注释




static void
ngx_http_wait_request_handler(ngx_event_t *rev)
{
    size_t                     size;
    ssize_t                    n;
    ngx_buf_t                 *b;
    ngx_connection_t          *c;
    ngx_http_connection_t     *hc;
    ngx_http_core_srv_conf_t  *cscf;


    c = rev->data;


    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http wait request handler");


    if (rev->timedout) {
        ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
        ngx_http_close_connection(c);
        return;
    }


    if (c->close) {
        ngx_http_close_connection(c);
        return;
    }


    hc = c->data;
    cscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_core_module);


    size = cscf->client_header_buffer_size;


    b = c->buffer;


    if (b == NULL) {
        b = ngx_create_temp_buf(c->pool, size);
        if (b == NULL) {
            ngx_http_close_connection(c);
            return;
        }


        c->buffer = b;


    } else if (b->start == NULL) {


        b->start = ngx_palloc(c->pool, size);
        if (b->start == NULL) {
            ngx_http_close_connection(c);
            return;
        }


        b->pos = b->start;
        b->last = b->start;
        b->end = b->last + size;
    }


    n = c->recv(c, b->last, size);


    if (n == NGX_AGAIN) {


#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
        if (c->listening->deferred_accept
#if (NGX_HTTP_SSL)
            && c->ssl == NULL
#endif
            )
        {
            ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
                          "client timed out in deferred accept");
            ngx_http_close_connection(c);
            return;
        }
#endif


        if (!rev->timer_set) {
            ngx_add_timer(rev, c->listening->post_accept_timeout);
            ngx_reusable_connection(c, 1);
        }


        if (ngx_handle_read_event(rev, 0) != NGX_OK) {
            ngx_http_close_connection(c);
            return;
        }


        /*
         * We are trying to not hold c->buffer's memory for an idle connection.
         */


        if (ngx_pfree(c->pool, b->start) == NGX_OK) {
            b->start = NULL;
        }


        return;
    }


    if (n == NGX_ERROR) {
        ngx_http_close_connection(c);
        return;
    }


    if (n == 0) {
        ngx_log_error(NGX_LOG_INFO, c->log, 0,
                      "client closed connection");
        ngx_http_close_connection(c);
        return;
    }


    b->last += n;


    c->log->action = "reading client request line";


    ngx_reusable_connection(c, 0);


    c->data = ngx_http_create_request(c);
    if (c->data == NULL) {
        ngx_http_close_connection(c);
        return;
    }


    rev->handler = ngx_http_process_request_line;// 将连接的读事件的处理函数设置为ngx_http_process_request_line函数
    ngx_http_process_request_line(rev);
}


你可能感兴趣的:(nginx)