nxt_conn.c (430:3a24c399394f) nxt_conn.c (431:5817734dd9b9)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

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

80 c->sendfile = NXT_CONN_SENDFILE_UNSET;
81
82 c->socket.read_work_queue = &thr->engine->fast_work_queue;
83 c->socket.write_work_queue = &thr->engine->fast_work_queue;
84
85 nxt_conn_timer_init(&c->read_timer, c, c->socket.read_work_queue);
86 nxt_conn_timer_init(&c->write_timer, c, c->socket.write_work_queue);
87
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

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

80 c->sendfile = NXT_CONN_SENDFILE_UNSET;
81
82 c->socket.read_work_queue = &thr->engine->fast_work_queue;
83 c->socket.write_work_queue = &thr->engine->fast_work_queue;
84
85 nxt_conn_timer_init(&c->read_timer, c, c->socket.read_work_queue);
86 nxt_conn_timer_init(&c->write_timer, c, c->socket.write_work_queue);
87
88 nxt_queue_init(&c->requests);
89
90 nxt_log_debug(&c->log, "connections: %uD", thr->engine->connections);
91
92 return c;
93}
94
95
96void
97nxt_conn_free(nxt_task_t *task, nxt_conn_t *c)

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

160void
161nxt_conn_work_queue_set(nxt_conn_t *c, nxt_work_queue_t *wq)
162{
163 c->read_work_queue = wq;
164 c->write_work_queue = wq;
165 c->read_timer.work_queue = wq;
166 c->write_timer.work_queue = wq;
167}
88 nxt_log_debug(&c->log, "connections: %uD", thr->engine->connections);
89
90 return c;
91}
92
93
94void
95nxt_conn_free(nxt_task_t *task, nxt_conn_t *c)

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

158void
159nxt_conn_work_queue_set(nxt_conn_t *c, nxt_work_queue_t *wq)
160{
161 c->read_work_queue = wq;
162 c->write_work_queue = wq;
163 c->read_timer.work_queue = wq;
164 c->write_timer.work_queue = wq;
165}
166
167
168nxt_sockaddr_t *
169nxt_conn_local_addr(nxt_task_t *task, nxt_conn_t *c)
170{
171 int ret;
172 size_t size, length;
173 socklen_t socklen;
174 nxt_sockaddr_t *sa;
175
176 if (c->local != NULL) {
177 return c->local;
178 }
179
180 /* AF_UNIX should not get in here. */
181
182 switch (c->remote->u.sockaddr.sa_family) {
183#if (NXT_INET6)
184 case AF_INET6:
185 socklen = sizeof(struct sockaddr_in6);
186 length = NXT_INET6_ADDR_STR_LEN;
187 size = offsetof(nxt_sockaddr_t, u) + socklen + length;
188 break;
189#endif
190 case AF_INET:
191 default:
192 socklen = sizeof(struct sockaddr_in);
193 length = NXT_INET_ADDR_STR_LEN;
194 size = offsetof(nxt_sockaddr_t, u) + socklen + length;
195 break;
196 }
197
198 sa = nxt_mp_get(c->mem_pool, size);
199 if (nxt_slow_path(sa == NULL)) {
200 return NULL;
201 }
202
203 sa->socklen = socklen;
204 sa->length = length;
205
206 ret = getsockname(c->socket.fd, &sa->u.sockaddr, &socklen);
207 if (nxt_slow_path(ret != 0)) {
208 nxt_log(task, NXT_LOG_CRIT, "getsockname(%d) failed", c->socket.fd);
209 return NULL;
210 }
211
212 c->local = sa;
213
214 nxt_sockaddr_text(sa);
215
216 /*
217 * TODO: here we can adjust the end of non-freeable block
218 * in c->mem_pool to the end of actual sockaddr length.
219 */
220
221 return sa;
222}