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> 10431Sigor@sysoev.ru #include <nxt_http.h> 1120Sigor@sysoev.ru 1220Sigor@sysoev.ru 13115Sigor@sysoev.ru typedef struct { 14318Smax.romanov@nginx.com nxt_str_t type; 15507Smax.romanov@nginx.com uint32_t processes; 16507Smax.romanov@nginx.com uint32_t max_processes; 17507Smax.romanov@nginx.com uint32_t spare_processes; 18318Smax.romanov@nginx.com nxt_msec_t timeout; 19427Smax.romanov@nginx.com nxt_msec_t res_timeout; 20507Smax.romanov@nginx.com nxt_msec_t idle_timeout; 21318Smax.romanov@nginx.com uint32_t requests; 22318Smax.romanov@nginx.com nxt_conf_value_t *limits_value; 23507Smax.romanov@nginx.com nxt_conf_value_t *processes_value; 24133Sigor@sysoev.ru } nxt_router_app_conf_t; 25133Sigor@sysoev.ru 26133Sigor@sysoev.ru 27133Sigor@sysoev.ru typedef struct { 28133Sigor@sysoev.ru nxt_str_t application; 29115Sigor@sysoev.ru } nxt_router_listener_conf_t; 30115Sigor@sysoev.ru 31115Sigor@sysoev.ru 32423Smax.romanov@nginx.com typedef struct nxt_msg_info_s { 33423Smax.romanov@nginx.com nxt_buf_t *buf; 34423Smax.romanov@nginx.com nxt_port_mmap_tracking_t tracking; 35423Smax.romanov@nginx.com nxt_work_handler_t completion_handler; 36423Smax.romanov@nginx.com } nxt_msg_info_t; 37423Smax.romanov@nginx.com 38423Smax.romanov@nginx.com 39167Smax.romanov@nginx.com typedef struct nxt_req_app_link_s nxt_req_app_link_t; 40141Smax.romanov@nginx.com 41141Smax.romanov@nginx.com 42318Smax.romanov@nginx.com typedef struct { 43431Sigor@sysoev.ru uint32_t stream; 44431Sigor@sysoev.ru nxt_app_t *app; 45431Sigor@sysoev.ru nxt_port_t *app_port; 46431Sigor@sysoev.ru nxt_app_parse_ctx_t *ap; 47431Sigor@sysoev.ru nxt_msg_info_t msg_info; 48431Sigor@sysoev.ru nxt_req_app_link_t *ra; 49431Sigor@sysoev.ru 50431Sigor@sysoev.ru nxt_queue_link_t link; /* for nxt_conn_t.requests */ 51318Smax.romanov@nginx.com } nxt_req_conn_link_t; 52318Smax.romanov@nginx.com 53318Smax.romanov@nginx.com 54167Smax.romanov@nginx.com struct nxt_req_app_link_s { 55318Smax.romanov@nginx.com uint32_t stream; 56425Smax.romanov@nginx.com nxt_atomic_t use_count; 57167Smax.romanov@nginx.com nxt_port_t *app_port; 58167Smax.romanov@nginx.com nxt_port_t *reply_port; 59167Smax.romanov@nginx.com nxt_app_parse_ctx_t *ap; 60423Smax.romanov@nginx.com nxt_msg_info_t msg_info; 61167Smax.romanov@nginx.com nxt_req_conn_link_t *rc; 62167Smax.romanov@nginx.com 63427Smax.romanov@nginx.com nxt_nsec_t res_time; 64427Smax.romanov@nginx.com 65425Smax.romanov@nginx.com nxt_queue_link_t link_app_requests; /* for nxt_app_t.requests */ 66425Smax.romanov@nginx.com nxt_queue_link_t link_port_pending; /* for nxt_port_t.pending_requests */ 67427Smax.romanov@nginx.com nxt_queue_link_t link_app_pending; /* for nxt_app_t.pending */ 68167Smax.romanov@nginx.com 69167Smax.romanov@nginx.com nxt_mp_t *mem_pool; 70167Smax.romanov@nginx.com nxt_work_t work; 71345Smax.romanov@nginx.com 72345Smax.romanov@nginx.com int err_code; 73345Smax.romanov@nginx.com const char *err_str; 74167Smax.romanov@nginx.com }; 75167Smax.romanov@nginx.com 76167Smax.romanov@nginx.com 77198Sigor@sysoev.ru typedef struct { 78198Sigor@sysoev.ru nxt_socket_conf_t *socket_conf; 79198Sigor@sysoev.ru nxt_router_temp_conf_t *temp_conf; 80198Sigor@sysoev.ru } nxt_socket_rpc_t; 81198Sigor@sysoev.ru 82198Sigor@sysoev.ru 83507Smax.romanov@nginx.com typedef struct { 84507Smax.romanov@nginx.com nxt_app_t *app; 85507Smax.romanov@nginx.com nxt_router_temp_conf_t *temp_conf; 86507Smax.romanov@nginx.com } nxt_app_rpc_t; 87507Smax.romanov@nginx.com 88507Smax.romanov@nginx.com 89427Smax.romanov@nginx.com struct nxt_port_select_state_s { 90427Smax.romanov@nginx.com nxt_app_t *app; 91427Smax.romanov@nginx.com nxt_req_app_link_t *ra; 92427Smax.romanov@nginx.com 93427Smax.romanov@nginx.com nxt_port_t *failed_port; 94427Smax.romanov@nginx.com int failed_port_use_delta; 95427Smax.romanov@nginx.com 96507Smax.romanov@nginx.com uint8_t start_process; /* 1 bit */ 97427Smax.romanov@nginx.com nxt_req_app_link_t *shared_ra; 98427Smax.romanov@nginx.com nxt_port_t *port; 99427Smax.romanov@nginx.com }; 100427Smax.romanov@nginx.com 101427Smax.romanov@nginx.com typedef struct nxt_port_select_state_s nxt_port_select_state_t; 102427Smax.romanov@nginx.com 103427Smax.romanov@nginx.com static void nxt_router_port_select(nxt_task_t *task, 104427Smax.romanov@nginx.com nxt_port_select_state_t *state); 105427Smax.romanov@nginx.com 106427Smax.romanov@nginx.com static nxt_int_t nxt_router_port_post_select(nxt_task_t *task, 107427Smax.romanov@nginx.com nxt_port_select_state_t *state); 108427Smax.romanov@nginx.com 109507Smax.romanov@nginx.com static nxt_int_t nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app); 110343Smax.romanov@nginx.com 111425Smax.romanov@nginx.com nxt_inline void 112425Smax.romanov@nginx.com nxt_router_ra_inc_use(nxt_req_app_link_t *ra) 113425Smax.romanov@nginx.com { 114425Smax.romanov@nginx.com nxt_atomic_fetch_add(&ra->use_count, 1); 115425Smax.romanov@nginx.com } 116425Smax.romanov@nginx.com 117425Smax.romanov@nginx.com nxt_inline void 118425Smax.romanov@nginx.com nxt_router_ra_dec_use(nxt_req_app_link_t *ra) 119425Smax.romanov@nginx.com { 120*538Svbart@nginx.com #if (NXT_DEBUG) 121425Smax.romanov@nginx.com int c; 122425Smax.romanov@nginx.com 123425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, -1); 124425Smax.romanov@nginx.com 125425Smax.romanov@nginx.com nxt_assert(c > 1); 126*538Svbart@nginx.com #else 127*538Svbart@nginx.com (void) nxt_atomic_fetch_add(&ra->use_count, -1); 128*538Svbart@nginx.com #endif 129425Smax.romanov@nginx.com } 130425Smax.romanov@nginx.com 131425Smax.romanov@nginx.com static void nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i); 132425Smax.romanov@nginx.com 133139Sigor@sysoev.ru static nxt_router_temp_conf_t *nxt_router_temp_conf(nxt_task_t *task); 134198Sigor@sysoev.ru static void nxt_router_conf_apply(nxt_task_t *task, void *obj, void *data); 135198Sigor@sysoev.ru static void nxt_router_conf_ready(nxt_task_t *task, 136139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 137139Sigor@sysoev.ru static void nxt_router_conf_error(nxt_task_t *task, 138139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 139139Sigor@sysoev.ru static void nxt_router_conf_send(nxt_task_t *task, 140193Smax.romanov@nginx.com nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type); 14153Sigor@sysoev.ru 142115Sigor@sysoev.ru static nxt_int_t nxt_router_conf_create(nxt_task_t *task, 143115Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, u_char *start, u_char *end); 144133Sigor@sysoev.ru static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name); 145133Sigor@sysoev.ru static nxt_app_t *nxt_router_listener_application(nxt_router_temp_conf_t *tmcf, 146133Sigor@sysoev.ru nxt_str_t *name); 147198Sigor@sysoev.ru static void nxt_router_listen_socket_rpc_create(nxt_task_t *task, 148198Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, nxt_socket_conf_t *skcf); 149198Sigor@sysoev.ru static void nxt_router_listen_socket_ready(nxt_task_t *task, 150198Sigor@sysoev.ru nxt_port_recv_msg_t *msg, void *data); 151198Sigor@sysoev.ru static void nxt_router_listen_socket_error(nxt_task_t *task, 152198Sigor@sysoev.ru nxt_port_recv_msg_t *msg, void *data); 153507Smax.romanov@nginx.com static void nxt_router_app_rpc_create(nxt_task_t *task, 154507Smax.romanov@nginx.com nxt_router_temp_conf_t *tmcf, nxt_app_t *app); 155507Smax.romanov@nginx.com static void nxt_router_app_prefork_ready(nxt_task_t *task, 156507Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 157507Smax.romanov@nginx.com static void nxt_router_app_prefork_error(nxt_task_t *task, 158507Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 159359Sigor@sysoev.ru static nxt_socket_conf_t *nxt_router_socket_conf(nxt_task_t *task, 160359Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, nxt_str_t *name); 161359Sigor@sysoev.ru static nxt_int_t nxt_router_listen_socket_find(nxt_router_temp_conf_t *tmcf, 162359Sigor@sysoev.ru nxt_socket_conf_t *nskcf, nxt_sockaddr_t *sa); 16353Sigor@sysoev.ru 16453Sigor@sysoev.ru static nxt_int_t nxt_router_engines_create(nxt_task_t *task, 16553Sigor@sysoev.ru nxt_router_t *router, nxt_router_temp_conf_t *tmcf, 16653Sigor@sysoev.ru const nxt_event_interface_t *interface); 167115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_create(nxt_router_temp_conf_t *tmcf, 168115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 169115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_update(nxt_router_temp_conf_t *tmcf, 170115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 171115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_delete(nxt_router_temp_conf_t *tmcf, 172115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 173154Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_create(nxt_router_temp_conf_t *tmcf, 174154Sigor@sysoev.ru nxt_router_engine_conf_t *recf, nxt_queue_t *sockets, 175154Sigor@sysoev.ru nxt_work_handler_t handler); 176313Sigor@sysoev.ru static nxt_int_t nxt_router_engine_quit(nxt_router_temp_conf_t *tmcf, 177313Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 178139Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_delete(nxt_router_temp_conf_t *tmcf, 179139Sigor@sysoev.ru nxt_router_engine_conf_t *recf, nxt_queue_t *sockets); 18053Sigor@sysoev.ru 18153Sigor@sysoev.ru static nxt_int_t nxt_router_threads_create(nxt_task_t *task, nxt_runtime_t *rt, 18253Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 18353Sigor@sysoev.ru static nxt_int_t nxt_router_thread_create(nxt_task_t *task, nxt_runtime_t *rt, 18453Sigor@sysoev.ru nxt_event_engine_t *engine); 185343Smax.romanov@nginx.com static void nxt_router_apps_sort(nxt_task_t *task, nxt_router_t *router, 186133Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 18753Sigor@sysoev.ru 188315Sigor@sysoev.ru static void nxt_router_engines_post(nxt_router_t *router, 189315Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 190315Sigor@sysoev.ru static void nxt_router_engine_post(nxt_event_engine_t *engine, 191315Sigor@sysoev.ru nxt_work_t *jobs); 19253Sigor@sysoev.ru 19353Sigor@sysoev.ru static void nxt_router_thread_start(void *data); 19453Sigor@sysoev.ru static void nxt_router_listen_socket_create(nxt_task_t *task, void *obj, 19553Sigor@sysoev.ru void *data); 19653Sigor@sysoev.ru static void nxt_router_listen_socket_update(nxt_task_t *task, void *obj, 19753Sigor@sysoev.ru void *data); 19853Sigor@sysoev.ru static void nxt_router_listen_socket_delete(nxt_task_t *task, void *obj, 19953Sigor@sysoev.ru void *data); 200313Sigor@sysoev.ru static void nxt_router_worker_thread_quit(nxt_task_t *task, void *obj, 201313Sigor@sysoev.ru void *data); 20253Sigor@sysoev.ru static void nxt_router_listen_socket_close(nxt_task_t *task, void *obj, 20353Sigor@sysoev.ru void *data); 20453Sigor@sysoev.ru static void nxt_router_thread_exit_handler(nxt_task_t *task, void *obj, 20553Sigor@sysoev.ru void *data); 206359Sigor@sysoev.ru static void nxt_router_listen_socket_release(nxt_task_t *task, 207359Sigor@sysoev.ru nxt_socket_conf_t *skcf); 20853Sigor@sysoev.ru static void nxt_router_conf_release(nxt_task_t *task, 20953Sigor@sysoev.ru nxt_socket_conf_joint_t *joint); 21053Sigor@sysoev.ru 211343Smax.romanov@nginx.com static void nxt_router_app_port_ready(nxt_task_t *task, 212343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 213343Smax.romanov@nginx.com static void nxt_router_app_port_error(nxt_task_t *task, 214343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 215343Smax.romanov@nginx.com 216507Smax.romanov@nginx.com static void nxt_router_app_quit(nxt_task_t *task, nxt_app_t *app); 217343Smax.romanov@nginx.com static void nxt_router_app_port_release(nxt_task_t *task, nxt_port_t *port, 218343Smax.romanov@nginx.com uint32_t request_failed, uint32_t got_response); 219427Smax.romanov@nginx.com static nxt_int_t nxt_router_app_port(nxt_task_t *task, nxt_app_t *app, 220427Smax.romanov@nginx.com nxt_req_app_link_t *ra); 221141Smax.romanov@nginx.com 222425Smax.romanov@nginx.com static void nxt_router_app_prepare_request(nxt_task_t *task, 223343Smax.romanov@nginx.com nxt_req_app_link_t *ra); 224216Sigor@sysoev.ru static nxt_int_t nxt_python_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 225216Sigor@sysoev.ru nxt_app_wmsg_t *wmsg); 226216Sigor@sysoev.ru static nxt_int_t nxt_php_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 227216Sigor@sysoev.ru nxt_app_wmsg_t *wmsg); 228216Sigor@sysoev.ru static nxt_int_t nxt_go_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 229216Sigor@sysoev.ru nxt_app_wmsg_t *wmsg); 230510Salexander.borisov@nginx.com static nxt_int_t nxt_perl_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 231510Salexander.borisov@nginx.com nxt_app_wmsg_t *wmsg); 232510Salexander.borisov@nginx.com 23353Sigor@sysoev.ru static void nxt_router_conn_free(nxt_task_t *task, void *obj, void *data); 234318Smax.romanov@nginx.com static void nxt_router_app_timeout(nxt_task_t *task, void *obj, void *data); 235507Smax.romanov@nginx.com static void nxt_router_adjust_idle_timer(nxt_task_t *task, void *obj, 236507Smax.romanov@nginx.com void *data); 237507Smax.romanov@nginx.com static void nxt_router_app_idle_timeout(nxt_task_t *task, void *obj, 238507Smax.romanov@nginx.com void *data); 239507Smax.romanov@nginx.com static void nxt_router_app_release_handler(nxt_task_t *task, void *obj, 240507Smax.romanov@nginx.com void *data); 241431Sigor@sysoev.ru 242431Sigor@sysoev.ru static const nxt_http_request_state_t nxt_http_request_send_state; 243431Sigor@sysoev.ru static void nxt_http_request_send_body(nxt_task_t *task, void *obj, void *data); 244141Smax.romanov@nginx.com 245119Smax.romanov@nginx.com static nxt_router_t *nxt_router; 24620Sigor@sysoev.ru 247216Sigor@sysoev.ru 248216Sigor@sysoev.ru static nxt_app_prepare_msg_t nxt_app_prepare_msg[] = { 249216Sigor@sysoev.ru nxt_python_prepare_msg, 250216Sigor@sysoev.ru nxt_php_prepare_msg, 251216Sigor@sysoev.ru nxt_go_prepare_msg, 252510Salexander.borisov@nginx.com nxt_perl_prepare_msg, 253216Sigor@sysoev.ru }; 254216Sigor@sysoev.ru 255216Sigor@sysoev.ru 25620Sigor@sysoev.ru nxt_int_t 257141Smax.romanov@nginx.com nxt_router_start(nxt_task_t *task, void *data) 25820Sigor@sysoev.ru { 259141Smax.romanov@nginx.com nxt_int_t ret; 260141Smax.romanov@nginx.com nxt_router_t *router; 261141Smax.romanov@nginx.com nxt_runtime_t *rt; 262141Smax.romanov@nginx.com 263141Smax.romanov@nginx.com rt = task->thread->runtime; 26453Sigor@sysoev.ru 265431Sigor@sysoev.ru ret = nxt_http_init(task, rt); 26688Smax.romanov@nginx.com if (nxt_slow_path(ret != NXT_OK)) { 26788Smax.romanov@nginx.com return ret; 26888Smax.romanov@nginx.com } 26988Smax.romanov@nginx.com 27053Sigor@sysoev.ru router = nxt_zalloc(sizeof(nxt_router_t)); 27153Sigor@sysoev.ru if (nxt_slow_path(router == NULL)) { 27253Sigor@sysoev.ru return NXT_ERROR; 27353Sigor@sysoev.ru } 27453Sigor@sysoev.ru 27553Sigor@sysoev.ru nxt_queue_init(&router->engines); 27653Sigor@sysoev.ru nxt_queue_init(&router->sockets); 277133Sigor@sysoev.ru nxt_queue_init(&router->apps); 27853Sigor@sysoev.ru 279119Smax.romanov@nginx.com nxt_router = router; 280119Smax.romanov@nginx.com 281115Sigor@sysoev.ru return NXT_OK; 282115Sigor@sysoev.ru } 283115Sigor@sysoev.ru 284115Sigor@sysoev.ru 285343Smax.romanov@nginx.com static void 286507Smax.romanov@nginx.com nxt_router_start_app_process_handler(nxt_task_t *task, nxt_port_t *port, 287507Smax.romanov@nginx.com void *data) 288167Smax.romanov@nginx.com { 289343Smax.romanov@nginx.com size_t size; 290343Smax.romanov@nginx.com uint32_t stream; 291430Sigor@sysoev.ru nxt_mp_t *mp; 292343Smax.romanov@nginx.com nxt_app_t *app; 293343Smax.romanov@nginx.com nxt_buf_t *b; 294343Smax.romanov@nginx.com nxt_port_t *main_port; 295343Smax.romanov@nginx.com nxt_runtime_t *rt; 296343Smax.romanov@nginx.com 297343Smax.romanov@nginx.com app = data; 298167Smax.romanov@nginx.com 299167Smax.romanov@nginx.com rt = task->thread->runtime; 300240Sigor@sysoev.ru main_port = rt->port_by_type[NXT_PROCESS_MAIN]; 301167Smax.romanov@nginx.com 302507Smax.romanov@nginx.com nxt_debug(task, "app '%V' %p start process", &app->name, app); 303343Smax.romanov@nginx.com 304343Smax.romanov@nginx.com size = app->name.length + 1 + app->conf.length; 305343Smax.romanov@nginx.com 306343Smax.romanov@nginx.com b = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool, size); 307343Smax.romanov@nginx.com 308343Smax.romanov@nginx.com if (nxt_slow_path(b == NULL)) { 309343Smax.romanov@nginx.com goto failed; 310167Smax.romanov@nginx.com } 311167Smax.romanov@nginx.com 312343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->name); 313343Smax.romanov@nginx.com *b->mem.free++ = '\0'; 314343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->conf); 315343Smax.romanov@nginx.com 316343Smax.romanov@nginx.com stream = nxt_port_rpc_register_handler(task, port, 317343Smax.romanov@nginx.com nxt_router_app_port_ready, 318343Smax.romanov@nginx.com nxt_router_app_port_error, 319343Smax.romanov@nginx.com -1, app); 320343Smax.romanov@nginx.com 321343Smax.romanov@nginx.com if (nxt_slow_path(stream == 0)) { 322430Sigor@sysoev.ru mp = b->data; 323430Sigor@sysoev.ru nxt_mp_free(mp, b); 324430Sigor@sysoev.ru nxt_mp_release(mp); 325343Smax.romanov@nginx.com 326343Smax.romanov@nginx.com goto failed; 327343Smax.romanov@nginx.com } 328343Smax.romanov@nginx.com 329343Smax.romanov@nginx.com nxt_port_socket_write(task, main_port, NXT_PORT_MSG_START_WORKER, -1, 330343Smax.romanov@nginx.com stream, port->id, b); 331343Smax.romanov@nginx.com 332343Smax.romanov@nginx.com return; 333343Smax.romanov@nginx.com 334343Smax.romanov@nginx.com failed: 335343Smax.romanov@nginx.com 336343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 337343Smax.romanov@nginx.com 338507Smax.romanov@nginx.com app->pending_processes--; 339343Smax.romanov@nginx.com 340343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 341343Smax.romanov@nginx.com 342343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 343167Smax.romanov@nginx.com } 344167Smax.romanov@nginx.com 345167Smax.romanov@nginx.com 346343Smax.romanov@nginx.com static nxt_int_t 347507Smax.romanov@nginx.com nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app) 348141Smax.romanov@nginx.com { 349343Smax.romanov@nginx.com nxt_int_t res; 350343Smax.romanov@nginx.com nxt_port_t *router_port; 351343Smax.romanov@nginx.com nxt_runtime_t *rt; 352343Smax.romanov@nginx.com 353343Smax.romanov@nginx.com rt = task->thread->runtime; 354343Smax.romanov@nginx.com router_port = rt->port_by_type[NXT_PROCESS_ROUTER]; 355343Smax.romanov@nginx.com 356343Smax.romanov@nginx.com nxt_router_app_use(task, app, 1); 357343Smax.romanov@nginx.com 358507Smax.romanov@nginx.com res = nxt_port_post(task, router_port, nxt_router_start_app_process_handler, 359343Smax.romanov@nginx.com app); 360343Smax.romanov@nginx.com 361343Smax.romanov@nginx.com if (res == NXT_OK) { 362343Smax.romanov@nginx.com return res; 363318Smax.romanov@nginx.com } 364318Smax.romanov@nginx.com 365343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 366343Smax.romanov@nginx.com 367507Smax.romanov@nginx.com app->pending_processes--; 368343Smax.romanov@nginx.com 369343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 370343Smax.romanov@nginx.com 371343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 372343Smax.romanov@nginx.com 373343Smax.romanov@nginx.com return NXT_ERROR; 374318Smax.romanov@nginx.com } 375318Smax.romanov@nginx.com 376318Smax.romanov@nginx.com 377351Smax.romanov@nginx.com nxt_inline void 378351Smax.romanov@nginx.com nxt_router_ra_init(nxt_task_t *task, nxt_req_app_link_t *ra, 379351Smax.romanov@nginx.com nxt_req_conn_link_t *rc) 380167Smax.romanov@nginx.com { 381318Smax.romanov@nginx.com nxt_event_engine_t *engine; 382351Smax.romanov@nginx.com 383318Smax.romanov@nginx.com engine = task->thread->engine; 384167Smax.romanov@nginx.com 385167Smax.romanov@nginx.com nxt_memzero(ra, sizeof(nxt_req_app_link_t)); 386167Smax.romanov@nginx.com 387318Smax.romanov@nginx.com ra->stream = rc->stream; 388425Smax.romanov@nginx.com ra->use_count = 1; 389167Smax.romanov@nginx.com ra->rc = rc; 390318Smax.romanov@nginx.com rc->ra = ra; 391318Smax.romanov@nginx.com ra->reply_port = engine->port; 392351Smax.romanov@nginx.com ra->ap = rc->ap; 393167Smax.romanov@nginx.com 394167Smax.romanov@nginx.com ra->work.handler = NULL; 395318Smax.romanov@nginx.com ra->work.task = &engine->task; 396167Smax.romanov@nginx.com ra->work.obj = ra; 397318Smax.romanov@nginx.com ra->work.data = engine; 398351Smax.romanov@nginx.com } 399351Smax.romanov@nginx.com 400351Smax.romanov@nginx.com 401351Smax.romanov@nginx.com nxt_inline nxt_req_app_link_t * 402351Smax.romanov@nginx.com nxt_router_ra_create(nxt_task_t *task, nxt_req_app_link_t *ra_src) 403351Smax.romanov@nginx.com { 404351Smax.romanov@nginx.com nxt_mp_t *mp; 405351Smax.romanov@nginx.com nxt_req_app_link_t *ra; 406351Smax.romanov@nginx.com 407425Smax.romanov@nginx.com if (ra_src->mem_pool != NULL) { 408425Smax.romanov@nginx.com return ra_src; 409425Smax.romanov@nginx.com } 410425Smax.romanov@nginx.com 411351Smax.romanov@nginx.com mp = ra_src->ap->mem_pool; 412351Smax.romanov@nginx.com 413430Sigor@sysoev.ru ra = nxt_mp_alloc(mp, sizeof(nxt_req_app_link_t)); 414351Smax.romanov@nginx.com 415351Smax.romanov@nginx.com if (nxt_slow_path(ra == NULL)) { 416351Smax.romanov@nginx.com 417351Smax.romanov@nginx.com ra_src->rc->ra = NULL; 418351Smax.romanov@nginx.com ra_src->rc = NULL; 419351Smax.romanov@nginx.com 420351Smax.romanov@nginx.com return NULL; 421351Smax.romanov@nginx.com } 422351Smax.romanov@nginx.com 423430Sigor@sysoev.ru nxt_mp_retain(mp); 424430Sigor@sysoev.ru 425351Smax.romanov@nginx.com nxt_router_ra_init(task, ra, ra_src->rc); 426351Smax.romanov@nginx.com 427351Smax.romanov@nginx.com ra->mem_pool = mp; 428167Smax.romanov@nginx.com 429167Smax.romanov@nginx.com return ra; 430167Smax.romanov@nginx.com } 431167Smax.romanov@nginx.com 432167Smax.romanov@nginx.com 433423Smax.romanov@nginx.com nxt_inline nxt_bool_t 434423Smax.romanov@nginx.com nxt_router_msg_cancel(nxt_task_t *task, nxt_msg_info_t *msg_info, 435423Smax.romanov@nginx.com uint32_t stream) 436423Smax.romanov@nginx.com { 437423Smax.romanov@nginx.com nxt_buf_t *b, *next; 438423Smax.romanov@nginx.com nxt_bool_t cancelled; 439423Smax.romanov@nginx.com 440423Smax.romanov@nginx.com if (msg_info->buf == NULL) { 441423Smax.romanov@nginx.com return 0; 442423Smax.romanov@nginx.com } 443423Smax.romanov@nginx.com 444423Smax.romanov@nginx.com cancelled = nxt_port_mmap_tracking_cancel(task, &msg_info->tracking, 445423Smax.romanov@nginx.com stream); 446423Smax.romanov@nginx.com 447423Smax.romanov@nginx.com if (cancelled) { 448423Smax.romanov@nginx.com nxt_debug(task, "stream #%uD: cancelled by router", stream); 449423Smax.romanov@nginx.com } 450423Smax.romanov@nginx.com 451423Smax.romanov@nginx.com for (b = msg_info->buf; b != NULL; b = next) { 452423Smax.romanov@nginx.com next = b->next; 453423Smax.romanov@nginx.com 454423Smax.romanov@nginx.com b->completion_handler = msg_info->completion_handler; 455423Smax.romanov@nginx.com 456423Smax.romanov@nginx.com if (b->is_port_mmap_sent) { 457423Smax.romanov@nginx.com b->is_port_mmap_sent = cancelled == 0; 458423Smax.romanov@nginx.com b->completion_handler(task, b, b->parent); 459423Smax.romanov@nginx.com } 460423Smax.romanov@nginx.com } 461423Smax.romanov@nginx.com 462423Smax.romanov@nginx.com msg_info->buf = NULL; 463423Smax.romanov@nginx.com 464423Smax.romanov@nginx.com return cancelled; 465423Smax.romanov@nginx.com } 466423Smax.romanov@nginx.com 467423Smax.romanov@nginx.com 468167Smax.romanov@nginx.com static void 469425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra); 470425Smax.romanov@nginx.com 471425Smax.romanov@nginx.com 472425Smax.romanov@nginx.com static void 473425Smax.romanov@nginx.com nxt_router_ra_update_peer_handler(nxt_task_t *task, void *obj, void *data) 474167Smax.romanov@nginx.com { 475425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 476425Smax.romanov@nginx.com 477425Smax.romanov@nginx.com ra = obj; 478425Smax.romanov@nginx.com 479425Smax.romanov@nginx.com nxt_router_ra_update_peer(task, ra); 480425Smax.romanov@nginx.com 481425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 482425Smax.romanov@nginx.com } 483425Smax.romanov@nginx.com 484425Smax.romanov@nginx.com 485425Smax.romanov@nginx.com static void 486425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra) 487425Smax.romanov@nginx.com { 488343Smax.romanov@nginx.com nxt_event_engine_t *engine; 489343Smax.romanov@nginx.com nxt_req_conn_link_t *rc; 490318Smax.romanov@nginx.com 491425Smax.romanov@nginx.com engine = ra->work.data; 492318Smax.romanov@nginx.com 493343Smax.romanov@nginx.com if (task->thread->engine != engine) { 494425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 495425Smax.romanov@nginx.com 496425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_update_peer_handler; 497318Smax.romanov@nginx.com ra->work.task = &engine->task; 498318Smax.romanov@nginx.com ra->work.next = NULL; 499318Smax.romanov@nginx.com 500425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post update peer to %p", 501318Smax.romanov@nginx.com ra->stream, engine); 502318Smax.romanov@nginx.com 503318Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 504318Smax.romanov@nginx.com 505318Smax.romanov@nginx.com return; 506318Smax.romanov@nginx.com } 507318Smax.romanov@nginx.com 508425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD update peer", ra->stream); 509425Smax.romanov@nginx.com 510425Smax.romanov@nginx.com rc = ra->rc; 511425Smax.romanov@nginx.com 512425Smax.romanov@nginx.com if (rc != NULL && ra->app_port != NULL) { 513425Smax.romanov@nginx.com nxt_port_rpc_ex_set_peer(task, engine->port, rc, ra->app_port->pid); 514425Smax.romanov@nginx.com } 515425Smax.romanov@nginx.com 516425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 517425Smax.romanov@nginx.com } 518425Smax.romanov@nginx.com 519425Smax.romanov@nginx.com 520425Smax.romanov@nginx.com static void 521425Smax.romanov@nginx.com nxt_router_ra_release(nxt_task_t *task, nxt_req_app_link_t *ra) 522425Smax.romanov@nginx.com { 523431Sigor@sysoev.ru nxt_mp_t *mp; 524431Sigor@sysoev.ru nxt_req_conn_link_t *rc; 525425Smax.romanov@nginx.com 526425Smax.romanov@nginx.com nxt_assert(task->thread->engine == ra->work.data); 527425Smax.romanov@nginx.com nxt_assert(ra->use_count == 0); 528425Smax.romanov@nginx.com 529343Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD release", ra->stream); 530343Smax.romanov@nginx.com 531343Smax.romanov@nginx.com rc = ra->rc; 532343Smax.romanov@nginx.com 533343Smax.romanov@nginx.com if (rc != NULL) { 534423Smax.romanov@nginx.com if (nxt_slow_path(ra->err_code != 0)) { 535431Sigor@sysoev.ru nxt_http_request_error(task, rc->ap->request, ra->err_code); 536423Smax.romanov@nginx.com 537423Smax.romanov@nginx.com } else { 538423Smax.romanov@nginx.com rc->app_port = ra->app_port; 539423Smax.romanov@nginx.com rc->msg_info = ra->msg_info; 540423Smax.romanov@nginx.com 541425Smax.romanov@nginx.com if (rc->app->timeout != 0) { 542431Sigor@sysoev.ru rc->ap->timer.handler = nxt_router_app_timeout; 543431Sigor@sysoev.ru nxt_timer_add(task->thread->engine, &rc->ap->timer, 544425Smax.romanov@nginx.com rc->app->timeout); 545425Smax.romanov@nginx.com } 546425Smax.romanov@nginx.com 547423Smax.romanov@nginx.com ra->app_port = NULL; 548423Smax.romanov@nginx.com ra->msg_info.buf = NULL; 549423Smax.romanov@nginx.com } 550343Smax.romanov@nginx.com 551343Smax.romanov@nginx.com rc->ra = NULL; 552343Smax.romanov@nginx.com ra->rc = NULL; 553343Smax.romanov@nginx.com } 554343Smax.romanov@nginx.com 555343Smax.romanov@nginx.com if (ra->app_port != NULL) { 556343Smax.romanov@nginx.com nxt_router_app_port_release(task, ra->app_port, 0, 1); 557343Smax.romanov@nginx.com 558343Smax.romanov@nginx.com ra->app_port = NULL; 559167Smax.romanov@nginx.com } 560167Smax.romanov@nginx.com 561423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &ra->msg_info, ra->stream); 562423Smax.romanov@nginx.com 563430Sigor@sysoev.ru mp = ra->mem_pool; 564430Sigor@sysoev.ru 565430Sigor@sysoev.ru if (mp != NULL) { 566430Sigor@sysoev.ru nxt_mp_free(mp, ra); 567430Sigor@sysoev.ru nxt_mp_release(mp); 568351Smax.romanov@nginx.com } 569167Smax.romanov@nginx.com } 570167Smax.romanov@nginx.com 571167Smax.romanov@nginx.com 572425Smax.romanov@nginx.com static void 573425Smax.romanov@nginx.com nxt_router_ra_release_handler(nxt_task_t *task, void *obj, void *data) 574425Smax.romanov@nginx.com { 575425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 576425Smax.romanov@nginx.com 577425Smax.romanov@nginx.com ra = obj; 578425Smax.romanov@nginx.com 579425Smax.romanov@nginx.com nxt_assert(ra->work.data == data); 580425Smax.romanov@nginx.com 581425Smax.romanov@nginx.com nxt_atomic_fetch_add(&ra->use_count, -1); 582425Smax.romanov@nginx.com 583425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 584425Smax.romanov@nginx.com } 585425Smax.romanov@nginx.com 586425Smax.romanov@nginx.com 587425Smax.romanov@nginx.com static void 588425Smax.romanov@nginx.com nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i) 589425Smax.romanov@nginx.com { 590425Smax.romanov@nginx.com int c; 591425Smax.romanov@nginx.com nxt_event_engine_t *engine; 592425Smax.romanov@nginx.com 593425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, i); 594425Smax.romanov@nginx.com 595425Smax.romanov@nginx.com if (i < 0 && c == -i) { 596425Smax.romanov@nginx.com engine = ra->work.data; 597425Smax.romanov@nginx.com 598425Smax.romanov@nginx.com if (task->thread->engine == engine) { 599425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 600425Smax.romanov@nginx.com 601425Smax.romanov@nginx.com return; 602425Smax.romanov@nginx.com } 603425Smax.romanov@nginx.com 604425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 605425Smax.romanov@nginx.com 606425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_release_handler; 607425Smax.romanov@nginx.com ra->work.task = &engine->task; 608425Smax.romanov@nginx.com ra->work.next = NULL; 609425Smax.romanov@nginx.com 610425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post release to %p", 611425Smax.romanov@nginx.com ra->stream, engine); 612425Smax.romanov@nginx.com 613425Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 614425Smax.romanov@nginx.com } 615425Smax.romanov@nginx.com } 616425Smax.romanov@nginx.com 617425Smax.romanov@nginx.com 618423Smax.romanov@nginx.com nxt_inline void 619521Szelenkov@nginx.com nxt_router_ra_error(nxt_req_app_link_t *ra, int code, const char *str) 620345Smax.romanov@nginx.com { 621423Smax.romanov@nginx.com ra->app_port = NULL; 622423Smax.romanov@nginx.com ra->err_code = code; 623423Smax.romanov@nginx.com ra->err_str = str; 624345Smax.romanov@nginx.com } 625345Smax.romanov@nginx.com 626345Smax.romanov@nginx.com 627427Smax.romanov@nginx.com nxt_inline void 628427Smax.romanov@nginx.com nxt_router_ra_pending(nxt_task_t *task, nxt_app_t *app, nxt_req_app_link_t *ra) 629427Smax.romanov@nginx.com { 630427Smax.romanov@nginx.com nxt_queue_insert_tail(&ra->app_port->pending_requests, 631427Smax.romanov@nginx.com &ra->link_port_pending); 632427Smax.romanov@nginx.com nxt_queue_insert_tail(&app->pending, &ra->link_app_pending); 633427Smax.romanov@nginx.com 634427Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 635427Smax.romanov@nginx.com 636427Smax.romanov@nginx.com ra->res_time = nxt_thread_monotonic_time(task->thread) + app->res_timeout; 637427Smax.romanov@nginx.com 638427Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD enqueue to pending_requests", ra->stream); 639427Smax.romanov@nginx.com } 640427Smax.romanov@nginx.com 641427Smax.romanov@nginx.com 642425Smax.romanov@nginx.com nxt_inline nxt_bool_t 643425Smax.romanov@nginx.com nxt_queue_chk_remove(nxt_queue_link_t *lnk) 644425Smax.romanov@nginx.com { 645425Smax.romanov@nginx.com if (lnk->next != NULL) { 646425Smax.romanov@nginx.com nxt_queue_remove(lnk); 647425Smax.romanov@nginx.com 648425Smax.romanov@nginx.com lnk->next = NULL; 649425Smax.romanov@nginx.com 650425Smax.romanov@nginx.com return 1; 651425Smax.romanov@nginx.com } 652425Smax.romanov@nginx.com 653425Smax.romanov@nginx.com return 0; 654425Smax.romanov@nginx.com } 655425Smax.romanov@nginx.com 656425Smax.romanov@nginx.com 657343Smax.romanov@nginx.com nxt_inline void 658343Smax.romanov@nginx.com nxt_router_rc_unlink(nxt_task_t *task, nxt_req_conn_link_t *rc) 659343Smax.romanov@nginx.com { 660425Smax.romanov@nginx.com int ra_use_delta; 661343Smax.romanov@nginx.com nxt_req_app_link_t *ra; 662343Smax.romanov@nginx.com 663343Smax.romanov@nginx.com if (rc->app_port != NULL) { 664343Smax.romanov@nginx.com nxt_router_app_port_release(task, rc->app_port, 0, 1); 665343Smax.romanov@nginx.com 666343Smax.romanov@nginx.com rc->app_port = NULL; 667343Smax.romanov@nginx.com } 668343Smax.romanov@nginx.com 669423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &rc->msg_info, rc->stream); 670423Smax.romanov@nginx.com 671343Smax.romanov@nginx.com ra = rc->ra; 672343Smax.romanov@nginx.com 673343Smax.romanov@nginx.com if (ra != NULL) { 674343Smax.romanov@nginx.com rc->ra = NULL; 675343Smax.romanov@nginx.com ra->rc = NULL; 676343Smax.romanov@nginx.com 677425Smax.romanov@nginx.com ra_use_delta = 0; 678425Smax.romanov@nginx.com 679343Smax.romanov@nginx.com nxt_thread_mutex_lock(&rc->app->mutex); 680343Smax.romanov@nginx.com 681425Smax.romanov@nginx.com if (ra->link_app_requests.next == NULL 682427Smax.romanov@nginx.com && ra->link_port_pending.next == NULL 683427Smax.romanov@nginx.com && ra->link_app_pending.next == NULL) 684425Smax.romanov@nginx.com { 685425Smax.romanov@nginx.com ra = NULL; 686343Smax.romanov@nginx.com 687343Smax.romanov@nginx.com } else { 688425Smax.romanov@nginx.com ra_use_delta -= nxt_queue_chk_remove(&ra->link_app_requests); 689425Smax.romanov@nginx.com ra_use_delta -= nxt_queue_chk_remove(&ra->link_port_pending); 690427Smax.romanov@nginx.com nxt_queue_chk_remove(&ra->link_app_pending); 691343Smax.romanov@nginx.com } 692343Smax.romanov@nginx.com 693343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&rc->app->mutex); 694425Smax.romanov@nginx.com 695425Smax.romanov@nginx.com if (ra != NULL) { 696425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, ra_use_delta); 697425Smax.romanov@nginx.com } 698343Smax.romanov@nginx.com } 699343Smax.romanov@nginx.com 700343Smax.romanov@nginx.com if (rc->app != NULL) { 701343Smax.romanov@nginx.com nxt_router_app_use(task, rc->app, -1); 702343Smax.romanov@nginx.com 703343Smax.romanov@nginx.com rc->app = NULL; 704343Smax.romanov@nginx.com } 705343Smax.romanov@nginx.com 706346Smax.romanov@nginx.com if (rc->ap != NULL) { 707346Smax.romanov@nginx.com nxt_app_http_req_done(task, rc->ap); 708346Smax.romanov@nginx.com 709346Smax.romanov@nginx.com rc->ap = NULL; 710346Smax.romanov@nginx.com } 711343Smax.romanov@nginx.com } 712343Smax.romanov@nginx.com 713343Smax.romanov@nginx.com 714141Smax.romanov@nginx.com void 715141Smax.romanov@nginx.com nxt_router_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) 716141Smax.romanov@nginx.com { 717141Smax.romanov@nginx.com nxt_port_new_port_handler(task, msg); 718141Smax.romanov@nginx.com 719192Smax.romanov@nginx.com if (msg->port_msg.stream == 0) { 720141Smax.romanov@nginx.com return; 721141Smax.romanov@nginx.com } 722141Smax.romanov@nginx.com 723426Smax.romanov@nginx.com if (msg->u.new_port == NULL 724426Smax.romanov@nginx.com || msg->u.new_port->type != NXT_PROCESS_WORKER) 725347Smax.romanov@nginx.com { 726192Smax.romanov@nginx.com msg->port_msg.type = _NXT_PORT_MSG_RPC_ERROR; 727141Smax.romanov@nginx.com } 728192Smax.romanov@nginx.com 729192Smax.romanov@nginx.com nxt_port_rpc_handler(task, msg); 730141Smax.romanov@nginx.com } 731141Smax.romanov@nginx.com 732141Smax.romanov@nginx.com 733139Sigor@sysoev.ru void 734139Sigor@sysoev.ru nxt_router_conf_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) 735115Sigor@sysoev.ru { 736198Sigor@sysoev.ru nxt_int_t ret; 737139Sigor@sysoev.ru nxt_buf_t *b; 738139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf; 739139Sigor@sysoev.ru 740139Sigor@sysoev.ru tmcf = nxt_router_temp_conf(task); 741139Sigor@sysoev.ru if (nxt_slow_path(tmcf == NULL)) { 742139Sigor@sysoev.ru return; 74353Sigor@sysoev.ru } 74453Sigor@sysoev.ru 745494Spluknet@nginx.com nxt_debug(task, "nxt_router_conf_data_handler(%O): %*s", 746423Smax.romanov@nginx.com nxt_buf_used_size(msg->buf), 747493Spluknet@nginx.com (size_t) nxt_buf_used_size(msg->buf), msg->buf->mem.pos); 748423Smax.romanov@nginx.com 749352Smax.romanov@nginx.com b = nxt_buf_chk_make_plain(tmcf->conf->mem_pool, msg->buf, msg->size); 750352Smax.romanov@nginx.com 751352Smax.romanov@nginx.com nxt_assert(b != NULL); 752352Smax.romanov@nginx.com 753139Sigor@sysoev.ru tmcf->conf->router = nxt_router; 754139Sigor@sysoev.ru tmcf->stream = msg->port_msg.stream; 755139Sigor@sysoev.ru tmcf->port = nxt_runtime_port_find(task->thread->runtime, 756198Sigor@sysoev.ru msg->port_msg.pid, 757198Sigor@sysoev.ru msg->port_msg.reply_port); 758198Sigor@sysoev.ru 759198Sigor@sysoev.ru ret = nxt_router_conf_create(task, tmcf, b->mem.pos, b->mem.free); 760198Sigor@sysoev.ru 761198Sigor@sysoev.ru if (nxt_fast_path(ret == NXT_OK)) { 762198Sigor@sysoev.ru nxt_router_conf_apply(task, tmcf, NULL); 763198Sigor@sysoev.ru 764198Sigor@sysoev.ru } else { 765198Sigor@sysoev.ru nxt_router_conf_error(task, tmcf); 766139Sigor@sysoev.ru } 76753Sigor@sysoev.ru } 76853Sigor@sysoev.ru 76953Sigor@sysoev.ru 770347Smax.romanov@nginx.com static void 771507Smax.romanov@nginx.com nxt_router_app_process_remove_pid(nxt_task_t *task, nxt_port_t *port, 772507Smax.romanov@nginx.com void *data) 773347Smax.romanov@nginx.com { 774347Smax.romanov@nginx.com union { 775347Smax.romanov@nginx.com nxt_pid_t removed_pid; 776347Smax.romanov@nginx.com void *data; 777347Smax.romanov@nginx.com } u; 778347Smax.romanov@nginx.com 779347Smax.romanov@nginx.com u.data = data; 780347Smax.romanov@nginx.com 781347Smax.romanov@nginx.com nxt_port_rpc_remove_peer(task, port, u.removed_pid); 782347Smax.romanov@nginx.com } 783347Smax.romanov@nginx.com 784347Smax.romanov@nginx.com 785192Smax.romanov@nginx.com void 786192Smax.romanov@nginx.com nxt_router_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) 787192Smax.romanov@nginx.com { 788347Smax.romanov@nginx.com nxt_event_engine_t *engine; 789318Smax.romanov@nginx.com 790192Smax.romanov@nginx.com nxt_port_remove_pid_handler(task, msg); 791192Smax.romanov@nginx.com 792192Smax.romanov@nginx.com if (msg->port_msg.stream == 0) { 793192Smax.romanov@nginx.com return; 794192Smax.romanov@nginx.com } 795192Smax.romanov@nginx.com 796318Smax.romanov@nginx.com nxt_queue_each(engine, &