nxt_sockaddr.c (211:6738bb76ae0a) nxt_sockaddr.c (337:854a1a440616)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 7 unchanged lines hidden (view full) ---

16static nxt_sockaddr_t *nxt_sockaddr_inet_parse(nxt_mp_t *mp, nxt_str_t *addr);
17
18static nxt_int_t nxt_job_sockaddr_unix_parse(nxt_job_sockaddr_parse_t *jbs);
19static nxt_int_t nxt_job_sockaddr_inet6_parse(nxt_job_sockaddr_parse_t *jbs);
20static nxt_int_t nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs);
21
22
23nxt_sockaddr_t *
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 7 unchanged lines hidden (view full) ---

16static nxt_sockaddr_t *nxt_sockaddr_inet_parse(nxt_mp_t *mp, nxt_str_t *addr);
17
18static nxt_int_t nxt_job_sockaddr_unix_parse(nxt_job_sockaddr_parse_t *jbs);
19static nxt_int_t nxt_job_sockaddr_inet6_parse(nxt_job_sockaddr_parse_t *jbs);
20static nxt_int_t nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs);
21
22
23nxt_sockaddr_t *
24nxt_sockaddr_cache_alloc(nxt_event_engine_t *engine, nxt_listen_event_t *lev)
25{
26 size_t size;
27 nxt_sockaddr_t *sa;
28 nxt_listen_socket_t *ls;
29
30 ls = lev->listen;
31
32 size = offsetof(nxt_sockaddr_t, u) + ls->socklen + ls->address_length;
33
34 sa = nxt_event_engine_mem_alloc(engine, &lev->mem_cache, size);
35
36 if (nxt_fast_path(sa != NULL)) {
37 /* Zero only beginning of structure up to sockaddr_un.sun_path[1]. */
38 nxt_memzero(sa, offsetof(nxt_sockaddr_t, u.sockaddr.sa_data[1]));
39
40 sa->sockaddr_size = size;
41 sa->socklen = ls->socklen;
42 sa->length = ls->address_length;
43
44 sa->type = ls->sockaddr->type;
45 /*
46 * Set address family for unspecified Unix domain socket,
47 * because these sockaddr's are not updated by old BSD systems,
48 * see comment in nxt_conn_io_accept().
49 */
50 sa->u.sockaddr.sa_family = ls->sockaddr->u.sockaddr.sa_family;
51 }
52
53 return sa;
54}
55
56
57void
58nxt_sockaddr_cache_free(nxt_event_engine_t *engine, nxt_conn_t *c)
59{
60 nxt_event_engine_mem_free(engine, &c->listen->mem_cache, c->remote);
61}
62
63
64nxt_sockaddr_t *
24nxt_sockaddr_alloc(nxt_mp_t *mp, socklen_t socklen, size_t address_length)
25{
26 size_t size;
27 nxt_sockaddr_t *sa;
28
29 size = offsetof(nxt_sockaddr_t, u) + socklen + address_length;
30
31 /*

--- 1244 unchanged lines hidden ---
65nxt_sockaddr_alloc(nxt_mp_t *mp, socklen_t socklen, size_t address_length)
66{
67 size_t size;
68 nxt_sockaddr_t *sa;
69
70 size = offsetof(nxt_sockaddr_t, u) + socklen + address_length;
71
72 /*

--- 1244 unchanged lines hidden ---