summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_sockaddr.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2017-09-27 19:22:59 +0300
committerIgor Sysoev <igor@sysoev.ru>2017-09-27 19:22:59 +0300
commitbfa808d68997d74bfe0d54196bbbb649646787c1 (patch)
tree16751ca3da7dfd1c3c7830b3203fffdaea55b0cf /src/nxt_sockaddr.c
parent752038eea857988045ce72252e0d1c19509981b3 (diff)
downloadunit-bfa808d68997d74bfe0d54196bbbb649646787c1.tar.gz
unit-bfa808d68997d74bfe0d54196bbbb649646787c1.tar.bz2
Event engine memory cache for nxt_sockaddr_t.
Introducing event engine memory cache and using the cache for nxt_sockaddr_t structures.
Diffstat (limited to '')
-rw-r--r--src/nxt_sockaddr.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/nxt_sockaddr.c b/src/nxt_sockaddr.c
index 74de0984..38e2189e 100644
--- a/src/nxt_sockaddr.c
+++ b/src/nxt_sockaddr.c
@@ -21,6 +21,47 @@ static nxt_int_t nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs);
nxt_sockaddr_t *
+nxt_sockaddr_cache_alloc(nxt_event_engine_t *engine, nxt_listen_event_t *lev)
+{
+ size_t size;
+ nxt_sockaddr_t *sa;
+ nxt_listen_socket_t *ls;
+
+ ls = lev->listen;
+
+ size = offsetof(nxt_sockaddr_t, u) + ls->socklen + ls->address_length;
+
+ sa = nxt_event_engine_mem_alloc(engine, &lev->mem_cache, size);
+
+ if (nxt_fast_path(sa != NULL)) {
+ /* Zero only beginning of structure up to sockaddr_un.sun_path[1]. */
+ nxt_memzero(sa, offsetof(nxt_sockaddr_t, u.sockaddr.sa_data[1]));
+
+ sa->sockaddr_size = size;
+ sa->socklen = ls->socklen;
+ sa->length = ls->address_length;
+
+ sa->type = ls->sockaddr->type;
+ /*
+ * Set address family for unspecified Unix domain socket,
+ * because these sockaddr's are not updated by old BSD systems,
+ * see comment in nxt_conn_io_accept().
+ */
+ sa->u.sockaddr.sa_family = ls->sockaddr->u.sockaddr.sa_family;
+ }
+
+ return sa;
+}
+
+
+void
+nxt_sockaddr_cache_free(nxt_event_engine_t *engine, nxt_conn_t *c)
+{
+ nxt_event_engine_mem_free(engine, &c->listen->mem_cache, c->remote);
+}
+
+
+nxt_sockaddr_t *
nxt_sockaddr_alloc(nxt_mp_t *mp, socklen_t socklen, size_t address_length)
{
size_t size;