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 { 120538Svbart@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); 126538Svbart@nginx.com #else 127538Svbart@nginx.com (void) nxt_atomic_fetch_add(&ra->use_count, -1); 128538Svbart@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 211*630Svbart@nginx.com static void nxt_router_access_log_writer(nxt_task_t *task, 212*630Svbart@nginx.com nxt_http_request_t *r, nxt_router_access_log_t *access_log); 213*630Svbart@nginx.com static u_char *nxt_router_access_log_date(u_char *buf, nxt_realtime_t *now, 214*630Svbart@nginx.com struct tm *tm, size_t size, const char *format); 215*630Svbart@nginx.com static void nxt_router_access_log_open(nxt_task_t *task, 216*630Svbart@nginx.com nxt_router_temp_conf_t *tmcf); 217*630Svbart@nginx.com static void nxt_router_access_log_ready(nxt_task_t *task, 218*630Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 219*630Svbart@nginx.com static void nxt_router_access_log_error(nxt_task_t *task, 220*630Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 221*630Svbart@nginx.com static void nxt_router_access_log_release(nxt_task_t *task, 222*630Svbart@nginx.com nxt_thread_spinlock_t *lock, nxt_router_access_log_t *access_log); 223*630Svbart@nginx.com 224343Smax.romanov@nginx.com static void nxt_router_app_port_ready(nxt_task_t *task, 225343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 226343Smax.romanov@nginx.com static void nxt_router_app_port_error(nxt_task_t *task, 227343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 228343Smax.romanov@nginx.com 229507Smax.romanov@nginx.com static void nxt_router_app_quit(nxt_task_t *task, nxt_app_t *app); 230343Smax.romanov@nginx.com static void nxt_router_app_port_release(nxt_task_t *task, nxt_port_t *port, 231343Smax.romanov@nginx.com uint32_t request_failed, uint32_t got_response); 232427Smax.romanov@nginx.com static nxt_int_t nxt_router_app_port(nxt_task_t *task, nxt_app_t *app, 233427Smax.romanov@nginx.com nxt_req_app_link_t *ra); 234141Smax.romanov@nginx.com 235425Smax.romanov@nginx.com static void nxt_router_app_prepare_request(nxt_task_t *task, 236343Smax.romanov@nginx.com nxt_req_app_link_t *ra); 237216Sigor@sysoev.ru static nxt_int_t nxt_python_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 238216Sigor@sysoev.ru nxt_app_wmsg_t *wmsg); 239216Sigor@sysoev.ru static nxt_int_t nxt_php_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 240216Sigor@sysoev.ru nxt_app_wmsg_t *wmsg); 241216Sigor@sysoev.ru static nxt_int_t nxt_go_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 242216Sigor@sysoev.ru nxt_app_wmsg_t *wmsg); 243510Salexander.borisov@nginx.com static nxt_int_t nxt_perl_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 244510Salexander.borisov@nginx.com nxt_app_wmsg_t *wmsg); 245584Salexander.borisov@nginx.com static nxt_int_t nxt_ruby_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 246584Salexander.borisov@nginx.com nxt_app_wmsg_t *wmsg); 247510Salexander.borisov@nginx.com 24853Sigor@sysoev.ru static void nxt_router_conn_free(nxt_task_t *task, void *obj, void *data); 249318Smax.romanov@nginx.com static void nxt_router_app_timeout(nxt_task_t *task, void *obj, void *data); 250507Smax.romanov@nginx.com static void nxt_router_adjust_idle_timer(nxt_task_t *task, void *obj, 251507Smax.romanov@nginx.com void *data); 252507Smax.romanov@nginx.com static void nxt_router_app_idle_timeout(nxt_task_t *task, void *obj, 253507Smax.romanov@nginx.com void *data); 254507Smax.romanov@nginx.com static void nxt_router_app_release_handler(nxt_task_t *task, void *obj, 255507Smax.romanov@nginx.com void *data); 256431Sigor@sysoev.ru 257431Sigor@sysoev.ru static const nxt_http_request_state_t nxt_http_request_send_state; 258431Sigor@sysoev.ru static void nxt_http_request_send_body(nxt_task_t *task, void *obj, void *data); 259141Smax.romanov@nginx.com 260119Smax.romanov@nginx.com static nxt_router_t *nxt_router; 26120Sigor@sysoev.ru 262216Sigor@sysoev.ru 263216Sigor@sysoev.ru static nxt_app_prepare_msg_t nxt_app_prepare_msg[] = { 264216Sigor@sysoev.ru nxt_python_prepare_msg, 265216Sigor@sysoev.ru nxt_php_prepare_msg, 266216Sigor@sysoev.ru nxt_go_prepare_msg, 267510Salexander.borisov@nginx.com nxt_perl_prepare_msg, 268584Salexander.borisov@nginx.com nxt_ruby_prepare_msg, 269216Sigor@sysoev.ru }; 270216Sigor@sysoev.ru 271216Sigor@sysoev.ru 27220Sigor@sysoev.ru nxt_int_t 273141Smax.romanov@nginx.com nxt_router_start(nxt_task_t *task, void *data) 27420Sigor@sysoev.ru { 275141Smax.romanov@nginx.com nxt_int_t ret; 276141Smax.romanov@nginx.com nxt_router_t *router; 277141Smax.romanov@nginx.com nxt_runtime_t *rt; 278141Smax.romanov@nginx.com 279141Smax.romanov@nginx.com rt = task->thread->runtime; 28053Sigor@sysoev.ru 281431Sigor@sysoev.ru ret = nxt_http_init(task, rt); 28288Smax.romanov@nginx.com if (nxt_slow_path(ret != NXT_OK)) { 28388Smax.romanov@nginx.com return ret; 28488Smax.romanov@nginx.com } 28588Smax.romanov@nginx.com 28653Sigor@sysoev.ru router = nxt_zalloc(sizeof(nxt_router_t)); 28753Sigor@sysoev.ru if (nxt_slow_path(router == NULL)) { 28853Sigor@sysoev.ru return NXT_ERROR; 28953Sigor@sysoev.ru } 29053Sigor@sysoev.ru 29153Sigor@sysoev.ru nxt_queue_init(&router->engines); 29253Sigor@sysoev.ru nxt_queue_init(&router->sockets); 293133Sigor@sysoev.ru nxt_queue_init(&router->apps); 29453Sigor@sysoev.ru 295119Smax.romanov@nginx.com nxt_router = router; 296119Smax.romanov@nginx.com 297115Sigor@sysoev.ru return NXT_OK; 298115Sigor@sysoev.ru } 299115Sigor@sysoev.ru 300115Sigor@sysoev.ru 301343Smax.romanov@nginx.com static void 302507Smax.romanov@nginx.com nxt_router_start_app_process_handler(nxt_task_t *task, nxt_port_t *port, 303507Smax.romanov@nginx.com void *data) 304167Smax.romanov@nginx.com { 305343Smax.romanov@nginx.com size_t size; 306343Smax.romanov@nginx.com uint32_t stream; 307430Sigor@sysoev.ru nxt_mp_t *mp; 308343Smax.romanov@nginx.com nxt_app_t *app; 309343Smax.romanov@nginx.com nxt_buf_t *b; 310343Smax.romanov@nginx.com nxt_port_t *main_port; 311343Smax.romanov@nginx.com nxt_runtime_t *rt; 312343Smax.romanov@nginx.com 313343Smax.romanov@nginx.com app = data; 314167Smax.romanov@nginx.com 315167Smax.romanov@nginx.com rt = task->thread->runtime; 316240Sigor@sysoev.ru main_port = rt->port_by_type[NXT_PROCESS_MAIN]; 317167Smax.romanov@nginx.com 318507Smax.romanov@nginx.com nxt_debug(task, "app '%V' %p start process", &app->name, app); 319343Smax.romanov@nginx.com 320343Smax.romanov@nginx.com size = app->name.length + 1 + app->conf.length; 321343Smax.romanov@nginx.com 322343Smax.romanov@nginx.com b = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool, size); 323343Smax.romanov@nginx.com 324343Smax.romanov@nginx.com if (nxt_slow_path(b == NULL)) { 325343Smax.romanov@nginx.com goto failed; 326167Smax.romanov@nginx.com } 327167Smax.romanov@nginx.com 328343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->name); 329343Smax.romanov@nginx.com *b->mem.free++ = '\0'; 330343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->conf); 331343Smax.romanov@nginx.com 332343Smax.romanov@nginx.com stream = nxt_port_rpc_register_handler(task, port, 333343Smax.romanov@nginx.com nxt_router_app_port_ready, 334343Smax.romanov@nginx.com nxt_router_app_port_error, 335343Smax.romanov@nginx.com -1, app); 336343Smax.romanov@nginx.com 337343Smax.romanov@nginx.com if (nxt_slow_path(stream == 0)) { 338430Sigor@sysoev.ru mp = b->data; 339430Sigor@sysoev.ru nxt_mp_free(mp, b); 340430Sigor@sysoev.ru nxt_mp_release(mp); 341343Smax.romanov@nginx.com 342343Smax.romanov@nginx.com goto failed; 343343Smax.romanov@nginx.com } 344343Smax.romanov@nginx.com 345343Smax.romanov@nginx.com nxt_port_socket_write(task, main_port, NXT_PORT_MSG_START_WORKER, -1, 346343Smax.romanov@nginx.com stream, port->id, b); 347343Smax.romanov@nginx.com 348343Smax.romanov@nginx.com return; 349343Smax.romanov@nginx.com 350343Smax.romanov@nginx.com failed: 351343Smax.romanov@nginx.com 352343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 353343Smax.romanov@nginx.com 354507Smax.romanov@nginx.com app->pending_processes--; 355343Smax.romanov@nginx.com 356343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 357343Smax.romanov@nginx.com 358343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 359167Smax.romanov@nginx.com } 360167Smax.romanov@nginx.com 361167Smax.romanov@nginx.com 362343Smax.romanov@nginx.com static nxt_int_t 363507Smax.romanov@nginx.com nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app) 364141Smax.romanov@nginx.com { 365343Smax.romanov@nginx.com nxt_int_t res; 366343Smax.romanov@nginx.com nxt_port_t *router_port; 367343Smax.romanov@nginx.com nxt_runtime_t *rt; 368343Smax.romanov@nginx.com 369343Smax.romanov@nginx.com rt = task->thread->runtime; 370343Smax.romanov@nginx.com router_port = rt->port_by_type[NXT_PROCESS_ROUTER]; 371343Smax.romanov@nginx.com 372343Smax.romanov@nginx.com nxt_router_app_use(task, app, 1); 373343Smax.romanov@nginx.com 374507Smax.romanov@nginx.com res = nxt_port_post(task, router_port, nxt_router_start_app_process_handler, 375343Smax.romanov@nginx.com app); 376343Smax.romanov@nginx.com 377343Smax.romanov@nginx.com if (res == NXT_OK) { 378343Smax.romanov@nginx.com return res; 379318Smax.romanov@nginx.com } 380318Smax.romanov@nginx.com 381343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 382343Smax.romanov@nginx.com 383507Smax.romanov@nginx.com app->pending_processes--; 384343Smax.romanov@nginx.com 385343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 386343Smax.romanov@nginx.com 387343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 388343Smax.romanov@nginx.com 389343Smax.romanov@nginx.com return NXT_ERROR; 390318Smax.romanov@nginx.com } 391318Smax.romanov@nginx.com 392318Smax.romanov@nginx.com 393351Smax.romanov@nginx.com nxt_inline void 394351Smax.romanov@nginx.com nxt_router_ra_init(nxt_task_t *task, nxt_req_app_link_t *ra, 395351Smax.romanov@nginx.com nxt_req_conn_link_t *rc) 396167Smax.romanov@nginx.com { 397318Smax.romanov@nginx.com nxt_event_engine_t *engine; 398351Smax.romanov@nginx.com 399318Smax.romanov@nginx.com engine = task->thread->engine; 400167Smax.romanov@nginx.com 401167Smax.romanov@nginx.com nxt_memzero(ra, sizeof(nxt_req_app_link_t)); 402167Smax.romanov@nginx.com 403318Smax.romanov@nginx.com ra->stream = rc->stream; 404425Smax.romanov@nginx.com ra->use_count = 1; 405167Smax.romanov@nginx.com ra->rc = rc; 406318Smax.romanov@nginx.com rc->ra = ra; 407318Smax.romanov@nginx.com ra->reply_port = engine->port; 408351Smax.romanov@nginx.com ra->ap = rc->ap; 409167Smax.romanov@nginx.com 410167Smax.romanov@nginx.com ra->work.handler = NULL; 411318Smax.romanov@nginx.com ra->work.task = &engine->task; 412167Smax.romanov@nginx.com ra->work.obj = ra; 413318Smax.romanov@nginx.com ra->work.data = engine; 414351Smax.romanov@nginx.com } 415351Smax.romanov@nginx.com 416351Smax.romanov@nginx.com 417351Smax.romanov@nginx.com nxt_inline nxt_req_app_link_t * 418351Smax.romanov@nginx.com nxt_router_ra_create(nxt_task_t *task, nxt_req_app_link_t *ra_src) 419351Smax.romanov@nginx.com { 420351Smax.romanov@nginx.com nxt_mp_t *mp; 421351Smax.romanov@nginx.com nxt_req_app_link_t *ra; 422351Smax.romanov@nginx.com 423425Smax.romanov@nginx.com if (ra_src->mem_pool != NULL) { 424425Smax.romanov@nginx.com return ra_src; 425425Smax.romanov@nginx.com } 426425Smax.romanov@nginx.com 427351Smax.romanov@nginx.com mp = ra_src->ap->mem_pool; 428351Smax.romanov@nginx.com 429430Sigor@sysoev.ru ra = nxt_mp_alloc(mp, sizeof(nxt_req_app_link_t)); 430351Smax.romanov@nginx.com 431351Smax.romanov@nginx.com if (nxt_slow_path(ra == NULL)) { 432351Smax.romanov@nginx.com 433351Smax.romanov@nginx.com ra_src->rc->ra = NULL; 434351Smax.romanov@nginx.com ra_src->rc = NULL; 435351Smax.romanov@nginx.com 436351Smax.romanov@nginx.com return NULL; 437351Smax.romanov@nginx.com } 438351Smax.romanov@nginx.com 439430Sigor@sysoev.ru nxt_mp_retain(mp); 440430Sigor@sysoev.ru 441351Smax.romanov@nginx.com nxt_router_ra_init(task, ra, ra_src->rc); 442351Smax.romanov@nginx.com 443351Smax.romanov@nginx.com ra->mem_pool = mp; 444167Smax.romanov@nginx.com 445167Smax.romanov@nginx.com return ra; 446167Smax.romanov@nginx.com } 447167Smax.romanov@nginx.com 448167Smax.romanov@nginx.com 449423Smax.romanov@nginx.com nxt_inline nxt_bool_t 450423Smax.romanov@nginx.com nxt_router_msg_cancel(nxt_task_t *task, nxt_msg_info_t *msg_info, 451423Smax.romanov@nginx.com uint32_t stream) 452423Smax.romanov@nginx.com { 453423Smax.romanov@nginx.com nxt_buf_t *b, *next; 454423Smax.romanov@nginx.com nxt_bool_t cancelled; 455423Smax.romanov@nginx.com 456423Smax.romanov@nginx.com if (msg_info->buf == NULL) { 457423Smax.romanov@nginx.com return 0; 458423Smax.romanov@nginx.com } 459423Smax.romanov@nginx.com 460423Smax.romanov@nginx.com cancelled = nxt_port_mmap_tracking_cancel(task, &msg_info->tracking, 461423Smax.romanov@nginx.com stream); 462423Smax.romanov@nginx.com 463423Smax.romanov@nginx.com if (cancelled) { 464423Smax.romanov@nginx.com nxt_debug(task, "stream #%uD: cancelled by router", stream); 465423Smax.romanov@nginx.com } 466423Smax.romanov@nginx.com 467423Smax.romanov@nginx.com for (b = msg_info->buf; b != NULL; b = next) { 468423Smax.romanov@nginx.com next = b->next; 469423Smax.romanov@nginx.com 470423Smax.romanov@nginx.com b->completion_handler = msg_info->completion_handler; 471423Smax.romanov@nginx.com 472423Smax.romanov@nginx.com if (b->is_port_mmap_sent) { 473423Smax.romanov@nginx.com b->is_port_mmap_sent = cancelled == 0; 474423Smax.romanov@nginx.com b->completion_handler(task, b, b->parent); 475423Smax.romanov@nginx.com } 476423Smax.romanov@nginx.com } 477423Smax.romanov@nginx.com 478423Smax.romanov@nginx.com msg_info->buf = NULL; 479423Smax.romanov@nginx.com 480423Smax.romanov@nginx.com return cancelled; 481423Smax.romanov@nginx.com } 482423Smax.romanov@nginx.com 483423Smax.romanov@nginx.com 484167Smax.romanov@nginx.com static void 485425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra); 486425Smax.romanov@nginx.com 487425Smax.romanov@nginx.com 488425Smax.romanov@nginx.com static void 489425Smax.romanov@nginx.com nxt_router_ra_update_peer_handler(nxt_task_t *task, void *obj, void *data) 490167Smax.romanov@nginx.com { 491425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 492425Smax.romanov@nginx.com 493425Smax.romanov@nginx.com ra = obj; 494425Smax.romanov@nginx.com 495425Smax.romanov@nginx.com nxt_router_ra_update_peer(task, ra); 496425Smax.romanov@nginx.com 497425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 498425Smax.romanov@nginx.com } 499425Smax.romanov@nginx.com 500425Smax.romanov@nginx.com 501425Smax.romanov@nginx.com static void 502425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra) 503425Smax.romanov@nginx.com { 504343Smax.romanov@nginx.com nxt_event_engine_t *engine; 505343Smax.romanov@nginx.com nxt_req_conn_link_t *rc; 506318Smax.romanov@nginx.com 507425Smax.romanov@nginx.com engine = ra->work.data; 508318Smax.romanov@nginx.com 509343Smax.romanov@nginx.com if (task->thread->engine != engine) { 510425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 511425Smax.romanov@nginx.com 512425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_update_peer_handler; 513318Smax.romanov@nginx.com ra->work.task = &engine->task; 514318Smax.romanov@nginx.com ra->work.next = NULL; 515318Smax.romanov@nginx.com 516425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post update peer to %p", 517318Smax.romanov@nginx.com ra->stream, engine); 518318Smax.romanov@nginx.com 519318Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 520318Smax.romanov@nginx.com 521318Smax.romanov@nginx.com return; 522318Smax.romanov@nginx.com } 523318Smax.romanov@nginx.com 524425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD update peer", ra->stream); 525425Smax.romanov@nginx.com 526425Smax.romanov@nginx.com rc = ra->rc; 527425Smax.romanov@nginx.com 528425Smax.romanov@nginx.com if (rc != NULL && ra->app_port != NULL) { 529425Smax.romanov@nginx.com nxt_port_rpc_ex_set_peer(task, engine->port, rc, ra->app_port->pid); 530425Smax.romanov@nginx.com } 531425Smax.romanov@nginx.com 532425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 533425Smax.romanov@nginx.com } 534425Smax.romanov@nginx.com 535425Smax.romanov@nginx.com 536425Smax.romanov@nginx.com static void 537425Smax.romanov@nginx.com nxt_router_ra_release(nxt_task_t *task, nxt_req_app_link_t *ra) 538425Smax.romanov@nginx.com { 539431Sigor@sysoev.ru nxt_mp_t *mp; 540431Sigor@sysoev.ru nxt_req_conn_link_t *rc; 541425Smax.romanov@nginx.com 542425Smax.romanov@nginx.com nxt_assert(task->thread->engine == ra->work.data); 543425Smax.romanov@nginx.com nxt_assert(ra->use_count == 0); 544425Smax.romanov@nginx.com 545343Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD release", ra->stream); 546343Smax.romanov@nginx.com 547343Smax.romanov@nginx.com rc = ra->rc; 548343Smax.romanov@nginx.com 549343Smax.romanov@nginx.com if (rc != NULL) { 550423Smax.romanov@nginx.com if (nxt_slow_path(ra->err_code != 0)) { 551431Sigor@sysoev.ru nxt_http_request_error(task, rc->ap->request, ra->err_code); 552423Smax.romanov@nginx.com 553423Smax.romanov@nginx.com } else { 554423Smax.romanov@nginx.com rc->app_port = ra->app_port; 555423Smax.romanov@nginx.com rc->msg_info = ra->msg_info; 556423Smax.romanov@nginx.com 557425Smax.romanov@nginx.com if (rc->app->timeout != 0) { 558431Sigor@sysoev.ru rc->ap->timer.handler = nxt_router_app_timeout; 559615Smax.romanov@nginx.com rc->ap->timer_data = rc; 560431Sigor@sysoev.ru nxt_timer_add(task->thread->engine, &rc->ap->timer, 561425Smax.romanov@nginx.com rc->app->timeout); 562425Smax.romanov@nginx.com } 563425Smax.romanov@nginx.com 564423Smax.romanov@nginx.com ra->app_port = NULL; 565423Smax.romanov@nginx.com ra->msg_info.buf = NULL; 566423Smax.romanov@nginx.com } 567343Smax.romanov@nginx.com 568343Smax.romanov@nginx.com rc->ra = NULL; 569343Smax.romanov@nginx.com ra->rc = NULL; 570343Smax.romanov@nginx.com } 571343Smax.romanov@nginx.com 572343Smax.romanov@nginx.com if (ra->app_port != NULL) { 573343Smax.romanov@nginx.com nxt_router_app_port_release(task, ra->app_port, 0, 1); 574343Smax.romanov@nginx.com 575343Smax.romanov@nginx.com ra->app_port = NULL; 576167Smax.romanov@nginx.com } 577167Smax.romanov@nginx.com 578423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &ra->msg_info, ra->stream); 579423Smax.romanov@nginx.com 580430Sigor@sysoev.ru mp = ra->mem_pool; 581430Sigor@sysoev.ru 582430Sigor@sysoev.ru if (mp != NULL) { 583430Sigor@sysoev.ru nxt_mp_free(mp, ra); 584430Sigor@sysoev.ru nxt_mp_release(mp); 585351Smax.romanov@nginx.com } 586167Smax.romanov@nginx.com } 587167Smax.romanov@nginx.com 588167Smax.romanov@nginx.com 589425Smax.romanov@nginx.com static void 590425Smax.romanov@nginx.com nxt_router_ra_release_handler(nxt_task_t *task, void *obj, void *data) 591425Smax.romanov@nginx.com { 592425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 593425Smax.romanov@nginx.com 594425Smax.romanov@nginx.com ra = obj; 595425Smax.romanov@nginx.com 596425Smax.romanov@nginx.com nxt_assert(ra->work.data == data); 597425Smax.romanov@nginx.com 598425Smax.romanov@nginx.com nxt_atomic_fetch_add(&ra->use_count, -1); 599425Smax.romanov@nginx.com 600425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 601425Smax.romanov@nginx.com } 602425Smax.romanov@nginx.com 603425Smax.romanov@nginx.com 604425Smax.romanov@nginx.com static void 605425Smax.romanov@nginx.com nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i) 606425Smax.romanov@nginx.com { 607425Smax.romanov@nginx.com int c; 608425Smax.romanov@nginx.com nxt_event_engine_t *engine; 609425Smax.romanov@nginx.com 610425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, i); 611425Smax.romanov@nginx.com 612425Smax.romanov@nginx.com if (i < 0 && c == -i) { 613425Smax.romanov@nginx.com engine = ra->work.data; 614425Smax.romanov@nginx.com 615425Smax.romanov@nginx.com if (task->thread->engine == engine) { 616425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 617425Smax.romanov@nginx.com 618425Smax.romanov@nginx.com return; 619425Smax.romanov@nginx.com } 620425Smax.romanov@nginx.com 621425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 622425Smax.romanov@nginx.com 623425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_release_handler; 624425Smax.romanov@nginx.com ra->work.task = &engine->task; 625425Smax.romanov@nginx.com ra->work.next = NULL; 626425Smax.romanov@nginx.com 627425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post release to %p", 628425Smax.romanov@nginx.com ra->stream, engine); 629425Smax.romanov@nginx.com 630425Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 631425Smax.romanov@nginx.com } 632425Smax.romanov@nginx.com } 633425Smax.romanov@nginx.com 634425Smax.romanov@nginx.com 635423Smax.romanov@nginx.com nxt_inline void 636521Szelenkov@nginx.com nxt_router_ra_error(nxt_req_app_link_t *ra, int code, const char *str) 637345Smax.romanov@nginx.com { 638423Smax.romanov@nginx.com ra->app_port = NULL; 639423Smax.romanov@nginx.com ra->err_code = code; 640423Smax.romanov@nginx.com ra->err_str = str; 641345Smax.romanov@nginx.com } 642345Smax.romanov@nginx.com 643345Smax.romanov@nginx.com 644427Smax.romanov@nginx.com nxt_inline void 645427Smax.romanov@nginx.com nxt_router_ra_pending(nxt_task_t *task, nxt_app_t *app, nxt_req_app_link_t *ra) 646427Smax.romanov@nginx.com { 647427Smax.romanov@nginx.com nxt_queue_insert_tail(&ra->app_port->pending_requests, 648427Smax.romanov@nginx.com &ra->link_port_pending); 649427Smax.romanov@nginx.com nxt_queue_insert_tail(&app->pending, &ra->link_app_pending); 650427Smax.romanov@nginx.com 651427Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 652427Smax.romanov@nginx.com 653427Smax.romanov@nginx.com ra->res_time = nxt_thread_monotonic_time(task->thread) + app->res_timeout; 654427Smax.romanov@nginx.com 655427Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD enqueue to pending_requests", ra->stream); 656427Smax.romanov@nginx.com } 657427Smax.romanov@nginx.com 658427Smax.romanov@nginx.com 659425Smax.romanov@nginx.com nxt_inline nxt_bool_t 660425Smax.romanov@nginx.com nxt_queue_chk_remove(nxt_queue_link_t *lnk) 661425Smax.romanov@nginx.com { 662425Smax.romanov@nginx.com if (lnk->next != NULL) { 663425Smax.romanov@nginx.com nxt_queue_remove(lnk); 664425Smax.romanov@nginx.com 665425Smax.romanov@nginx.com lnk->next = NULL; 666425Smax.romanov@nginx.com 667425Smax.romanov@nginx.com return 1; 668425Smax.romanov@nginx.com } 669425Smax.romanov@nginx.com 670425Smax.romanov@nginx.com return 0; 671425Smax.romanov@nginx.com } 672425Smax.romanov@nginx.com 673425Smax.romanov@nginx.com 674343Smax.romanov@nginx.com nxt_inline void 675343Smax.romanov@nginx.com nxt_router_rc_unlink(nxt_task_t *task, nxt_req_conn_link_t *rc) 676343Smax.romanov@nginx.com { 677425Smax.romanov@nginx.com int ra_use_delta; 678343Smax.romanov@nginx.com nxt_req_app_link_t *ra; 679343Smax.romanov@nginx.com 680343Smax.romanov@nginx.com if (rc->app_port != NULL) { 681343Smax.romanov@nginx.com nxt_router_app_port_release(task, rc->app_port, 0, 1); 682343Smax.romanov@nginx.com 683343Smax.romanov@nginx.com rc->app_port = NULL; 684343Smax.romanov@nginx.com } 685343Smax.romanov@nginx.com 686423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &rc->msg_info, rc->stream); 687423Smax.romanov@nginx.com 688343Smax.romanov@nginx.com ra = rc->ra; 689343Smax.romanov@nginx.com 690343Smax.romanov@nginx.com if (ra != NULL) { 691343Smax.romanov@nginx.com rc->ra = NULL; 692343Smax.romanov@nginx.com ra->rc = NULL; 693343Smax.romanov@nginx.com 694425Smax.romanov@nginx.com ra_use_delta = 0; 695425Smax.romanov@nginx.com 696343Smax.romanov@nginx.com nxt_thread_mutex_lock(&rc->app->mutex); 697343Smax.romanov@nginx.com 698425Smax.romanov@nginx.com if (ra->link_app_requests.next == NULL 699427Smax.romanov@nginx.com && ra->link_port_pending.next == NULL 700427Smax.romanov@nginx.com && ra->link_app_pending.next == NULL) 701425Smax.romanov@nginx.com { 702425Smax.romanov@nginx.com ra = NULL; 703343Smax.romanov@nginx.com 704343Smax.romanov@nginx.com } else { 705425Smax.romanov@nginx.com ra_use_delta -= nxt_queue_chk_remove(&ra->link_app_requests); 706425Smax.romanov@nginx.com ra_use_delta -= nxt_queue_chk_remove(&ra->link_port_pending); 707427Smax.romanov@nginx.com nxt_queue_chk_remove(&ra->link_app_pending); 708343Smax.romanov@nginx.com } 709343Smax.romanov@nginx.com 710343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&rc->app->mutex); 711425Smax.romanov@nginx.com 712425Smax.romanov@nginx.com if (ra != NULL) { 713425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, ra_use_delta); 714425Smax.romanov@nginx.com } 715343Smax.romanov@nginx.com } 716343Smax.romanov@nginx.com 717343Smax.romanov@nginx.com if (rc->app != NULL) { 718343Smax.romanov@nginx.com nxt_router_app_use(task, rc->app, -1); 719343Smax.romanov@nginx.com 720343Smax.romanov@nginx.com rc->app = NULL; 721343Smax.romanov@nginx.com } 722343Smax.romanov@nginx.com 723346Smax.romanov@nginx.com if (rc->ap != NULL) { 724615Smax.romanov@nginx.com rc->ap->timer_data = NULL; 725615Smax.romanov@nginx.com 726346Smax.romanov@nginx.com nxt_app_http_req_done(task, rc->ap); 727346Smax.romanov@nginx.com 728346Smax.romanov@nginx.com rc->ap = NULL; 729346Smax.romanov@nginx.com } 730343Smax.romanov@nginx.com } 731343Smax.romanov@nginx.com 732343Smax.romanov@nginx.com 733141Smax.romanov@nginx.com void 734141Smax.romanov@nginx.com nxt_router_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) 735141Smax.romanov@nginx.com { 736141Smax.romanov@nginx.com nxt_port_new_port_handler(task, msg); 737141Smax.romanov@nginx.com 738192Smax.romanov@nginx.com if (msg->port_msg.stream == 0) { 739141Smax.romanov@nginx.com return; 740141Smax.romanov@nginx.com } 741141Smax.romanov@nginx.com 742426Smax.romanov@nginx.com if (msg->u.new_port == NULL 743426Smax.romanov@nginx.com || msg->u.new_port->type != NXT_PROCESS_WORKER) 744347Smax.romanov@nginx.com { 745192Smax.romanov@nginx.com msg->port_msg.type = _NXT_PORT_MSG_RPC_ERROR; 746141Smax.romanov@nginx.com } 747192Smax.romanov@nginx.com 748192Smax.romanov@nginx.com nxt_port_rpc_handler(task, msg); 749141Smax.romanov@nginx.com } 750141Smax.romanov@nginx.com 751141Smax.romanov@nginx.com 752139Sigor@sysoev.ru void 753139Sigor@sysoev.ru nxt_router_conf_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) 754115Sigor@sysoev.ru { 755198Sigor@sysoev.ru nxt_int_t ret; 756139Sigor@sysoev.ru nxt_buf_t *b; 757139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf; 758139Sigor@sysoev.ru 759139Sigor@sysoev.ru tmcf = nxt_router_temp_conf(task); 760139Sigor@sysoev.ru if (nxt_slow_path(tmcf == NULL)) { 761139Sigor@sysoev.ru return; 76253Sigor@sysoev.ru } 76353Sigor@sysoev.ru 764494Spluknet@nginx.com nxt_debug(task, "nxt_router_conf_data_handler(%O): %*s", 765423Smax.romanov@nginx.com nxt_buf_used_size(msg->buf), 766493Spluknet@nginx.com (size_t) nxt_buf_used_size(msg->buf), msg->buf->mem.pos); 767423Smax.romanov@nginx.com 768591Sigor@sysoev.ru tmcf->router_conf->router = nxt_router; 769139Sigor@sysoev.ru tmcf->stream = msg->port_msg.stream; 770139Sigor@sysoev.ru tmcf->port = nxt_runtime_port_find(task->thread->runtime, 771198Sigor@sysoev.ru msg->port_msg.pid, 772198Sigor@sysoev.ru msg->port_msg.reply_port); 773198Sigor@sysoev.ru 774591Sigor@sysoev.ru b = nxt_buf_chk_make_plain(tmcf->router_conf->mem_pool, 775591Sigor@sysoev.ru msg->buf, msg->size); 776551Smax.romanov@nginx.com if (nxt_slow_path(b == NULL)) { 777551Smax.romanov@nginx.com nxt_router_conf_error(task, tmcf); 778551Smax.romanov@nginx.com 779551Smax.romanov@nginx.com return; 780551Smax.romanov@nginx.com } 781551Smax.romanov@nginx.com 782198Sigor@sysoev.ru ret = nxt_router_conf_create(task, tmcf, b->mem.pos, b->mem.free); 783198Sigor@sysoev.ru 784198Sigor@sysoev.ru if (nxt_fast_path(ret == NXT_OK)) { 785198Sigor@sysoev.ru nxt_router_conf_apply(task, tmcf, NULL); 786198Sigor@sysoev.ru 787198Sigor@sysoev.ru } else { 788198Sigor@sysoev.ru nxt_router_conf_error(task, tmcf); 789139Sigor@sysoev.ru } 79053Sigor@sysoev.ru } 79153Sigor@sysoev.ru 79253Sigor@sysoev.ru 793347Smax.romanov@nginx.com static void 794507Smax.romanov@nginx.com nxt_router_app_process_remove_pid(nxt_task_t *task, nxt_port_t *port, 795507Smax.romanov@nginx.com void *data) 796347Smax.romanov@nginx.com { 797347Smax.romanov@nginx.com union { 798347Smax.romanov@nginx.com nxt_pid_t removed_pid; 799