summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_conn.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2017-12-28 16:01:06 +0300
committerIgor Sysoev <igor@sysoev.ru>2017-12-28 16:01:06 +0300
commit9a6d3c5775d945509c7c2cbec48be59757da42c3 (patch)
tree7129c13d6027a45e1a324deab373125bd7a14794 /src/nxt_conn.c
parent497faf1b9abb188cab40c389a9e6221add5dd496 (diff)
downloadunit-9a6d3c5775d945509c7c2cbec48be59757da42c3.tar.gz
unit-9a6d3c5775d945509c7c2cbec48be59757da42c3.tar.bz2
HTTP keep-alive connections support.
Diffstat (limited to 'src/nxt_conn.c')
-rw-r--r--src/nxt_conn.c59
1 files changed, 57 insertions, 2 deletions
diff --git a/src/nxt_conn.c b/src/nxt_conn.c
index 854181ca..6d0182e3 100644
--- a/src/nxt_conn.c
+++ b/src/nxt_conn.c
@@ -85,8 +85,6 @@ nxt_conn_create(nxt_mp_t *mp, nxt_task_t *task)
nxt_conn_timer_init(&c->read_timer, c, c->socket.read_work_queue);
nxt_conn_timer_init(&c->write_timer, c, c->socket.write_work_queue);
- nxt_queue_init(&c->requests);
-
nxt_log_debug(&c->log, "connections: %uD", thr->engine->connections);
return c;
@@ -165,3 +163,60 @@ nxt_conn_work_queue_set(nxt_conn_t *c, nxt_work_queue_t *wq)
c->read_timer.work_queue = wq;
c->write_timer.work_queue = wq;
}
+
+
+nxt_sockaddr_t *
+nxt_conn_local_addr(nxt_task_t *task, nxt_conn_t *c)
+{
+ int ret;
+ size_t size, length;
+ socklen_t socklen;
+ nxt_sockaddr_t *sa;
+
+ if (c->local != NULL) {
+ return c->local;
+ }
+
+ /* AF_UNIX should not get in here. */
+
+ switch (c->remote->u.sockaddr.sa_family) {
+#if (NXT_INET6)
+ case AF_INET6:
+ socklen = sizeof(struct sockaddr_in6);
+ length = NXT_INET6_ADDR_STR_LEN;
+ size = offsetof(nxt_sockaddr_t, u) + socklen + length;
+ break;
+#endif
+ case AF_INET:
+ default:
+ socklen = sizeof(struct sockaddr_in);
+ length = NXT_INET_ADDR_STR_LEN;
+ size = offsetof(nxt_sockaddr_t, u) + socklen + length;
+ break;
+ }
+
+ sa = nxt_mp_get(c->mem_pool, size);
+ if (nxt_slow_path(sa == NULL)) {
+ return NULL;
+ }
+
+ sa->socklen = socklen;
+ sa->length = length;
+
+ ret = getsockname(c->socket.fd, &sa->u.sockaddr, &socklen);
+ if (nxt_slow_path(ret != 0)) {
+ nxt_log(task, NXT_LOG_CRIT, "getsockname(%d) failed", c->socket.fd);
+ return NULL;
+ }
+
+ c->local = sa;
+
+ nxt_sockaddr_text(sa);
+
+ /*
+ * TODO: here we can adjust the end of non-freeable block
+ * in c->mem_pool to the end of actual sockaddr length.
+ */
+
+ return sa;
+}