static ngx_listening_t *
ngx_http_add_listening(ngx_conf_t *cf, ngx_http_conf_addr_t *addr)
{
    ngx_listening_t           *ls;
    struct sockaddr           *sa;
    ngx_http_core_loc_conf_t  *clcf;
    ngx_http_core_srv_conf_t  *cscf;
    u_char                     text[NGX_SOCKADDR_STRLEN];
    ls = ngx_array_push(&cf->cycle->listening);
    if (ls == NULL) {
        return NULL;
    }
    ngx_memzero(ls, sizeof(ngx_listening_t));
    sa = ngx_palloc(cf->pool, addr->socklen);
    if (sa == NULL) {
        return NULL;
    }
    ngx_memcpy(sa, addr->sockaddr, addr->socklen);
    ls->sockaddr = sa;
    ls->socklen = addr->socklen;
    ls->addr_text.len = ngx_sock_ntop(sa, text, NGX_SOCKADDR_STRLEN, 1);
    ls->addr_text.data = ngx_pnalloc(cf->pool, ls->addr_text.len);
    if (ls->addr_text.data == NULL) {
        return NULL;
    }
    ngx_memcpy(ls->addr_text.data, text, ls->addr_text.len);
    ls->fd = (ngx_socket_t) -1;
    ls->type = SOCK_STREAM;
    switch (ls->sockaddr->sa_family) {
#if (NGX_HAVE_INET6)
    case AF_INET6:
         ls->addr_text_max_len = NGX_INET6_ADDRSTRLEN;
         break;
#endif
    case AF_INET:
         ls->addr_text_max_len = NGX_INET_ADDRSTRLEN;
         break;
    default:
         ls->addr_text_max_len = NGX_SOCKADDR_STRLEN;
         break;
    }
    ls->addr_ntop = 1;
    ls->handler = ngx_http_init_connection;
    cscf = addr->core_srv_conf;
    ls->pool_size = cscf->connection_pool_size;
    ls->post_accept_timeout = cscf->client_header_timeout;
    clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];
    ls->log = *clcf->err_log;
    ls->log.data = &ls->addr_text;
    ls->log.handler = ngx_accept_log_error;
#if (NGX_WIN32)
    {
    ngx_iocp_conf_t  *iocpcf;
    iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module);
    if (iocpcf->acceptex_read) {
        ls->post_accept_buffer_size = cscf->client_header_buffer_size;
    }
    }
#endif
    ls->backlog = addr->listen_conf->backlog;
    ls->rcvbuf = addr->listen_conf->rcvbuf;
    ls->sndbuf = addr->listen_conf->sndbuf;
#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
    ls->accept_filter = addr->listen_conf->accept_filter;
#endif
#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
    ls->deferred_accept = addr->listen_conf->deferred_accept;
#endif
#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
    ls->ipv6only = addr->listen_conf->ipv6only;
#endif
    return ls;
}
['static ngx_listening_t *\nngx_http_add_listening(ngx_conf_t *cf, ngx_http_conf_addr_t *addr)\n{\n    ngx_listening_t           *ls;\n    struct sockaddr           *sa;\n    ngx_http_core_loc_conf_t  *clcf;\n    ngx_http_core_srv_conf_t  *cscf;\n    u_char                     text[NGX_SOCKADDR_STRLEN];\n    ls = ngx_array_push(&cf->cycle->listening);\n    if (ls == NULL) {\n        return NULL;\n    }\n    ngx_memzero(ls, sizeof(ngx_listening_t));\n    sa = ngx_palloc(cf->pool, addr->socklen);\n    if (sa == NULL) {\n        return NULL;\n    }\n    ngx_memcpy(sa, addr->sockaddr, addr->socklen);\n    ls->sockaddr = sa;\n    ls->socklen = addr->socklen;\n    ls->addr_text.len = ngx_sock_ntop(sa, text, NGX_SOCKADDR_STRLEN, 1);\n    ls->addr_text.data = ngx_pnalloc(cf->pool, ls->addr_text.len);\n    if (ls->addr_text.data == NULL) {\n        return NULL;\n    }\n    ngx_memcpy(ls->addr_text.data, text, ls->addr_text.len);\n    ls->fd = (ngx_socket_t) -1;\n    ls->type = SOCK_STREAM;\n    switch (ls->sockaddr->sa_family) {\n#if (NGX_HAVE_INET6)\n    case AF_INET6:\n         ls->addr_text_max_len = NGX_INET6_ADDRSTRLEN;\n         break;\n#endif\n    case AF_INET:\n         ls->addr_text_max_len = NGX_INET_ADDRSTRLEN;\n         break;\n    default:\n         ls->addr_text_max_len = NGX_SOCKADDR_STRLEN;\n         break;\n    }\n    ls->addr_ntop = 1;\n    ls->handler = ngx_http_init_connection;\n    cscf = addr->core_srv_conf;\n    ls->pool_size = cscf->connection_pool_size;\n    ls->post_accept_timeout = cscf->client_header_timeout;\n    clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];\n    ls->log = *clcf->err_log;\n    ls->log.data = &ls->addr_text;\n    ls->log.handler = ngx_accept_log_error;\n#if (NGX_WIN32)\n    {\n    ngx_iocp_conf_t  *iocpcf;\n    iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module);\n    if (iocpcf->acceptex_read) {\n        ls->post_accept_buffer_size = cscf->client_header_buffer_size;\n    }\n    }\n#endif\n    ls->backlog = addr->listen_conf->backlog;\n    ls->rcvbuf = addr->listen_conf->rcvbuf;\n    ls->sndbuf = addr->listen_conf->sndbuf;\n#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)\n    ls->accept_filter = addr->listen_conf->accept_filter;\n#endif\n#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)\n    ls->deferred_accept = addr->listen_conf->deferred_accept;\n#endif\n#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)\n    ls->ipv6only = addr->listen_conf->ipv6only;\n#endif\n    return ls;\n}', 'size_t\nngx_sock_ntop(struct sockaddr *sa, u_char *text, size_t len, ngx_uint_t port)\n{\n    u_char               *p;\n    struct sockaddr_in   *sin;\n#if (NGX_HAVE_INET6)\n    size_t                n;\n    struct sockaddr_in6  *sin6;\n#endif\n    switch (sa->sa_family) {\n    case AF_INET:\n        sin = (struct sockaddr_in *) sa;\n        p = (u_char *) &sin->sin_addr;\n        if (port) {\n            p = ngx_snprintf(text, len, "%ud.%ud.%ud.%ud:%d",\n                             p[0], p[1], p[2], p[3], ntohs(sin->sin_port));\n        } else {\n            p = ngx_snprintf(text, len, "%ud.%ud.%ud.%ud",\n                             p[0], p[1], p[2], p[3]);\n        }\n        return (p - text);\n#if (NGX_HAVE_INET6)\n    case AF_INET6:\n        sin6 = (struct sockaddr_in6 *) sa;\n        n = 0;\n        if (port) {\n            text[n++] = \'[\';\n        }\n        n = ngx_inet6_ntop((u_char *) &sin6->sin6_addr, &text[n], len);\n        if (port) {\n            n = ngx_sprintf(&text[1 + n], "]:%d",\n                            ntohs(sin6->sin6_port)) - text;\n        }\n        return n;\n#endif\n    default:\n        return 0;\n    }\n}', 'void *\nngx_pnalloc(ngx_pool_t *pool, size_t size)\n{\n    u_char      *m;\n    ngx_pool_t  *p;\n    if (size <= pool->max) {\n        p = pool->current;\n        do {\n            m = p->d.last;\n            if ((size_t) (p->d.end - m) >= size) {\n                p->d.last = m + size;\n                return m;\n            }\n            p = p->d.next;\n        } while (p);\n        return ngx_palloc_block(pool, size);\n    }\n    return ngx_palloc_large(pool, size);\n}']