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 { 120425Smax.romanov@nginx.com int c; 121425Smax.romanov@nginx.com 122425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, -1); 123425Smax.romanov@nginx.com 124425Smax.romanov@nginx.com nxt_assert(c > 1); 125425Smax.romanov@nginx.com } 126425Smax.romanov@nginx.com 127425Smax.romanov@nginx.com static void nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i); 128425Smax.romanov@nginx.com 129139Sigor@sysoev.ru static nxt_router_temp_conf_t *nxt_router_temp_conf(nxt_task_t *task); 130198Sigor@sysoev.ru static void nxt_router_conf_apply(nxt_task_t *task, void *obj, void *data); 131198Sigor@sysoev.ru static void nxt_router_conf_ready(nxt_task_t *task, 132139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 133139Sigor@sysoev.ru static void nxt_router_conf_error(nxt_task_t *task, 134139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 135139Sigor@sysoev.ru static void nxt_router_conf_send(nxt_task_t *task, 136193Smax.romanov@nginx.com nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type); 13753Sigor@sysoev.ru 138115Sigor@sysoev.ru static nxt_int_t nxt_router_conf_create(nxt_task_t *task, 139115Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, u_char *start, u_char *end); 140133Sigor@sysoev.ru static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name); 141133Sigor@sysoev.ru static nxt_app_t *nxt_router_listener_application(nxt_router_temp_conf_t *tmcf, 142133Sigor@sysoev.ru nxt_str_t *name); 143198Sigor@sysoev.ru static void nxt_router_listen_socket_rpc_create(nxt_task_t *task, 144198Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, nxt_socket_conf_t *skcf); 145198Sigor@sysoev.ru static void nxt_router_listen_socket_ready(nxt_task_t *task, 146198Sigor@sysoev.ru nxt_port_recv_msg_t *msg, void *data); 147198Sigor@sysoev.ru static void nxt_router_listen_socket_error(nxt_task_t *task, 148198Sigor@sysoev.ru nxt_port_recv_msg_t *msg, void *data); 149507Smax.romanov@nginx.com static void nxt_router_app_rpc_create(nxt_task_t *task, 150507Smax.romanov@nginx.com nxt_router_temp_conf_t *tmcf, nxt_app_t *app); 151507Smax.romanov@nginx.com static void nxt_router_app_prefork_ready(nxt_task_t *task, 152507Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 153507Smax.romanov@nginx.com static void nxt_router_app_prefork_error(nxt_task_t *task, 154507Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 155359Sigor@sysoev.ru static nxt_socket_conf_t *nxt_router_socket_conf(nxt_task_t *task, 156359Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, nxt_str_t *name); 157359Sigor@sysoev.ru static nxt_int_t nxt_router_listen_socket_find(nxt_router_temp_conf_t *tmcf, 158359Sigor@sysoev.ru nxt_socket_conf_t *nskcf, nxt_sockaddr_t *sa); 15953Sigor@sysoev.ru 16053Sigor@sysoev.ru static nxt_int_t nxt_router_engines_create(nxt_task_t *task, 16153Sigor@sysoev.ru nxt_router_t *router, nxt_router_temp_conf_t *tmcf, 16253Sigor@sysoev.ru const nxt_event_interface_t *interface); 163115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_create(nxt_router_temp_conf_t *tmcf, 164115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 165115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_update(nxt_router_temp_conf_t *tmcf, 166115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 167115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_delete(nxt_router_temp_conf_t *tmcf, 168115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 169154Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_create(nxt_router_temp_conf_t *tmcf, 170154Sigor@sysoev.ru nxt_router_engine_conf_t *recf, nxt_queue_t *sockets, 171154Sigor@sysoev.ru nxt_work_handler_t handler); 172313Sigor@sysoev.ru static nxt_int_t nxt_router_engine_quit(nxt_router_temp_conf_t *tmcf, 173313Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 174139Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_delete(nxt_router_temp_conf_t *tmcf, 175139Sigor@sysoev.ru nxt_router_engine_conf_t *recf, nxt_queue_t *sockets); 17653Sigor@sysoev.ru 17753Sigor@sysoev.ru static nxt_int_t nxt_router_threads_create(nxt_task_t *task, nxt_runtime_t *rt, 17853Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 17953Sigor@sysoev.ru static nxt_int_t nxt_router_thread_create(nxt_task_t *task, nxt_runtime_t *rt, 18053Sigor@sysoev.ru nxt_event_engine_t *engine); 181343Smax.romanov@nginx.com static void nxt_router_apps_sort(nxt_task_t *task, nxt_router_t *router, 182133Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 18353Sigor@sysoev.ru 184315Sigor@sysoev.ru static void nxt_router_engines_post(nxt_router_t *router, 185315Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 186315Sigor@sysoev.ru static void nxt_router_engine_post(nxt_event_engine_t *engine, 187315Sigor@sysoev.ru nxt_work_t *jobs); 18853Sigor@sysoev.ru 18953Sigor@sysoev.ru static void nxt_router_thread_start(void *data); 19053Sigor@sysoev.ru static void nxt_router_listen_socket_create(nxt_task_t *task, void *obj, 19153Sigor@sysoev.ru void *data); 19253Sigor@sysoev.ru static void nxt_router_listen_socket_update(nxt_task_t *task, void *obj, 19353Sigor@sysoev.ru void *data); 19453Sigor@sysoev.ru static void nxt_router_listen_socket_delete(nxt_task_t *task, void *obj, 19553Sigor@sysoev.ru void *data); 196313Sigor@sysoev.ru static void nxt_router_worker_thread_quit(nxt_task_t *task, void *obj, 197313Sigor@sysoev.ru void *data); 19853Sigor@sysoev.ru static void nxt_router_listen_socket_close(nxt_task_t *task, void *obj, 19953Sigor@sysoev.ru void *data); 20053Sigor@sysoev.ru static void nxt_router_thread_exit_handler(nxt_task_t *task, void *obj, 20153Sigor@sysoev.ru void *data); 202359Sigor@sysoev.ru static void nxt_router_listen_socket_release(nxt_task_t *task, 203359Sigor@sysoev.ru nxt_socket_conf_t *skcf); 20453Sigor@sysoev.ru static void nxt_router_conf_release(nxt_task_t *task, 20553Sigor@sysoev.ru nxt_socket_conf_joint_t *joint); 20653Sigor@sysoev.ru 207343Smax.romanov@nginx.com static void nxt_router_app_port_ready(nxt_task_t *task, 208343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 209343Smax.romanov@nginx.com static void nxt_router_app_port_error(nxt_task_t *task, 210343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 211343Smax.romanov@nginx.com 212507Smax.romanov@nginx.com static void nxt_router_app_quit(nxt_task_t *task, nxt_app_t *app); 213343Smax.romanov@nginx.com static void nxt_router_app_port_release(nxt_task_t *task, nxt_port_t *port, 214343Smax.romanov@nginx.com uint32_t request_failed, uint32_t got_response); 215427Smax.romanov@nginx.com static nxt_int_t nxt_router_app_port(nxt_task_t *task, nxt_app_t *app, 216427Smax.romanov@nginx.com nxt_req_app_link_t *ra); 217141Smax.romanov@nginx.com 218425Smax.romanov@nginx.com static void nxt_router_app_prepare_request(nxt_task_t *task, 219343Smax.romanov@nginx.com nxt_req_app_link_t *ra); 220216Sigor@sysoev.ru static nxt_int_t nxt_python_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 221216Sigor@sysoev.ru nxt_app_wmsg_t *wmsg); 222216Sigor@sysoev.ru static nxt_int_t nxt_php_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 223216Sigor@sysoev.ru nxt_app_wmsg_t *wmsg); 224216Sigor@sysoev.ru static nxt_int_t nxt_go_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 225216Sigor@sysoev.ru nxt_app_wmsg_t *wmsg); 226*510Salexander.borisov@nginx.com static nxt_int_t nxt_perl_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 227*510Salexander.borisov@nginx.com nxt_app_wmsg_t *wmsg); 228*510Salexander.borisov@nginx.com 22953Sigor@sysoev.ru static void nxt_router_conn_free(nxt_task_t *task, void *obj, void *data); 230318Smax.romanov@nginx.com static void nxt_router_app_timeout(nxt_task_t *task, void *obj, void *data); 231507Smax.romanov@nginx.com static void nxt_router_adjust_idle_timer(nxt_task_t *task, void *obj, 232507Smax.romanov@nginx.com void *data); 233507Smax.romanov@nginx.com static void nxt_router_app_idle_timeout(nxt_task_t *task, void *obj, 234507Smax.romanov@nginx.com void *data); 235507Smax.romanov@nginx.com static void nxt_router_app_release_handler(nxt_task_t *task, void *obj, 236507Smax.romanov@nginx.com void *data); 237431Sigor@sysoev.ru 238431Sigor@sysoev.ru static const nxt_http_request_state_t nxt_http_request_send_state; 239431Sigor@sysoev.ru static void nxt_http_request_send_body(nxt_task_t *task, void *obj, void *data); 240141Smax.romanov@nginx.com 241119Smax.romanov@nginx.com static nxt_router_t *nxt_router; 24220Sigor@sysoev.ru 243216Sigor@sysoev.ru 244216Sigor@sysoev.ru static nxt_app_prepare_msg_t nxt_app_prepare_msg[] = { 245216Sigor@sysoev.ru nxt_python_prepare_msg, 246216Sigor@sysoev.ru nxt_php_prepare_msg, 247216Sigor@sysoev.ru nxt_go_prepare_msg, 248*510Salexander.borisov@nginx.com nxt_perl_prepare_msg, 249216Sigor@sysoev.ru }; 250216Sigor@sysoev.ru 251216Sigor@sysoev.ru 25220Sigor@sysoev.ru nxt_int_t 253141Smax.romanov@nginx.com nxt_router_start(nxt_task_t *task, void *data) 25420Sigor@sysoev.ru { 255141Smax.romanov@nginx.com nxt_int_t ret; 256141Smax.romanov@nginx.com nxt_router_t *router; 257141Smax.romanov@nginx.com nxt_runtime_t *rt; 258141Smax.romanov@nginx.com 259141Smax.romanov@nginx.com rt = task->thread->runtime; 26053Sigor@sysoev.ru 261431Sigor@sysoev.ru ret = nxt_http_init(task, rt); 26288Smax.romanov@nginx.com if (nxt_slow_path(ret != NXT_OK)) { 26388Smax.romanov@nginx.com return ret; 26488Smax.romanov@nginx.com } 26588Smax.romanov@nginx.com 26653Sigor@sysoev.ru router = nxt_zalloc(sizeof(nxt_router_t)); 26753Sigor@sysoev.ru if (nxt_slow_path(router == NULL)) { 26853Sigor@sysoev.ru return NXT_ERROR; 26953Sigor@sysoev.ru } 27053Sigor@sysoev.ru 27153Sigor@sysoev.ru nxt_queue_init(&router->engines); 27253Sigor@sysoev.ru nxt_queue_init(&router->sockets); 273133Sigor@sysoev.ru nxt_queue_init(&router->apps); 27453Sigor@sysoev.ru 275119Smax.romanov@nginx.com nxt_router = router; 276119Smax.romanov@nginx.com 277115Sigor@sysoev.ru return NXT_OK; 278115Sigor@sysoev.ru } 279115Sigor@sysoev.ru 280115Sigor@sysoev.ru 281343Smax.romanov@nginx.com static void 282507Smax.romanov@nginx.com nxt_router_start_app_process_handler(nxt_task_t *task, nxt_port_t *port, 283507Smax.romanov@nginx.com void *data) 284167Smax.romanov@nginx.com { 285343Smax.romanov@nginx.com size_t size; 286343Smax.romanov@nginx.com uint32_t stream; 287430Sigor@sysoev.ru nxt_mp_t *mp; 288343Smax.romanov@nginx.com nxt_app_t *app; 289343Smax.romanov@nginx.com nxt_buf_t *b; 290343Smax.romanov@nginx.com nxt_port_t *main_port; 291343Smax.romanov@nginx.com nxt_runtime_t *rt; 292343Smax.romanov@nginx.com 293343Smax.romanov@nginx.com app = data; 294167Smax.romanov@nginx.com 295167Smax.romanov@nginx.com rt = task->thread->runtime; 296240Sigor@sysoev.ru main_port = rt->port_by_type[NXT_PROCESS_MAIN]; 297167Smax.romanov@nginx.com 298507Smax.romanov@nginx.com nxt_debug(task, "app '%V' %p start process", &app->name, app); 299343Smax.romanov@nginx.com 300343Smax.romanov@nginx.com size = app->name.length + 1 + app->conf.length; 301343Smax.romanov@nginx.com 302343Smax.romanov@nginx.com b = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool, size); 303343Smax.romanov@nginx.com 304343Smax.romanov@nginx.com if (nxt_slow_path(b == NULL)) { 305343Smax.romanov@nginx.com goto failed; 306167Smax.romanov@nginx.com } 307167Smax.romanov@nginx.com 308343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->name); 309343Smax.romanov@nginx.com *b->mem.free++ = '\0'; 310343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->conf); 311343Smax.romanov@nginx.com 312343Smax.romanov@nginx.com stream = nxt_port_rpc_register_handler(task, port, 313343Smax.romanov@nginx.com nxt_router_app_port_ready, 314343Smax.romanov@nginx.com nxt_router_app_port_error, 315343Smax.romanov@nginx.com -1, app); 316343Smax.romanov@nginx.com 317343Smax.romanov@nginx.com if (nxt_slow_path(stream == 0)) { 318430Sigor@sysoev.ru mp = b->data; 319430Sigor@sysoev.ru nxt_mp_free(mp, b); 320430Sigor@sysoev.ru nxt_mp_release(mp); 321343Smax.romanov@nginx.com 322343Smax.romanov@nginx.com goto failed; 323343Smax.romanov@nginx.com } 324343Smax.romanov@nginx.com 325343Smax.romanov@nginx.com nxt_port_socket_write(task, main_port, NXT_PORT_MSG_START_WORKER, -1, 326343Smax.romanov@nginx.com stream, port->id, b); 327343Smax.romanov@nginx.com 328343Smax.romanov@nginx.com return; 329343Smax.romanov@nginx.com 330343Smax.romanov@nginx.com failed: 331343Smax.romanov@nginx.com 332343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 333343Smax.romanov@nginx.com 334507Smax.romanov@nginx.com app->pending_processes--; 335343Smax.romanov@nginx.com 336343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 337343Smax.romanov@nginx.com 338343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 339167Smax.romanov@nginx.com } 340167Smax.romanov@nginx.com 341167Smax.romanov@nginx.com 342343Smax.romanov@nginx.com static nxt_int_t 343507Smax.romanov@nginx.com nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app) 344141Smax.romanov@nginx.com { 345343Smax.romanov@nginx.com nxt_int_t res; 346343Smax.romanov@nginx.com nxt_port_t *router_port; 347343Smax.romanov@nginx.com nxt_runtime_t *rt; 348343Smax.romanov@nginx.com 349343Smax.romanov@nginx.com rt = task->thread->runtime; 350343Smax.romanov@nginx.com router_port = rt->port_by_type[NXT_PROCESS_ROUTER]; 351343Smax.romanov@nginx.com 352343Smax.romanov@nginx.com nxt_router_app_use(task, app, 1); 353343Smax.romanov@nginx.com 354507Smax.romanov@nginx.com res = nxt_port_post(task, router_port, nxt_router_start_app_process_handler, 355343Smax.romanov@nginx.com app); 356343Smax.romanov@nginx.com 357343Smax.romanov@nginx.com if (res == NXT_OK) { 358343Smax.romanov@nginx.com return res; 359318Smax.romanov@nginx.com } 360318Smax.romanov@nginx.com 361343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 362343Smax.romanov@nginx.com 363507Smax.romanov@nginx.com app->pending_processes--; 364343Smax.romanov@nginx.com 365343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 366343Smax.romanov@nginx.com 367343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 368343Smax.romanov@nginx.com 369343Smax.romanov@nginx.com return NXT_ERROR; 370318Smax.romanov@nginx.com } 371318Smax.romanov@nginx.com 372318Smax.romanov@nginx.com 373351Smax.romanov@nginx.com nxt_inline void 374351Smax.romanov@nginx.com nxt_router_ra_init(nxt_task_t *task, nxt_req_app_link_t *ra, 375351Smax.romanov@nginx.com nxt_req_conn_link_t *rc) 376167Smax.romanov@nginx.com { 377318Smax.romanov@nginx.com nxt_event_engine_t *engine; 378351Smax.romanov@nginx.com 379318Smax.romanov@nginx.com engine = task->thread->engine; 380167Smax.romanov@nginx.com 381167Smax.romanov@nginx.com nxt_memzero(ra, sizeof(nxt_req_app_link_t)); 382167Smax.romanov@nginx.com 383318Smax.romanov@nginx.com ra->stream = rc->stream; 384425Smax.romanov@nginx.com ra->use_count = 1; 385167Smax.romanov@nginx.com ra->rc = rc; 386318Smax.romanov@nginx.com rc->ra = ra; 387318Smax.romanov@nginx.com ra->reply_port = engine->port; 388351Smax.romanov@nginx.com ra->ap = rc->ap; 389167Smax.romanov@nginx.com 390167Smax.romanov@nginx.com ra->work.handler = NULL; 391318Smax.romanov@nginx.com ra->work.task = &engine->task; 392167Smax.romanov@nginx.com ra->work.obj = ra; 393318Smax.romanov@nginx.com ra->work.data = engine; 394351Smax.romanov@nginx.com } 395351Smax.romanov@nginx.com 396351Smax.romanov@nginx.com 397351Smax.romanov@nginx.com nxt_inline nxt_req_app_link_t * 398351Smax.romanov@nginx.com nxt_router_ra_create(nxt_task_t *task, nxt_req_app_link_t *ra_src) 399351Smax.romanov@nginx.com { 400351Smax.romanov@nginx.com nxt_mp_t *mp; 401351Smax.romanov@nginx.com nxt_req_app_link_t *ra; 402351Smax.romanov@nginx.com 403425Smax.romanov@nginx.com if (ra_src->mem_pool != NULL) { 404425Smax.romanov@nginx.com return ra_src; 405425Smax.romanov@nginx.com } 406425Smax.romanov@nginx.com 407351Smax.romanov@nginx.com mp = ra_src->ap->mem_pool; 408351Smax.romanov@nginx.com 409430Sigor@sysoev.ru ra = nxt_mp_alloc(mp, sizeof(nxt_req_app_link_t)); 410351Smax.romanov@nginx.com 411351Smax.romanov@nginx.com if (nxt_slow_path(ra == NULL)) { 412351Smax.romanov@nginx.com 413351Smax.romanov@nginx.com ra_src->rc->ra = NULL; 414351Smax.romanov@nginx.com ra_src->rc = NULL; 415351Smax.romanov@nginx.com 416351Smax.romanov@nginx.com return NULL; 417351Smax.romanov@nginx.com } 418351Smax.romanov@nginx.com 419430Sigor@sysoev.ru nxt_mp_retain(mp); 420430Sigor@sysoev.ru 421351Smax.romanov@nginx.com nxt_router_ra_init(task, ra, ra_src->rc); 422351Smax.romanov@nginx.com 423351Smax.romanov@nginx.com ra->mem_pool = mp; 424167Smax.romanov@nginx.com 425167Smax.romanov@nginx.com return ra; 426167Smax.romanov@nginx.com } 427167Smax.romanov@nginx.com 428167Smax.romanov@nginx.com 429423Smax.romanov@nginx.com nxt_inline nxt_bool_t 430423Smax.romanov@nginx.com nxt_router_msg_cancel(nxt_task_t *task, nxt_msg_info_t *msg_info, 431423Smax.romanov@nginx.com uint32_t stream) 432423Smax.romanov@nginx.com { 433423Smax.romanov@nginx.com nxt_buf_t *b, *next; 434423Smax.romanov@nginx.com nxt_bool_t cancelled; 435423Smax.romanov@nginx.com 436423Smax.romanov@nginx.com if (msg_info->buf == NULL) { 437423Smax.romanov@nginx.com return 0; 438423Smax.romanov@nginx.com } 439423Smax.romanov@nginx.com 440423Smax.romanov@nginx.com cancelled = nxt_port_mmap_tracking_cancel(task, &msg_info->tracking, 441423Smax.romanov@nginx.com stream); 442423Smax.romanov@nginx.com 443423Smax.romanov@nginx.com if (cancelled) { 444423Smax.romanov@nginx.com nxt_debug(task, "stream #%uD: cancelled by router", stream); 445423Smax.romanov@nginx.com } 446423Smax.romanov@nginx.com 447423Smax.romanov@nginx.com for (b = msg_info->buf; b != NULL; b = next) { 448423Smax.romanov@nginx.com next = b->next; 449423Smax.romanov@nginx.com 450423Smax.romanov@nginx.com b->completion_handler = msg_info->completion_handler; 451423Smax.romanov@nginx.com 452423Smax.romanov@nginx.com if (b->is_port_mmap_sent) { 453423Smax.romanov@nginx.com b->is_port_mmap_sent = cancelled == 0; 454423Smax.romanov@nginx.com b->completion_handler(task, b, b->parent); 455423Smax.romanov@nginx.com } 456423Smax.romanov@nginx.com } 457423Smax.romanov@nginx.com 458423Smax.romanov@nginx.com msg_info->buf = NULL; 459423Smax.romanov@nginx.com 460423Smax.romanov@nginx.com return cancelled; 461423Smax.romanov@nginx.com } 462423Smax.romanov@nginx.com 463423Smax.romanov@nginx.com 464167Smax.romanov@nginx.com static void 465425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra); 466425Smax.romanov@nginx.com 467425Smax.romanov@nginx.com 468425Smax.romanov@nginx.com static void 469425Smax.romanov@nginx.com nxt_router_ra_update_peer_handler(nxt_task_t *task, void *obj, void *data) 470167Smax.romanov@nginx.com { 471425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 472425Smax.romanov@nginx.com 473425Smax.romanov@nginx.com ra = obj; 474425Smax.romanov@nginx.com 475425Smax.romanov@nginx.com nxt_router_ra_update_peer(task, ra); 476425Smax.romanov@nginx.com 477425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 478425Smax.romanov@nginx.com } 479425Smax.romanov@nginx.com 480425Smax.romanov@nginx.com 481425Smax.romanov@nginx.com static void 482425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra) 483425Smax.romanov@nginx.com { 484343Smax.romanov@nginx.com nxt_event_engine_t *engine; 485343Smax.romanov@nginx.com nxt_req_conn_link_t *rc; 486318Smax.romanov@nginx.com 487425Smax.romanov@nginx.com engine = ra->work.data; 488318Smax.romanov@nginx.com 489343Smax.romanov@nginx.com if (task->thread->engine != engine) { 490425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 491425Smax.romanov@nginx.com 492425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_update_peer_handler; 493318Smax.romanov@nginx.com ra->work.task = &engine->task; 494318Smax.romanov@nginx.com ra->work.next = NULL; 495318Smax.romanov@nginx.com 496425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post update peer to %p", 497318Smax.romanov@nginx.com ra->stream, engine); 498318Smax.romanov@nginx.com 499318Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 500318Smax.romanov@nginx.com 501318Smax.romanov@nginx.com return; 502318Smax.romanov@nginx.com } 503318Smax.romanov@nginx.com 504425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD update peer", ra->stream); 505425Smax.romanov@nginx.com 506425Smax.romanov@nginx.com rc = ra->rc; 507425Smax.romanov@nginx.com 508425Smax.romanov@nginx.com if (rc != NULL && ra->app_port != NULL) { 509425Smax.romanov@nginx.com nxt_port_rpc_ex_set_peer(task, engine->port, rc, ra->app_port->pid); 510425Smax.romanov@nginx.com } 511425Smax.romanov@nginx.com 512425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 513425Smax.romanov@nginx.com } 514425Smax.romanov@nginx.com 515425Smax.romanov@nginx.com 516425Smax.romanov@nginx.com static void 517425Smax.romanov@nginx.com nxt_router_ra_release(nxt_task_t *task, nxt_req_app_link_t *ra) 518425Smax.romanov@nginx.com { 519431Sigor@sysoev.ru nxt_mp_t *mp; 520431Sigor@sysoev.ru nxt_req_conn_link_t *rc; 521425Smax.romanov@nginx.com 522425Smax.romanov@nginx.com nxt_assert(task->thread->engine == ra->work.data); 523425Smax.romanov@nginx.com nxt_assert(ra->use_count == 0); 524425Smax.romanov@nginx.com 525343Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD release", ra->stream); 526343Smax.romanov@nginx.com 527343Smax.romanov@nginx.com rc = ra->rc; 528343Smax.romanov@nginx.com 529343Smax.romanov@nginx.com if (rc != NULL) { 530423Smax.romanov@nginx.com if (nxt_slow_path(ra->err_code != 0)) { 531431Sigor@sysoev.ru nxt_http_request_error(task, rc->ap->request, ra->err_code); 532423Smax.romanov@nginx.com 533423Smax.romanov@nginx.com } else { 534423Smax.romanov@nginx.com rc->app_port = ra->app_port; 535423Smax.romanov@nginx.com rc->msg_info = ra->msg_info; 536423Smax.romanov@nginx.com 537425Smax.romanov@nginx.com if (rc->app->timeout != 0) { 538431Sigor@sysoev.ru rc->ap->timer.handler = nxt_router_app_timeout; 539431Sigor@sysoev.ru nxt_timer_add(task->thread->engine, &rc->ap->timer, 540425Smax.romanov@nginx.com rc->app->timeout); 541425Smax.romanov@nginx.com } 542425Smax.romanov@nginx.com 543423Smax.romanov@nginx.com ra->app_port = NULL; 544423Smax.romanov@nginx.com ra->msg_info.buf = NULL; 545423Smax.romanov@nginx.com } 546343Smax.romanov@nginx.com 547343Smax.romanov@nginx.com rc->ra = NULL; 548343Smax.romanov@nginx.com ra->rc = NULL; 549343Smax.romanov@nginx.com } 550343Smax.romanov@nginx.com 551343Smax.romanov@nginx.com if (ra->app_port != NULL) { 552343Smax.romanov@nginx.com nxt_router_app_port_release(task, ra->app_port, 0, 1); 553343Smax.romanov@nginx.com 554343Smax.romanov@nginx.com ra->app_port = NULL; 555167Smax.romanov@nginx.com } 556167Smax.romanov@nginx.com 557423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &ra->msg_info, ra->stream); 558423Smax.romanov@nginx.com 559430Sigor@sysoev.ru mp = ra->mem_pool; 560430Sigor@sysoev.ru 561430Sigor@sysoev.ru if (mp != NULL) { 562430Sigor@sysoev.ru nxt_mp_free(mp, ra); 563430Sigor@sysoev.ru nxt_mp_release(mp); 564351Smax.romanov@nginx.com } 565167Smax.romanov@nginx.com } 566167Smax.romanov@nginx.com 567167Smax.romanov@nginx.com 568425Smax.romanov@nginx.com static void 569425Smax.romanov@nginx.com nxt_router_ra_release_handler(nxt_task_t *task, void *obj, void *data) 570425Smax.romanov@nginx.com { 571425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 572425Smax.romanov@nginx.com 573425Smax.romanov@nginx.com ra = obj; 574425Smax.romanov@nginx.com 575425Smax.romanov@nginx.com nxt_assert(ra->work.data == data); 576425Smax.romanov@nginx.com 577425Smax.romanov@nginx.com nxt_atomic_fetch_add(&ra->use_count, -1); 578425Smax.romanov@nginx.com 579425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 580425Smax.romanov@nginx.com } 581425Smax.romanov@nginx.com 582425Smax.romanov@nginx.com 583425Smax.romanov@nginx.com static void 584425Smax.romanov@nginx.com nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i) 585425Smax.romanov@nginx.com { 586425Smax.romanov@nginx.com int c; 587425Smax.romanov@nginx.com nxt_event_engine_t *engine; 588425Smax.romanov@nginx.com 589425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, i); 590425Smax.romanov@nginx.com 591425Smax.romanov@nginx.com if (i < 0 && c == -i) { 592425Smax.romanov@nginx.com engine = ra->work.data; 593425Smax.romanov@nginx.com 594425Smax.romanov@nginx.com if (task->thread->engine == engine) { 595425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 596425Smax.romanov@nginx.com 597425Smax.romanov@nginx.com return; 598425Smax.romanov@nginx.com } 599425Smax.romanov@nginx.com 600425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 601425Smax.romanov@nginx.com 602425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_release_handler; 603425Smax.romanov@nginx.com ra->work.task = &engine->task; 604425Smax.romanov@nginx.com ra->work.next = NULL; 605425Smax.romanov@nginx.com 606425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post release to %p", 607425Smax.romanov@nginx.com ra->stream, engine); 608425Smax.romanov@nginx.com 609425Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 610425Smax.romanov@nginx.com } 611425Smax.romanov@nginx.com } 612425Smax.romanov@nginx.com 613425Smax.romanov@nginx.com 614423Smax.romanov@nginx.com nxt_inline void 615423Smax.romanov@nginx.com nxt_router_ra_error(nxt_req_app_link_t *ra, int code, const char* str) 616345Smax.romanov@nginx.com { 617423Smax.romanov@nginx.com ra->app_port = NULL; 618423Smax.romanov@nginx.com ra->err_code = code; 619423Smax.romanov@nginx.com ra->err_str = str; 620345Smax.romanov@nginx.com } 621345Smax.romanov@nginx.com 622345Smax.romanov@nginx.com 623427Smax.romanov@nginx.com nxt_inline void 624427Smax.romanov@nginx.com nxt_router_ra_pending(nxt_task_t *task, nxt_app_t *app, nxt_req_app_link_t *ra) 625427Smax.romanov@nginx.com { 626427Smax.romanov@nginx.com nxt_queue_insert_tail(&ra->app_port->pending_requests, 627427Smax.romanov@nginx.com &ra->link_port_pending); 628427Smax.romanov@nginx.com nxt_queue_insert_tail(&app->pending, &ra->link_app_pending); 629427Smax.romanov@nginx.com 630427Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 631427Smax.romanov@nginx.com 632427Smax.romanov@nginx.com ra->res_time = nxt_thread_monotonic_time(task->thread) + app->res_timeout; 633427Smax.romanov@nginx.com 634427Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD enqueue to pending_requests", ra->stream); 635427Smax.romanov@nginx.com } 636427Smax.romanov@nginx.com 637427Smax.romanov@nginx.com 638425Smax.romanov@nginx.com nxt_inline nxt_bool_t 639425Smax.romanov@nginx.com nxt_queue_chk_remove(nxt_queue_link_t *lnk) 640425Smax.romanov@nginx.com { 641425Smax.romanov@nginx.com if (lnk->next != NULL) { 642425Smax.romanov@nginx.com nxt_queue_remove(lnk); 643425Smax.romanov@nginx.com 644425Smax.romanov@nginx.com lnk->next = NULL; 645425Smax.romanov@nginx.com 646425Smax.romanov@nginx.com return 1; 647425Smax.romanov@nginx.com } 648425Smax.romanov@nginx.com 649425Smax.romanov@nginx.com return 0; 650425Smax.romanov@nginx.com } 651425Smax.romanov@nginx.com 652425Smax.romanov@nginx.com 653343Smax.romanov@nginx.com nxt_inline void 654343Smax.romanov@nginx.com nxt_router_rc_unlink(nxt_task_t *task, nxt_req_conn_link_t *rc) 655343Smax.romanov@nginx.com { 656425Smax.romanov@nginx.com int ra_use_delta; 657343Smax.romanov@nginx.com nxt_req_app_link_t *ra; 658343Smax.romanov@nginx.com 659343Smax.romanov@nginx.com if (rc->app_port != NULL) { 660343Smax.romanov@nginx.com nxt_router_app_port_release(task, rc->app_port, 0, 1); 661343Smax.romanov@nginx.com 662343Smax.romanov@nginx.com rc->app_port = NULL; 663343Smax.romanov@nginx.com } 664343Smax.romanov@nginx.com 665423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &rc->msg_info, rc->stream); 666423Smax.romanov@nginx.com 667343Smax.romanov@nginx.com ra = rc->ra; 668343Smax.romanov@nginx.com 669343Smax.romanov@nginx.com if (ra != NULL) { 670343Smax.romanov@nginx.com rc->ra = NULL; 671343Smax.romanov@nginx.com ra->rc = NULL; 672343Smax.romanov@nginx.com 673425Smax.romanov@nginx.com ra_use_delta = 0; 674425Smax.romanov@nginx.com 675343Smax.romanov@nginx.com nxt_thread_mutex_lock(&rc->app->mutex); 676343Smax.romanov@nginx.com 677425Smax.romanov@nginx.com if (ra->link_app_requests.next == NULL 678427Smax.romanov@nginx.com && ra->link_port_pending.next == NULL 679427Smax.romanov@nginx.com && ra->link_app_pending.next == NULL) 680425Smax.romanov@nginx.com { 681425Smax.romanov@nginx.com ra = NULL; 682343Smax.romanov@nginx.com 683343Smax.romanov@nginx.com } else { 684425Smax.romanov@nginx.com ra_use_delta -= nxt_queue_chk_remove(&ra->link_app_requests); 685425Smax.romanov@nginx.com ra_use_delta -= nxt_queue_chk_remove(&ra->link_port_pending); 686427Smax.romanov@nginx.com nxt_queue_chk_remove(&ra->link_app_pending); 687343Smax.romanov@nginx.com } 688343Smax.romanov@nginx.com 689343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&rc->app->mutex); 690425Smax.romanov@nginx.com 691425Smax.romanov@nginx.com if (ra != NULL) { 692425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, ra_use_delta); 693425Smax.romanov@nginx.com } 694343Smax.romanov@nginx.com } 695343Smax.romanov@nginx.com 696343Smax.romanov@nginx.com if (rc->app != NULL) { 697343Smax.romanov@nginx.com nxt_router_app_use(task, rc->app, -1); 698343Smax.romanov@nginx.com 699343Smax.romanov@nginx.com rc->app = NULL; 700343Smax.romanov@nginx.com } 701343Smax.romanov@nginx.com 702346Smax.romanov@nginx.com if (rc->ap != NULL) { 703346Smax.romanov@nginx.com nxt_app_http_req_done(task, rc->ap); 704346Smax.romanov@nginx.com 705346Smax.romanov@nginx.com rc->ap = NULL; 706346Smax.romanov@nginx.com } 707343Smax.romanov@nginx.com } 708343Smax.romanov@nginx.com 709343Smax.romanov@nginx.com 710141Smax.romanov@nginx.com void 711141Smax.romanov@nginx.com nxt_router_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) 712141Smax.romanov@nginx.com { 713141Smax.romanov@nginx.com nxt_port_new_port_handler(task, msg); 714141Smax.romanov@nginx.com 715192Smax.romanov@nginx.com if (msg->port_msg.stream == 0) { 716141Smax.romanov@nginx.com return; 717141Smax.romanov@nginx.com } 718141Smax.romanov@nginx.com 719426Smax.romanov@nginx.com if (msg->u.new_port == NULL 720426Smax.romanov@nginx.com || msg->u.new_port->type != NXT_PROCESS_WORKER) 721347Smax.romanov@nginx.com { 722192Smax.romanov@nginx.com msg->port_msg.type = _NXT_PORT_MSG_RPC_ERROR; 723141Smax.romanov@nginx.com } 724192Smax.romanov@nginx.com 725192Smax.romanov@nginx.com nxt_port_rpc_handler(task, msg); 726141Smax.romanov@nginx.com } 727141Smax.romanov@nginx.com 728141Smax.romanov@nginx.com 729139Sigor@sysoev.ru void 730139Sigor@sysoev.ru nxt_router_conf_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) 731115Sigor@sysoev.ru { 732198Sigor@sysoev.ru nxt_int_t ret; 733139Sigor@sysoev.ru nxt_buf_t *b; 734139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf; 735139Sigor@sysoev.ru 736139Sigor@sysoev.ru tmcf = nxt_router_temp_conf(task); 737139Sigor@sysoev.ru if (nxt_slow_path(tmcf == NULL)) { 738139Sigor@sysoev.ru return; 73953Sigor@sysoev.ru } 74053Sigor@sysoev.ru 741494Spluknet@nginx.com nxt_debug(task, "nxt_router_conf_data_handler(%O): %*s", 742423Smax.romanov@nginx.com nxt_buf_used_size(msg->buf), 743493Spluknet@nginx.com (size_t) nxt_buf_used_size(msg->buf), msg->buf->mem.pos); 744423Smax.romanov@nginx.com 745352Smax.romanov@nginx.com b = nxt_buf_chk_make_plain(tmcf->conf->mem_pool, msg->buf, msg->size); 746352Smax.romanov@nginx.com 747352Smax.romanov@nginx.com nxt_assert(b != NULL); 748352Smax.romanov@nginx.com 749139Sigor@sysoev.ru tmcf->conf->router = nxt_router; 750139Sigor@sysoev.ru tmcf->stream = msg->port_msg.stream; 751139Sigor@sysoev.ru tmcf->port = nxt_runtime_port_find(task->thread->runtime, 752198Sigor@sysoev.ru msg->port_msg.pid, 753198Sigor@sysoev.ru msg->port_msg.reply_port); 754198Sigor@sysoev.ru 755198Sigor@sysoev.ru ret = nxt_router_conf_create(task, tmcf, b->mem.pos, b->mem.free); 756198Sigor@sysoev.ru 757198Sigor@sysoev.ru if (nxt_fast_path(ret == NXT_OK)) { 758198Sigor@sysoev.ru nxt_router_conf_apply(task, tmcf, NULL); 759198Sigor@sysoev.ru 760198Sigor@sysoev.ru } else { 761198Sigor@sysoev.ru nxt_router_conf_error(task, tmcf); 762139Sigor@sysoev.ru } 76353Sigor@sysoev.ru } 76453Sigor@sysoev.ru 76553Sigor@sysoev.ru 766347Smax.romanov@nginx.com static void 767507Smax.romanov@nginx.com nxt_router_app_process_remove_pid(nxt_task_t *task, nxt_port_t *port, 768507Smax.romanov@nginx.com void *data) 769347Smax.romanov@nginx.com { 770347Smax.romanov@nginx.com union { 771347Smax.romanov@nginx.com nxt_pid_t removed_pid; 772347Smax.romanov@nginx.com void *data; 773347Smax.romanov@nginx.com } u; 774347Smax.romanov@nginx.com 775347Smax.romanov@nginx.com u.data = data; 776347Smax.romanov@nginx.com 777347Smax.romanov@nginx.com nxt_port_rpc_remove_peer(task, port, u.removed_pid); 778347Smax.romanov@nginx.com } 779347Smax.romanov@nginx.com 780347Smax.romanov@nginx.com 781192Smax.romanov@nginx.com void 782192Smax.romanov@nginx.com nxt_router_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) 783192Smax.romanov@nginx.com { 784347Smax.romanov@nginx.com nxt_event_engine_t *engine; 785318Smax.romanov@nginx.com 786192Smax.romanov@nginx.com nxt_port_remove_pid_handler(task, msg); 787192Smax.romanov@nginx.com 788192Smax.romanov@nginx.com if (msg->port_msg.stream == 0) { 789192Smax.romanov@nginx.com return; 790192Smax.romanov@nginx.com } 791192Smax.romanov@nginx.com 792318Smax.romanov@nginx.com nxt_queue_each(engine, &nxt_router->engines, nxt_event_engine_t, link0) 793318Smax.romanov@nginx.com { 794507Smax.romanov@nginx.com nxt_port_post(task, engine->port, nxt_router_app_process_remove_pid, 795