xref: /unit/src/nxt_router.c (revision 1828)
120Sigor@sysoev.ru 
220Sigor@sysoev.ru /*
320Sigor@sysoev.ru  * Copyright (C) Igor Sysoev
420Sigor@sysoev.ru  * Copyright (C) Valentin V. Bartenev
520Sigor@sysoev.ru  * Copyright (C) NGINX, Inc.
620Sigor@sysoev.ru  */
720Sigor@sysoev.ru 
853Sigor@sysoev.ru #include <nxt_router.h>
9115Sigor@sysoev.ru #include <nxt_conf.h>
10774Svbart@nginx.com #if (NXT_TLS)
11774Svbart@nginx.com #include <nxt_cert.h>
12774Svbart@nginx.com #endif
13431Sigor@sysoev.ru #include <nxt_http.h>
14743Smax.romanov@nginx.com #include <nxt_port_memory_int.h>
15743Smax.romanov@nginx.com #include <nxt_unit_request.h>
16743Smax.romanov@nginx.com #include <nxt_unit_response.h>
171131Smax.romanov@nginx.com #include <nxt_router_request.h>
181555Smax.romanov@nginx.com #include <nxt_app_queue.h>
191555Smax.romanov@nginx.com #include <nxt_port_queue.h>
2020Sigor@sysoev.ru 
21115Sigor@sysoev.ru typedef struct {
22318Smax.romanov@nginx.com     nxt_str_t         type;
23507Smax.romanov@nginx.com     uint32_t          processes;
24507Smax.romanov@nginx.com     uint32_t          max_processes;
25507Smax.romanov@nginx.com     uint32_t          spare_processes;
26318Smax.romanov@nginx.com     nxt_msec_t        timeout;
27507Smax.romanov@nginx.com     nxt_msec_t        idle_timeout;
28318Smax.romanov@nginx.com     uint32_t          requests;
29318Smax.romanov@nginx.com     nxt_conf_value_t  *limits_value;
30507Smax.romanov@nginx.com     nxt_conf_value_t  *processes_value;
311473Svbart@nginx.com     nxt_conf_value_t  *targets_value;
32133Sigor@sysoev.ru } nxt_router_app_conf_t;
33133Sigor@sysoev.ru 
34133Sigor@sysoev.ru 
35133Sigor@sysoev.ru typedef struct {
36964Sigor@sysoev.ru     nxt_str_t         pass;
37964Sigor@sysoev.ru     nxt_str_t         application;
38115Sigor@sysoev.ru } nxt_router_listener_conf_t;
39115Sigor@sysoev.ru 
40115Sigor@sysoev.ru 
41774Svbart@nginx.com #if (NXT_TLS)
42774Svbart@nginx.com 
43774Svbart@nginx.com typedef struct {
44774Svbart@nginx.com     nxt_str_t          name;
45774Svbart@nginx.com     nxt_socket_conf_t  *conf;
46774Svbart@nginx.com 
47774Svbart@nginx.com     nxt_queue_link_t   link;  /* for nxt_socket_conf_t.tls */
48774Svbart@nginx.com } nxt_router_tlssock_t;
49774Svbart@nginx.com 
50774Svbart@nginx.com #endif
51774Svbart@nginx.com 
52774Svbart@nginx.com 
53198Sigor@sysoev.ru typedef struct {
54*1828Sa.suvorov@f5.com     nxt_str_t               *name;
55198Sigor@sysoev.ru     nxt_socket_conf_t       *socket_conf;
56198Sigor@sysoev.ru     nxt_router_temp_conf_t  *temp_conf;
57*1828Sa.suvorov@f5.com     nxt_bool_t              last;
58198Sigor@sysoev.ru } nxt_socket_rpc_t;
59198Sigor@sysoev.ru 
60198Sigor@sysoev.ru 
61507Smax.romanov@nginx.com typedef struct {
62507Smax.romanov@nginx.com     nxt_app_t               *app;
63507Smax.romanov@nginx.com     nxt_router_temp_conf_t  *temp_conf;
64507Smax.romanov@nginx.com } nxt_app_rpc_t;
65507Smax.romanov@nginx.com 
66507Smax.romanov@nginx.com 
671488St.nateldemoura@f5.com static nxt_int_t nxt_router_prefork(nxt_task_t *task, nxt_process_t *process,
681488St.nateldemoura@f5.com     nxt_mp_t *mp);
691488St.nateldemoura@f5.com static nxt_int_t nxt_router_start(nxt_task_t *task, nxt_process_data_t *data);
70662Smax.romanov@nginx.com static void nxt_router_greet_controller(nxt_task_t *task,
71662Smax.romanov@nginx.com     nxt_port_t *controller_port);
72662Smax.romanov@nginx.com 
73507Smax.romanov@nginx.com static nxt_int_t nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app);
74425Smax.romanov@nginx.com 
751552Smax.romanov@nginx.com static void nxt_router_new_port_handler(nxt_task_t *task,
761552Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg);
771552Smax.romanov@nginx.com static void nxt_router_conf_data_handler(nxt_task_t *task,
781552Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg);
791552Smax.romanov@nginx.com static void nxt_router_remove_pid_handler(nxt_task_t *task,
801552Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg);
811552Smax.romanov@nginx.com static void nxt_router_access_log_reopen_handler(nxt_task_t *task,
821552Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg);
831552Smax.romanov@nginx.com 
84139Sigor@sysoev.ru static nxt_router_temp_conf_t *nxt_router_temp_conf(nxt_task_t *task);
85198Sigor@sysoev.ru static void nxt_router_conf_apply(nxt_task_t *task, void *obj, void *data);
86198Sigor@sysoev.ru static void nxt_router_conf_ready(nxt_task_t *task,
87139Sigor@sysoev.ru     nxt_router_temp_conf_t *tmcf);
88139Sigor@sysoev.ru static void nxt_router_conf_error(nxt_task_t *task,
89139Sigor@sysoev.ru     nxt_router_temp_conf_t *tmcf);
90139Sigor@sysoev.ru static void nxt_router_conf_send(nxt_task_t *task,
91193Smax.romanov@nginx.com     nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type);
9253Sigor@sysoev.ru 
93115Sigor@sysoev.ru static nxt_int_t nxt_router_conf_create(nxt_task_t *task,
94115Sigor@sysoev.ru     nxt_router_temp_conf_t *tmcf, u_char *start, u_char *end);
951183Svbart@nginx.com static nxt_int_t nxt_router_conf_process_static(nxt_task_t *task,
961183Svbart@nginx.com     nxt_router_conf_t *rtcf, nxt_conf_value_t *conf);
971563Svbart@nginx.com 
98133Sigor@sysoev.ru static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name);
991563Svbart@nginx.com static nxt_int_t nxt_router_apps_hash_test(nxt_lvlhsh_query_t *lhq, void *data);
1001563Svbart@nginx.com static nxt_int_t nxt_router_apps_hash_add(nxt_router_conf_t *rtcf,
1011563Svbart@nginx.com     nxt_app_t *app);
1021563Svbart@nginx.com static nxt_app_t *nxt_router_apps_hash_get(nxt_router_conf_t *rtcf,
1031563Svbart@nginx.com     nxt_str_t *name);
1041563Svbart@nginx.com static void nxt_router_apps_hash_use(nxt_task_t *task, nxt_router_conf_t *rtcf,
1051563Svbart@nginx.com     int i);
1061563Svbart@nginx.com 
1071555Smax.romanov@nginx.com static nxt_int_t nxt_router_app_queue_init(nxt_task_t *task,
1081555Smax.romanov@nginx.com     nxt_port_t *port);
1091555Smax.romanov@nginx.com static nxt_int_t nxt_router_port_queue_init(nxt_task_t *task,
1101555Smax.romanov@nginx.com     nxt_port_t *port);
1111555Smax.romanov@nginx.com static nxt_int_t nxt_router_port_queue_map(nxt_task_t *task,
1121555Smax.romanov@nginx.com     nxt_port_t *port, nxt_fd_t fd);
113198Sigor@sysoev.ru static void nxt_router_listen_socket_rpc_create(nxt_task_t *task,
114198Sigor@sysoev.ru     nxt_router_temp_conf_t *tmcf, nxt_socket_conf_t *skcf);
115198Sigor@sysoev.ru static void nxt_router_listen_socket_ready(nxt_task_t *task,
116198Sigor@sysoev.ru     nxt_port_recv_msg_t *msg, void *data);
117198Sigor@sysoev.ru static void nxt_router_listen_socket_error(nxt_task_t *task,
118198Sigor@sysoev.ru     nxt_port_recv_msg_t *msg, void *data);
119774Svbart@nginx.com #if (NXT_TLS)
120774Svbart@nginx.com static void nxt_router_tls_rpc_create(nxt_task_t *task,
121*1828Sa.suvorov@f5.com     nxt_router_temp_conf_t *tmcf, nxt_router_tlssock_t *tls, nxt_bool_t last);
122774Svbart@nginx.com static void nxt_router_tls_rpc_handler(nxt_task_t *task,
123774Svbart@nginx.com     nxt_port_recv_msg_t *msg, void *data);
124*1828Sa.suvorov@f5.com static nxt_int_t nxt_router_conf_tls_insert(nxt_router_temp_conf_t *tmcf,
125*1828Sa.suvorov@f5.com     nxt_conf_value_t *value, nxt_socket_conf_t *skcf);
126774Svbart@nginx.com #endif
127507Smax.romanov@nginx.com static void nxt_router_app_rpc_create(nxt_task_t *task,
128507Smax.romanov@nginx.com     nxt_router_temp_conf_t *tmcf, nxt_app_t *app);
129507Smax.romanov@nginx.com static void nxt_router_app_prefork_ready(nxt_task_t *task,
130507Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg, void *data);
131507Smax.romanov@nginx.com static void nxt_router_app_prefork_error(nxt_task_t *task,
132507Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg, void *data);
133359Sigor@sysoev.ru static nxt_socket_conf_t *nxt_router_socket_conf(nxt_task_t *task,
134359Sigor@sysoev.ru     nxt_router_temp_conf_t *tmcf, nxt_str_t *name);
135359Sigor@sysoev.ru static nxt_int_t nxt_router_listen_socket_find(nxt_router_temp_conf_t *tmcf,
136359Sigor@sysoev.ru     nxt_socket_conf_t *nskcf, nxt_sockaddr_t *sa);
13753Sigor@sysoev.ru 
13853Sigor@sysoev.ru static nxt_int_t nxt_router_engines_create(nxt_task_t *task,
13953Sigor@sysoev.ru     nxt_router_t *router, nxt_router_temp_conf_t *tmcf,
14053Sigor@sysoev.ru     const nxt_event_interface_t *interface);
141115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_create(nxt_router_temp_conf_t *tmcf,
142115Sigor@sysoev.ru     nxt_router_engine_conf_t *recf);
143115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_update(nxt_router_temp_conf_t *tmcf,
144115Sigor@sysoev.ru     nxt_router_engine_conf_t *recf);
145115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_delete(nxt_router_temp_conf_t *tmcf,
146115Sigor@sysoev.ru     nxt_router_engine_conf_t *recf);
147154Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_create(nxt_router_temp_conf_t *tmcf,
148154Sigor@sysoev.ru     nxt_router_engine_conf_t *recf, nxt_queue_t *sockets,
149154Sigor@sysoev.ru     nxt_work_handler_t handler);
150313Sigor@sysoev.ru static nxt_int_t nxt_router_engine_quit(nxt_router_temp_conf_t *tmcf,
151313Sigor@sysoev.ru     nxt_router_engine_conf_t *recf);
152139Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_delete(nxt_router_temp_conf_t *tmcf,
153139Sigor@sysoev.ru     nxt_router_engine_conf_t *recf, nxt_queue_t *sockets);
15453Sigor@sysoev.ru 
15553Sigor@sysoev.ru static nxt_int_t nxt_router_threads_create(nxt_task_t *task, nxt_runtime_t *rt,
15653Sigor@sysoev.ru     nxt_router_temp_conf_t *tmcf);
15753Sigor@sysoev.ru static nxt_int_t nxt_router_thread_create(nxt_task_t *task, nxt_runtime_t *rt,
15853Sigor@sysoev.ru     nxt_event_engine_t *engine);
159343Smax.romanov@nginx.com static void nxt_router_apps_sort(nxt_task_t *task, nxt_router_t *router,
160133Sigor@sysoev.ru     nxt_router_temp_conf_t *tmcf);
16153Sigor@sysoev.ru 
162315Sigor@sysoev.ru static void nxt_router_engines_post(nxt_router_t *router,
163315Sigor@sysoev.ru     nxt_router_temp_conf_t *tmcf);
164315Sigor@sysoev.ru static void nxt_router_engine_post(nxt_event_engine_t *engine,
165315Sigor@sysoev.ru     nxt_work_t *jobs);
16653Sigor@sysoev.ru 
16753Sigor@sysoev.ru static void nxt_router_thread_start(void *data);
1681545Smax.romanov@nginx.com static void nxt_router_rt_add_port(nxt_task_t *task, void *obj,
1691545Smax.romanov@nginx.com     void *data);
17053Sigor@sysoev.ru static void nxt_router_listen_socket_create(nxt_task_t *task, void *obj,
17153Sigor@sysoev.ru     void *data);
17253Sigor@sysoev.ru static void nxt_router_listen_socket_update(nxt_task_t *task, void *obj,
17353Sigor@sysoev.ru     void *data);
17453Sigor@sysoev.ru static void nxt_router_listen_socket_delete(nxt_task_t *task, void *obj,
17553Sigor@sysoev.ru     void *data);
176313Sigor@sysoev.ru static void nxt_router_worker_thread_quit(nxt_task_t *task, void *obj,
177313Sigor@sysoev.ru     void *data);
17853Sigor@sysoev.ru static void nxt_router_listen_socket_close(nxt_task_t *task, void *obj,
17953Sigor@sysoev.ru     void *data);
18053Sigor@sysoev.ru static void nxt_router_thread_exit_handler(nxt_task_t *task, void *obj,
18153Sigor@sysoev.ru     void *data);
1821547Smax.romanov@nginx.com static void nxt_router_req_headers_ack_handler(nxt_task_t *task,
1831547Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg, nxt_request_rpc_data_t *req_rpc_data);
184359Sigor@sysoev.ru static void nxt_router_listen_socket_release(nxt_task_t *task,
185359Sigor@sysoev.ru     nxt_socket_conf_t *skcf);
18653Sigor@sysoev.ru 
187630Svbart@nginx.com static void nxt_router_access_log_writer(nxt_task_t *task,
188630Svbart@nginx.com     nxt_http_request_t *r, nxt_router_access_log_t *access_log);
189630Svbart@nginx.com static u_char *nxt_router_access_log_date(u_char *buf, nxt_realtime_t *now,
190630Svbart@nginx.com     struct tm *tm, size_t size, const char *format);
191630Svbart@nginx.com static void nxt_router_access_log_open(nxt_task_t *task,
192630Svbart@nginx.com     nxt_router_temp_conf_t *tmcf);
193630Svbart@nginx.com static void nxt_router_access_log_ready(nxt_task_t *task,
194630Svbart@nginx.com     nxt_port_recv_msg_t *msg, void *data);
195630Svbart@nginx.com static void nxt_router_access_log_error(nxt_task_t *task,
196630Svbart@nginx.com     nxt_port_recv_msg_t *msg, void *data);
197630Svbart@nginx.com static void nxt_router_access_log_release(nxt_task_t *task,
198630Svbart@nginx.com     nxt_thread_spinlock_t *lock, nxt_router_access_log_t *access_log);
199651Svbart@nginx.com static void nxt_router_access_log_reopen_completion(nxt_task_t *task, void *obj,
200651Svbart@nginx.com     void *data);
201631Svbart@nginx.com static void nxt_router_access_log_reopen_ready(nxt_task_t *task,
202631Svbart@nginx.com     nxt_port_recv_msg_t *msg, void *data);
203631Svbart@nginx.com static void nxt_router_access_log_reopen_error(nxt_task_t *task,
204631Svbart@nginx.com     nxt_port_recv_msg_t *msg, void *data);
205630Svbart@nginx.com 
206343Smax.romanov@nginx.com static void nxt_router_app_port_ready(nxt_task_t *task,
207343Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg, void *data);
2081547Smax.romanov@nginx.com static nxt_int_t nxt_router_app_shared_port_send(nxt_task_t *task,
2091547Smax.romanov@nginx.com     nxt_port_t *app_port);
210343Smax.romanov@nginx.com static void nxt_router_app_port_error(nxt_task_t *task,
211343Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg, void *data);
212343Smax.romanov@nginx.com 
2131563Svbart@nginx.com static void nxt_router_app_use(nxt_task_t *task, nxt_app_t *app, int i);
214753Smax.romanov@nginx.com static void nxt_router_app_unlink(nxt_task_t *task, nxt_app_t *app);
2151123Smax.romanov@nginx.com 
216343Smax.romanov@nginx.com static void nxt_router_app_port_release(nxt_task_t *task, nxt_port_t *port,
2171123Smax.romanov@nginx.com     nxt_apr_action_t action);
2181547Smax.romanov@nginx.com static void nxt_router_app_port_get(nxt_task_t *task, nxt_app_t *app,
2191547Smax.romanov@nginx.com     nxt_request_rpc_data_t *req_rpc_data);
2201561Smax.romanov@nginx.com static void nxt_router_http_request_error(nxt_task_t *task, void *obj,
2211561Smax.romanov@nginx.com     void *data);
2221547Smax.romanov@nginx.com static void nxt_router_http_request_done(nxt_task_t *task, void *obj,
2231547Smax.romanov@nginx.com     void *data);
224141Smax.romanov@nginx.com 
2251566Smax.romanov@nginx.com static void nxt_router_dummy_buf_completion(nxt_task_t *task, void *obj,
2261566Smax.romanov@nginx.com     void *data);
227425Smax.romanov@nginx.com static void nxt_router_app_prepare_request(nxt_task_t *task,
2281547Smax.romanov@nginx.com     nxt_request_rpc_data_t *req_rpc_data);
2291007Salexander.borisov@nginx.com static nxt_buf_t *nxt_router_prepare_msg(nxt_task_t *task,
2301547Smax.romanov@nginx.com     nxt_http_request_t *r, nxt_app_t *app, const nxt_str_t *prefix);
231510Salexander.borisov@nginx.com 
232318Smax.romanov@nginx.com static void nxt_router_app_timeout(nxt_task_t *task, void *obj, void *data);
233507Smax.romanov@nginx.com static void nxt_router_adjust_idle_timer(nxt_task_t *task, void *obj,
234507Smax.romanov@nginx.com     void *data);
235507Smax.romanov@nginx.com static void nxt_router_app_idle_timeout(nxt_task_t *task, void *obj,
236507Smax.romanov@nginx.com     void *data);
237753Smax.romanov@nginx.com static void nxt_router_app_joint_release_handler(nxt_task_t *task, void *obj,
238507Smax.romanov@nginx.com     void *data);
239753Smax.romanov@nginx.com static void nxt_router_free_app(nxt_task_t *task, void *obj, void *data);
240431Sigor@sysoev.ru 
241431Sigor@sysoev.ru static const nxt_http_request_state_t  nxt_http_request_send_state;
242431Sigor@sysoev.ru static void nxt_http_request_send_body(nxt_task_t *task, void *obj, void *data);
243141Smax.romanov@nginx.com 
244753Smax.romanov@nginx.com static void nxt_router_app_joint_use(nxt_task_t *task,
245753Smax.romanov@nginx.com     nxt_app_joint_t *app_joint, int i);
246753Smax.romanov@nginx.com 
2471547Smax.romanov@nginx.com static void nxt_router_http_request_release_post(nxt_task_t *task,
2481007Salexander.borisov@nginx.com     nxt_http_request_t *r);
2491007Salexander.borisov@nginx.com static void nxt_router_http_request_release(nxt_task_t *task, void *obj,
2501007Salexander.borisov@nginx.com     void *data);
2511321Smax.romanov@nginx.com static void nxt_router_oosm_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
2521545Smax.romanov@nginx.com static void nxt_router_get_port_handler(nxt_task_t *task,
2531545Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg);
2541546Smax.romanov@nginx.com static void nxt_router_get_mmap_handler(nxt_task_t *task,
2551546Smax.romanov@nginx.com     nxt_port_recv_msg_t *msg);
2561007Salexander.borisov@nginx.com 
2571149Smax.romanov@nginx.com extern const nxt_http_request_state_t  nxt_http_websocket;
2581131Smax.romanov@nginx.com 
259119Smax.romanov@nginx.com static nxt_router_t  *nxt_router;
26020Sigor@sysoev.ru 
261743Smax.romanov@nginx.com static const nxt_str_t http_prefix = nxt_string("HTTP_");
262743Smax.romanov@nginx.com static const nxt_str_t empty_prefix = nxt_string("");
263743Smax.romanov@nginx.com 
264743Smax.romanov@nginx.com static const nxt_str_t  *nxt_app_msg_prefix[] = {
265804Svbart@nginx.com     &empty_prefix,
2661594Smax.romanov@nginx.com     &empty_prefix,
267743Smax.romanov@nginx.com     &http_prefix,
268743Smax.romanov@nginx.com     &http_prefix,
269743Smax.romanov@nginx.com     &http_prefix,
270977Smax.romanov@gmail.com     &empty_prefix,
271216Sigor@sysoev.ru };
272216Sigor@sysoev.ru 
273216Sigor@sysoev.ru 
2741488St.nateldemoura@f5.com static const nxt_port_handlers_t  nxt_router_process_port_handlers = {
2751488St.nateldemoura@f5.com     .quit         = nxt_signal_quit_handler,
276662Smax.romanov@nginx.com     .new_port     = nxt_router_new_port_handler,
2771545Smax.romanov@nginx.com     .get_port     = nxt_router_get_port_handler,
278662Smax.romanov@nginx.com     .change_file  = nxt_port_change_log_file_handler,
279662Smax.romanov@nginx.com     .mmap         = nxt_port_mmap_handler,
2801546Smax.romanov@nginx.com     .get_mmap     = nxt_router_get_mmap_handler,
281662Smax.romanov@nginx.com     .data         = nxt_router_conf_data_handler,
282662Smax.romanov@nginx.com     .remove_pid   = nxt_router_remove_pid_handler,
283662Smax.romanov@nginx.com     .access_log   = nxt_router_access_log_reopen_handler,
284662Smax.romanov@nginx.com     .rpc_ready    = nxt_port_rpc_handler,
285662Smax.romanov@nginx.com     .rpc_error    = nxt_port_rpc_handler,
2861321Smax.romanov@nginx.com     .oosm         = nxt_router_oosm_handler,
287662Smax.romanov@nginx.com };
288662Smax.romanov@nginx.com 
289662Smax.romanov@nginx.com 
2901488St.nateldemoura@f5.com const nxt_process_init_t  nxt_router_process = {
2911488St.nateldemoura@f5.com     .name           = "router",
2921488St.nateldemoura@f5.com     .type           = NXT_PROCESS_ROUTER,
2931488St.nateldemoura@f5.com     .prefork        = nxt_router_prefork,
2941488St.nateldemoura@f5.com     .restart        = 1,
2951488St.nateldemoura@f5.com     .setup          = nxt_process_core_setup,
2961488St.nateldemoura@f5.com     .start          = nxt_router_start,
2971488St.nateldemoura@f5.com     .port_handlers  = &nxt_router_process_port_handlers,
2981488St.nateldemoura@f5.com     .signals        = nxt_process_signals,
2991488St.nateldemoura@f5.com };
3001488St.nateldemoura@f5.com 
3011488St.nateldemoura@f5.com 
3021509Sigor@sysoev.ru /* Queues of nxt_socket_conf_t */
3031509Sigor@sysoev.ru nxt_queue_t  creating_sockets;
3041509Sigor@sysoev.ru nxt_queue_t  pending_sockets;
3051509Sigor@sysoev.ru nxt_queue_t  updating_sockets;
3061509Sigor@sysoev.ru nxt_queue_t  keeping_sockets;
3071509Sigor@sysoev.ru nxt_queue_t  deleting_sockets;
3081509Sigor@sysoev.ru 
3091509Sigor@sysoev.ru 
3101488St.nateldemoura@f5.com static nxt_int_t
3111488St.nateldemoura@f5.com nxt_router_prefork(nxt_task_t *task, nxt_process_t *process, nxt_mp_t *mp)
3121488St.nateldemoura@f5.com {
3131488St.nateldemoura@f5.com     nxt_runtime_stop_app_processes(task, task->thread->runtime);
3141488St.nateldemoura@f5.com 
3151488St.nateldemoura@f5.com     return NXT_OK;
3161488St.nateldemoura@f5.com }
3171488St.nateldemoura@f5.com 
3181488St.nateldemoura@f5.com 
3191488St.nateldemoura@f5.com static nxt_int_t
3201488St.nateldemoura@f5.com nxt_router_start(nxt_task_t *task, nxt_process_data_t *data)
32120Sigor@sysoev.ru {
322141Smax.romanov@nginx.com     nxt_int_t      ret;
323662Smax.romanov@nginx.com     nxt_port_t     *controller_port;
324141Smax.romanov@nginx.com     nxt_router_t   *router;
325141Smax.romanov@nginx.com     nxt_runtime_t  *rt;
326141Smax.romanov@nginx.com 
327141Smax.romanov@nginx.com     rt = task->thread->runtime;
32853Sigor@sysoev.ru 
3291488St.nateldemoura@f5.com     nxt_log(task, NXT_LOG_INFO, "router started");
3301488St.nateldemoura@f5.com 
331771Sigor@sysoev.ru #if (NXT_TLS)
332771Sigor@sysoev.ru     rt->tls = nxt_service_get(rt->services, "SSL/TLS", "OpenSSL");
333771Sigor@sysoev.ru     if (nxt_slow_path(rt->tls == NULL)) {
334771Sigor@sysoev.ru         return NXT_ERROR;
335771Sigor@sysoev.ru     }
336771Sigor@sysoev.ru 
337771Sigor@sysoev.ru     ret = rt->tls->library_init(task);
338771Sigor@sysoev.ru     if (nxt_slow_path(ret != NXT_OK)) {
339771Sigor@sysoev.ru         return ret;
340771Sigor@sysoev.ru     }
341771Sigor@sysoev.ru #endif
342771Sigor@sysoev.ru 
3431459Smax.romanov@nginx.com     ret = nxt_http_init(task);
34488Smax.romanov@nginx.com     if (nxt_slow_path(ret != NXT_OK)) {
34588Smax.romanov@nginx.com         return ret;
34688Smax.romanov@nginx.com     }
34788Smax.romanov@nginx.com 
34853Sigor@sysoev.ru     router = nxt_zalloc(sizeof(nxt_router_t));
34953Sigor@sysoev.ru     if (nxt_slow_path(router == NULL)) {
35053Sigor@sysoev.ru         return NXT_ERROR;
35153Sigor@sysoev.ru     }
35253Sigor@sysoev.ru 
35353Sigor@sysoev.ru     nxt_queue_init(&router->engines);
35453Sigor@sysoev.ru     nxt_queue_init(&router->sockets);
355133Sigor@sysoev.ru     nxt_queue_init(&router->apps);
35653Sigor@sysoev.ru 
357119Smax.romanov@nginx.com     nxt_router = router;
358119Smax.romanov@nginx.com 
359662Smax.romanov@nginx.com     controller_port = rt->port_by_type[NXT_PROCESS_CONTROLLER];
360662Smax.romanov@nginx.com     if (controller_port != NULL) {
361662Smax.romanov@nginx.com         nxt_router_greet_controller(task, controller_port);
362662Smax.romanov@nginx.com     }
363662Smax.romanov@nginx.com 
364115Sigor@sysoev.ru     return NXT_OK;
365115Sigor@sysoev.ru }
366115Sigor@sysoev.ru 
367115Sigor@sysoev.ru 
368343Smax.romanov@nginx.com static void
369662Smax.romanov@nginx.com nxt_router_greet_controller(nxt_task_t *task, nxt_port_t *controller_port)
370662Smax.romanov@nginx.com {
371662Smax.romanov@nginx.com     nxt_port_socket_write(task, controller_port, NXT_PORT_MSG_PROCESS_READY,
372662Smax.romanov@nginx.com                           -1, 0, 0, NULL);
373662Smax.romanov@nginx.com }
374662Smax.romanov@nginx.com 
375662Smax.romanov@nginx.com 
376662Smax.romanov@nginx.com static void
377507Smax.romanov@nginx.com nxt_router_start_app_process_handler(nxt_task_t *task, nxt_port_t *port,
378507Smax.romanov@nginx.com     void *data)
379167Smax.romanov@nginx.com {
380343Smax.romanov@nginx.com     size_t         size;
381343Smax.romanov@nginx.com     uint32_t       stream;
382430Sigor@sysoev.ru     nxt_mp_t       *mp;
383648Svbart@nginx.com     nxt_int_t      ret;
384343Smax.romanov@nginx.com     nxt_app_t      *app;
385343Smax.romanov@nginx.com     nxt_buf_t      *b;
386343Smax.romanov@nginx.com     nxt_port_t     *main_port;
387343Smax.romanov@nginx.com     nxt_runtime_t  *rt;
388343Smax.romanov@nginx.com 
389343Smax.romanov@nginx.com     app = data;
390167Smax.romanov@nginx.com 
391167Smax.romanov@nginx.com     rt = task->thread->runtime;
392240Sigor@sysoev.ru     main_port = rt->port_by_type[NXT_PROCESS_MAIN];
393167Smax.romanov@nginx.com 
394507Smax.romanov@nginx.com     nxt_debug(task, "app '%V' %p start process", &app->name, app);
395343Smax.romanov@nginx.com 
396343Smax.romanov@nginx.com     size = app->name.length + 1 + app->conf.length;
397343Smax.romanov@nginx.com 
398343Smax.romanov@nginx.com     b = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool, size);
399343Smax.romanov@nginx.com 
400343Smax.romanov@nginx.com     if (nxt_slow_path(b == NULL)) {
401343Smax.romanov@nginx.com         goto failed;
402167Smax.romanov@nginx.com     }
403167Smax.romanov@nginx.com 
404343Smax.romanov@nginx.com     nxt_buf_cpystr(b, &app->name);
405343Smax.romanov@nginx.com     *b->mem.free++ = '\0';
406343Smax.romanov@nginx.com     nxt_buf_cpystr(b, &app->conf);
407343Smax.romanov@nginx.com 
408753Smax.romanov@nginx.com     nxt_router_app_joint_use(task, app->joint, 1);
409753Smax.romanov@nginx.com 
410343Smax.romanov@nginx.com     stream = nxt_port_rpc_register_handler(task, port,
411343Smax.romanov@nginx.com                                            nxt_router_app_port_ready,
412343Smax.romanov@nginx.com                                            nxt_router_app_port_error,
413753Smax.romanov@nginx.com                                            -1, app->joint);
414343Smax.romanov@nginx.com 
415343Smax.romanov@nginx.com     if (nxt_slow_path(stream == 0)) {
416753Smax.romanov@nginx.com         nxt_router_app_joint_use(task, app->joint, -1);
417753Smax.romanov@nginx.com 
418343Smax.romanov@nginx.com         goto failed;
419343Smax.romanov@nginx.com     }
420343Smax.romanov@nginx.com 
4211488St.nateldemoura@f5.com     ret = nxt_port_socket_write(task, main_port, NXT_PORT_MSG_START_PROCESS,
4221488St.nateldemoura@f5.com                                 -1, stream, port->id, b);
423648Svbart@nginx.com 
424648Svbart@nginx.com     if (nxt_slow_path(ret != NXT_OK)) {
425648Svbart@nginx.com         nxt_port_rpc_cancel(task, port, stream);
426753Smax.romanov@nginx.com 
427753Smax.romanov@nginx.com         nxt_router_app_joint_use(task, app->joint, -1);
428753Smax.romanov@nginx.com 
429648Svbart@nginx.com         goto failed;
430648Svbart@nginx.com     }
431343Smax.romanov@nginx.com 
432753Smax.romanov@nginx.com     nxt_router_app_use(task, app, -1);
433753Smax.romanov@nginx.com 
434343Smax.romanov@nginx.com     return;
435343Smax.romanov@nginx.com 
436343Smax.romanov@nginx.com failed:
437343Smax.romanov@nginx.com 
438648Svbart@nginx.com     if (b != NULL) {
439648Svbart@nginx.com         mp = b->data;
440648Svbart@nginx.com         nxt_mp_free(mp, b);
441648Svbart@nginx.com         nxt_mp_release(mp);
442648Svbart@nginx.com     }
443648Svbart@nginx.com 
444343Smax.romanov@nginx.com     nxt_thread_mutex_lock(&app->mutex);
445343Smax.romanov@nginx.com 
446507Smax.romanov@nginx.com     app->pending_processes--;
447343Smax.romanov@nginx.com 
448343Smax.romanov@nginx.com     nxt_thread_mutex_unlock(&app->mutex);
449343Smax.romanov@nginx.com 
450343Smax.romanov@nginx.com     nxt_router_app_use(task, app, -1);
451167Smax.romanov@nginx.com }
452167Smax.romanov@nginx.com 
453167Smax.romanov@nginx.com 
454753Smax.romanov@nginx.com static void
455753Smax.romanov@nginx.com nxt_router_app_joint_use(nxt_task_t *task, nxt_app_joint_t *app_joint, int i)
456753Smax.romanov@nginx.com {
457753Smax.romanov@nginx.com     app_joint->use_count += i;
458753Smax.romanov@nginx.com 
459753Smax.romanov@nginx.com     if (app_joint->use_count == 0) {
460753Smax.romanov@nginx.com         nxt_assert(app_joint->app == NULL);
461753Smax.romanov@nginx.com 
462753Smax.romanov@nginx.com         nxt_free(app_joint);
463753Smax.romanov@nginx.com     }
464753Smax.romanov@nginx.com }
465753Smax.romanov@nginx.com 
466753Smax.romanov@nginx.com 
467343Smax.romanov@nginx.com static nxt_int_t
468507Smax.romanov@nginx.com nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app)
469141Smax.romanov@nginx.com {
470343Smax.romanov@nginx.com     nxt_int_t      res;
471343Smax.romanov@nginx.com     nxt_port_t     *router_port;
472343Smax.romanov@nginx.com     nxt_runtime_t  *rt;
473343Smax.romanov@nginx.com 
4741549Smax.romanov@nginx.com     nxt_debug(task, "app '%V' start process", &app->name);
4751549Smax.romanov@nginx.com 
476343Smax.romanov@nginx.com     rt = task->thread->runtime;
477343Smax.romanov@nginx.com     router_port = rt->port_by_type[NXT_PROCESS_ROUTER];
478343Smax.romanov@nginx.com 
479343Smax.romanov@nginx.com     nxt_router_app_use(task, app, 1);
480343Smax.romanov@nginx.com 
481507Smax.romanov@nginx.com     res = nxt_port_post(task, router_port, nxt_router_start_app_process_handler,
482343Smax.romanov@nginx.com                         app);
483343Smax.romanov@nginx.com 
484343Smax.romanov@nginx.com     if (res == NXT_OK) {
485343Smax.romanov@nginx.com         return res;
486318Smax.romanov@nginx.com     }
487318Smax.romanov@nginx.com 
488343Smax.romanov@nginx.com     nxt_thread_mutex_lock(&app->mutex);
489343Smax.romanov@nginx.com 
490507Smax.romanov@nginx.com     app->pending_processes--;
491343Smax.romanov@nginx.com 
492343Smax.romanov@nginx.com     nxt_thread_mutex_unlock(&app->mutex);
493343Smax.romanov@nginx.com 
494343Smax.romanov@nginx.com     nxt_router_app_use(task, app, -1);
495343Smax.romanov@nginx.com 
496343Smax.romanov@nginx.com     return NXT_ERROR;
497318Smax.romanov@nginx.com }
498318Smax.romanov@nginx.com 
499318Smax.romanov@nginx.com 
500423Smax.romanov@nginx.com nxt_inline nxt_bool_t
5011555Smax.romanov@nginx.com nxt_router_msg_cancel(nxt_task_t *task, nxt_request_rpc_data_t *req_rpc_data)
502423Smax.romanov@nginx.com {
5031555Smax.romanov@nginx.com     nxt_buf_t       *b, *next;
5041555Smax.romanov@nginx.com     nxt_bool_t      cancelled;
5051555Smax.romanov@nginx.com     nxt_msg_info_t  *msg_info;
5061555Smax.romanov@nginx.com 
5071555Smax.romanov@nginx.com     msg_info = &req_rpc_data->msg_info;
508423Smax.romanov@nginx.com 
509423Smax.romanov@nginx.com     if (msg_info->buf == NULL) {
510423Smax.romanov@nginx.com         return 0;
511423Smax.romanov@nginx.com     }
512423Smax.romanov@nginx.com 
5131555Smax.romanov@nginx.com     cancelled = nxt_app_queue_cancel(req_rpc_data->app->shared_port->queue,
5141555Smax.romanov@nginx.com                                      msg_info->tracking_cookie,
5151555Smax.romanov@nginx.com                                      req_rpc_data->stream);
516423Smax.romanov@nginx.com 
517423Smax.romanov@nginx.com     if (cancelled) {
5181555Smax.romanov@nginx.com         nxt_debug(task, "stream #%uD: cancelled by router",
5191555Smax.romanov@nginx.com                   req_rpc_data->stream);
520423Smax.romanov@nginx.com     }
521423Smax.romanov@nginx.com 
522423Smax.romanov@nginx.com     for (b = msg_info->buf; b != NULL; b = next) {
523423Smax.romanov@nginx.com         next = b->next;
5241269Sigor@sysoev.ru         b->next = NULL;
525423Smax.romanov@nginx.com 
526423Smax.romanov@nginx.com         b->completion_handler = msg_info->completion_handler;
527423Smax.romanov@nginx.com 
528423Smax.romanov@nginx.com         if (b->is_port_mmap_sent) {
529423Smax.romanov@nginx.com             b->is_port_mmap_sent = cancelled == 0;
530423Smax.romanov@nginx.com             b->completion_handler(task, b, b->parent);
531423Smax.romanov@nginx.com         }
532423Smax.romanov@nginx.com     }
533423Smax.romanov@nginx.com 
534423Smax.romanov@nginx.com     msg_info->buf = NULL;
535423Smax.romanov@nginx.com 
536423Smax.romanov@nginx.com     return cancelled;
537423Smax.romanov@nginx.com }
538423Smax.romanov@nginx.com 
539423Smax.romanov@nginx.com 
540425Smax.romanov@nginx.com nxt_inline nxt_bool_t
541425Smax.romanov@nginx.com nxt_queue_chk_remove(nxt_queue_link_t *lnk)
542425Smax.romanov@nginx.com {
543425Smax.romanov@nginx.com     if (lnk->next != NULL) {
544425Smax.romanov@nginx.com         nxt_queue_remove(lnk);
545425Smax.romanov@nginx.com 
546425Smax.romanov@nginx.com         lnk->next = NULL;
547425Smax.romanov@nginx.com 
548425Smax.romanov@nginx.com         return 1;
549425Smax.romanov@nginx.com     }
550425Smax.romanov@nginx.com 
551425Smax.romanov@nginx.com     return 0;
552425Smax.romanov@nginx.com }
553425Smax.romanov@nginx.com 
554425Smax.romanov@nginx.com 
555343Smax.romanov@nginx.com nxt_inline void
5561123Smax.romanov@nginx.com nxt_request_rpc_data_unlink(nxt_task_t *task,
5571123Smax.romanov@nginx.com     nxt_request_rpc_data_t *req_rpc_data)
558343Smax.romanov@nginx.com {
5591561Smax.romanov@nginx.com     nxt_app_t           *app;
5601561Smax.romanov@nginx.com     nxt_bool_t          unlinked;
5611547Smax.romanov@nginx.com     nxt_http_request_t  *r;
5621547Smax.romanov@nginx.com 
5631555Smax.romanov@nginx.com     nxt_router_msg_cancel(task, req_rpc_data);
5641123Smax.romanov@nginx.com 
5651123Smax.romanov@nginx.com     if (req_rpc_data->app_port != NULL) {
5661123Smax.romanov@nginx.com         nxt_router_app_port_release(task, req_rpc_data->app_port,
5671123Smax.romanov@nginx.com                                     req_rpc_data->apr_action);
5681123Smax.romanov@nginx.com 
5691123Smax.romanov@nginx.com         req_rpc_data->app_port = NULL;
5701123Smax.romanov@nginx.com     }
5711123Smax.romanov@nginx.com 
5721561Smax.romanov@nginx.com     app = req_rpc_data->app;
5731547Smax.romanov@nginx.com     r = req_rpc_data->request;
5741547Smax.romanov@nginx.com 
5751547Smax.romanov@nginx.com     if (r != NULL) {
5761547Smax.romanov@nginx.com         r->timer_data = NULL;
5771547Smax.romanov@nginx.com 
5781547Smax.romanov@nginx.com         nxt_router_http_request_release_post(task, r);
5791547Smax.romanov@nginx.com 
5801547Smax.romanov@nginx.com         r->req_rpc_data = NULL;
5811123Smax.romanov@nginx.com         req_rpc_data->request = NULL;
5821561Smax.romanov@nginx.com 
5831561Smax.romanov@nginx.com         if (app != NULL) {
5841561Smax.romanov@nginx.com             unlinked = 0;
5851561Smax.romanov@nginx.com 
5861561Smax.romanov@nginx.com             nxt_thread_mutex_lock(&app->mutex);
5871561Smax.romanov@nginx.com 
5881561Smax.romanov@nginx.com             if (r->app_link.next != NULL) {
5891561Smax.romanov@nginx.com                 nxt_queue_remove(&r->app_link);
5901561Smax.romanov@nginx.com                 r->app_link.next = NULL;
5911561Smax.romanov@nginx.com 
5921561Smax.romanov@nginx.com                 unlinked = 1;
5931561Smax.romanov@nginx.com             }
5941561Smax.romanov@nginx.com 
5951561Smax.romanov@nginx.com             nxt_thread_mutex_unlock(&app->mutex);
5961561Smax.romanov@nginx.com 
5971561Smax.romanov@nginx.com             if (unlinked) {
5981561Smax.romanov@nginx.com                 nxt_mp_release(r->mem_pool);
5991561Smax.romanov@nginx.com             }
6001561Smax.romanov@nginx.com         }
6011561Smax.romanov@nginx.com     }
6021561Smax.romanov@nginx.com 
6031561Smax.romanov@nginx.com     if (app != NULL) {
6041561Smax.romanov@nginx.com         nxt_router_app_use(task, app, -1);
6051561Smax.romanov@nginx.com 
6061561Smax.romanov@nginx.com         req_rpc_data->app = NULL;
607346Smax.romanov@nginx.com     }
6081547Smax.romanov@nginx.com 
6091547Smax.romanov@nginx.com     if (req_rpc_data->msg_info.body_fd != -1) {
6101547Smax.romanov@nginx.com         nxt_fd_close(req_rpc_data->msg_info.body_fd);
6111547Smax.romanov@nginx.com 
6121547Smax.romanov@nginx.com         req_rpc_data->msg_info.body_fd = -1;
6131547Smax.romanov@nginx.com     }
6141547Smax.romanov@nginx.com 
6151547Smax.romanov@nginx.com     if (req_rpc_data->rpc_cancel) {
6161547Smax.romanov@nginx.com         req_rpc_data->rpc_cancel = 0;
6171547Smax.romanov@nginx.com 
6181547Smax.romanov@nginx.com         nxt_port_rpc_cancel(task, task->thread->engine->port,
6191547Smax.romanov@nginx.com                             req_rpc_data->stream);
6201547Smax.romanov@nginx.com     }
621343Smax.romanov@nginx.com }
622343Smax.romanov@nginx.com 
623343Smax.romanov@nginx.com 
6241552Smax.romanov@nginx.com static void
625141Smax.romanov@nginx.com nxt_router_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
626141Smax.romanov@nginx.com {
6271555Smax.romanov@nginx.com     nxt_int_t      res;
6281547Smax.romanov@nginx.com     nxt_app_t      *app;
6291547Smax.romanov@nginx.com     nxt_port_t     *port, *main_app_port;
6301547Smax.romanov@nginx.com     nxt_runtime_t  *rt;
6311547Smax.romanov@nginx.com 
632141Smax.romanov@nginx.com     nxt_port_new_port_handler(task, msg);
633141Smax.romanov@nginx.com 
6341547Smax.romanov@nginx.com     port = msg->u.new_port;
6351547Smax.romanov@nginx.com 
6361547Smax.romanov@nginx.com     if (port != NULL && port->type == NXT_PROCESS_CONTROLLER) {
637662Smax.romanov@nginx.com         nxt_router_greet_controller(task, msg->u.new_port);
638662Smax.romanov@nginx.com     }
639662Smax.romanov@nginx.com 
6401547Smax.romanov@nginx.com     if (port == NULL || port->type != NXT_PROCESS_APP) {
6411547Smax.romanov@nginx.com 
6421547Smax.romanov@nginx.com         if (msg->port_msg.stream == 0) {
6431547Smax.romanov@nginx.com             return;
6441547Smax.romanov@nginx.com         }
6451547Smax.romanov@nginx.com 
6461547Smax.romanov@nginx.com         msg->port_msg.type = _NXT_PORT_MSG_RPC_ERROR;
6471555Smax.romanov@nginx.com 
6481555Smax.romanov@nginx.com     } else {
6491558Smax.romanov@nginx.com         if (msg->fd[1] != -1) {
6501558Smax.romanov@nginx.com             res = nxt_router_port_queue_map(task, port, msg->fd[1]);
6511555Smax.romanov@nginx.com             if (nxt_slow_path(res != NXT_OK)) {
6521555Smax.romanov@nginx.com                 return;
6531555Smax.romanov@nginx.com             }
6541555Smax.romanov@nginx.com 
6551558Smax.romanov@nginx.com             nxt_fd_close(msg->fd[1]);
6561558Smax.romanov@nginx.com             msg->fd[1] = -1;
6571555Smax.romanov@nginx.com         }
6581547Smax.romanov@nginx.com     }
6591547Smax.romanov@nginx.com 
6601547Smax.romanov@nginx.com     if (msg->port_msg.stream != 0) {
6611547Smax.romanov@nginx.com         nxt_port_rpc_handler(task, msg);
662141Smax.romanov@nginx.com         return;
663141Smax.romanov@nginx.com     }
664141Smax.romanov@nginx.com 
6651547Smax.romanov@nginx.com     /*
6661547Smax.romanov@nginx.com      * Port with "id == 0" is application 'main' port and it always
6671547Smax.romanov@nginx.com      * should come with non-zero stream.
6681547Smax.romanov@nginx.com      */
6691547Smax.romanov@nginx.com     nxt_assert(port->id != 0);
6701547Smax.romanov@nginx.com 
6711547Smax.romanov@nginx.com     /* Find 'main' app port and get app reference. */
6721547Smax.romanov@nginx.com     rt = task->thread->runtime;
6731547Smax.romanov@nginx.com 
6741547Smax.romanov@nginx.com     /*
6751547Smax.romanov@nginx.com      * It is safe to access 'runtime->ports' hash because 'NEW_PORT'
6761547Smax.romanov@nginx.com      * sent to main port (with id == 0) and processed in main thread.
6771547Smax.romanov@nginx.com      */
6781547Smax.romanov@nginx.com     main_app_port = nxt_port_hash_find(&rt->ports, port->pid, 0);
6791547Smax.romanov@nginx.com     nxt_assert(main_app_port != NULL);
6801547Smax.romanov@nginx.com 
6811547Smax.romanov@nginx.com     app = main_app_port->app;
6821547Smax.romanov@nginx.com     nxt_assert(app != NULL);
6831547Smax.romanov@nginx.com 
6841547Smax.romanov@nginx.com     nxt_thread_mutex_lock(&app->mutex);
6851547Smax.romanov@nginx.com 
6861547Smax.romanov@nginx.com     /* TODO here should be find-and-add code because there can be
6871547Smax.romanov@nginx.com        port waiters in port_hash */
6881547Smax.romanov@nginx.com     nxt_port_hash_add(&app->port_hash, port);
6891547Smax.romanov@nginx.com     app->port_hash_count++;
6901547Smax.romanov@nginx.com 
6911547Smax.romanov@nginx.com     nxt_thread_mutex_unlock(&app->mutex);
6921547Smax.romanov@nginx.com 
6931547Smax.romanov@nginx.com     port->app = app;
6941547Smax.romanov@nginx.com     port->main_app_port = main_app_port;
6951666Smax.romanov@nginx.com 
6961666Smax.romanov@nginx.com     nxt_port_socket_write(task, port, NXT_PORT_MSG_PORT_ACK, -1, 0, 0, NULL);
697141Smax.romanov@nginx.com }
698141Smax.romanov@nginx.com 
699141Smax.romanov@nginx.com 
7001552Smax.romanov@nginx.com static void
701139Sigor@sysoev.ru nxt_router_conf_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
702115Sigor@sysoev.ru {
7031526Smax.romanov@nginx.com     void                    *p;
7041526Smax.romanov@nginx.com     size_t                  size;
705198Sigor@sysoev.ru     nxt_int_t               ret;
7061779Smax.romanov@nginx.com     nxt_port_t              *port;
707139Sigor@sysoev.ru     nxt_router_temp_conf_t  *tmcf;
708139Sigor@sysoev.ru 
7091779Smax.romanov@nginx.com     port = nxt_runtime_port_find(task->thread->runtime,
7101779Smax.romanov@nginx.com                                  msg->port_msg.pid,
7111779Smax.romanov@nginx.com                                  msg->port_msg.reply_port);
7121779Smax.romanov@nginx.com     if (nxt_slow_path(port == NULL)) {
7131779Smax.romanov@nginx.com         nxt_alert(task, "conf_data_handler: reply port not found");
7141779Smax.romanov@nginx.com         return;
7151779Smax.romanov@nginx.com     }
7161779Smax.romanov@nginx.com 
7171779Smax.romanov@nginx.com     p = MAP_FAILED;
7181779Smax.romanov@nginx.com 
7191779Smax.romanov@nginx.com     /*
7201779Smax.romanov@nginx.com      * Ancient compilers like gcc 4.8.5 on CentOS 7 wants 'size' to be
7211779Smax.romanov@nginx.com      * initialized in 'cleanup' section.
7221779Smax.romanov@nginx.com      */
723