ngx_pool_t *
ngx_create_pool(size_t size, ngx_log_t *log)
{
    ngx_pool_t  *p;
    p = ngx_alloc(size, log);
    if (p == NULL) {
        return NULL;
    }
    p->d.last = (u_char *) p + sizeof(ngx_pool_t);
    p->d.end = (u_char *) p + size;
    p->d.next = NULL;
    size = size - sizeof(ngx_pool_t);
    p->max = (size < NGX_MAX_ALLOC_FROM_POOL) ? size : NGX_MAX_ALLOC_FROM_POOL;
    p->current = p;
    p->chain = NULL;
    p->large = NULL;
    p->cleanup = NULL;
    p->log = log;
    return p;
}
['void\nngx_event_accept(ngx_event_t *ev)\n{\n    socklen_t          socklen;\n    ngx_err_t          err;\n    ngx_log_t         *log;\n    ngx_socket_t       s;\n    ngx_event_t       *rev, *wev;\n    ngx_listening_t   *ls;\n    ngx_connection_t  *c, *lc;\n    ngx_event_conf_t  *ecf;\n    u_char             sa[NGX_SOCKADDRLEN];\n    ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module);\n    if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {\n        ev->available = 1;\n    } else if (!(ngx_event_flags & NGX_USE_KQUEUE_EVENT)) {\n        ev->available = ecf->multi_accept;\n    }\n    lc = ev->data;\n    ls = lc->listening;\n    ev->ready = 0;\n    ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,\n                   "accept on %V, ready: %d", &ls->addr_text, ev->available);\n    do {\n        socklen = NGX_SOCKADDRLEN;\n        s = accept(lc->fd, (struct sockaddr *) sa, &socklen);\n        if (s == -1) {\n            err = ngx_socket_errno;\n            if (err == NGX_EAGAIN) {\n                ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err,\n                               "accept() not ready");\n                return;\n            }\n            ngx_log_error((err == NGX_ECONNABORTED) ? NGX_LOG_ERR:\n                                                      NGX_LOG_ALERT,\n                          ev->log, err, "accept() failed");\n            if (err == NGX_ECONNABORTED) {\n                if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {\n                    ev->available--;\n                }\n                if (ev->available) {\n                    continue;\n                }\n            }\n            return;\n        }\n#if (NGX_STAT_STUB)\n        ngx_atomic_fetch_add(ngx_stat_accepted, 1);\n#endif\n        ngx_accept_disabled = ngx_cycle->connection_n / 8\n                              - ngx_cycle->free_connection_n;\n        c = ngx_get_connection(s, ev->log);\n        if (c == NULL) {\n            if (ngx_close_socket(s) == -1) {\n                ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,\n                              ngx_close_socket_n " failed");\n            }\n            return;\n        }\n#if (NGX_STAT_STUB)\n        ngx_atomic_fetch_add(ngx_stat_active, 1);\n#endif\n        c->pool = ngx_create_pool(ls->pool_size, ev->log);\n        if (c->pool == NULL) {\n            ngx_close_accepted_connection(c);\n            return;\n        }\n        c->sockaddr = ngx_palloc(c->pool, socklen);\n        if (c->sockaddr == NULL) {\n            ngx_close_accepted_connection(c);\n            return;\n        }\n        ngx_memcpy(c->sockaddr, sa, socklen);\n        log = ngx_palloc(c->pool, sizeof(ngx_log_t));\n        if (log == NULL) {\n            ngx_close_accepted_connection(c);\n            return;\n        }\n        if (ngx_inherited_nonblocking) {\n            if (ngx_event_flags & NGX_USE_AIO_EVENT) {\n                if (ngx_blocking(s) == -1) {\n                    ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,\n                                  ngx_blocking_n " failed");\n                    ngx_close_accepted_connection(c);\n                    return;\n                }\n            }\n        } else {\n            if (!(ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT))) {\n                if (ngx_nonblocking(s) == -1) {\n                    ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,\n                                  ngx_nonblocking_n " failed");\n                    ngx_close_accepted_connection(c);\n                    return;\n                }\n            }\n        }\n        *log = ls->log;\n        c->recv = ngx_recv;\n        c->send = ngx_send;\n        c->recv_chain = ngx_recv_chain;\n        c->send_chain = ngx_send_chain;\n        c->log = log;\n        c->pool->log = log;\n        c->socklen = socklen;\n        c->listening = ls;\n        c->local_sockaddr = ls->sockaddr;\n        c->local_socklen = ls->socklen;\n        c->unexpected_eof = 1;\n        rev = c->read;\n        wev = c->write;\n        wev->ready = 1;\n        if (ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT)) {\n            rev->ready = 1;\n        }\n        if (ev->deferred_accept) {\n            rev->ready = 1;\n#if (NGX_HAVE_KQUEUE)\n            rev->available = 1;\n#endif\n        }\n        rev->log = log;\n        wev->log = log;\n        c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1);\n#if (NGX_STAT_STUB)\n        ngx_atomic_fetch_add(ngx_stat_handled, 1);\n#endif\n#if (NGX_THREADS)\n        rev->lock = &c->lock;\n        wev->lock = &c->lock;\n        rev->own_lock = &c->lock;\n        wev->own_lock = &c->lock;\n#endif\n        if (ls->addr_ntop) {\n            c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len);\n            if (c->addr_text.data == NULL) {\n                ngx_close_accepted_connection(c);\n                return;\n            }\n            c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->addr_text.data,\n                                             ls->addr_text_max_len, 0);\n            if (c->addr_text.len == 0) {\n                ngx_close_accepted_connection(c);\n                return;\n            }\n        }\n#if (NGX_DEBUG)\n        {\n        in_addr_t            i;\n        ngx_event_debug_t   *dc;\n        struct sockaddr_in  *sin;\n        sin = (struct sockaddr_in *) sa;\n        dc = ecf->debug_connection.elts;\n        for (i = 0; i < ecf->debug_connection.nelts; i++) {\n            if ((sin->sin_addr.s_addr & dc[i].mask) == dc[i].addr) {\n                log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL;\n                break;\n            }\n        }\n        }\n#endif\n        ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0,\n                       "*%d accept: %V fd:%d", c->number, &c->addr_text, s);\n        if (ngx_add_conn && (ngx_event_flags & NGX_USE_EPOLL_EVENT) == 0) {\n            if (ngx_add_conn(c) == NGX_ERROR) {\n                ngx_close_accepted_connection(c);\n                return;\n            }\n        }\n        log->data = NULL;\n        log->handler = NULL;\n        ls->handler(c);\n        if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {\n            ev->available--;\n        }\n    } while (ev->available);\n}', 'ngx_pool_t *\nngx_create_pool(size_t size, ngx_log_t *log)\n{\n    ngx_pool_t  *p;\n    p = ngx_alloc(size, log);\n    if (p == NULL) {\n        return NULL;\n    }\n    p->d.last = (u_char *) p + sizeof(ngx_pool_t);\n    p->d.end = (u_char *) p + size;\n    p->d.next = NULL;\n    size = size - sizeof(ngx_pool_t);\n    p->max = (size < NGX_MAX_ALLOC_FROM_POOL) ? size : NGX_MAX_ALLOC_FROM_POOL;\n    p->current = p;\n    p->chain = NULL;\n    p->large = NULL;\n    p->cleanup = NULL;\n    p->log = log;\n    return p;\n}']