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> 11*743Smax.romanov@nginx.com #include <nxt_port_memory_int.h> 12*743Smax.romanov@nginx.com #include <nxt_unit_request.h> 13*743Smax.romanov@nginx.com #include <nxt_unit_response.h> 1420Sigor@sysoev.ru 1520Sigor@sysoev.ru 16115Sigor@sysoev.ru typedef struct { 17318Smax.romanov@nginx.com nxt_str_t type; 18507Smax.romanov@nginx.com uint32_t processes; 19507Smax.romanov@nginx.com uint32_t max_processes; 20507Smax.romanov@nginx.com uint32_t spare_processes; 21318Smax.romanov@nginx.com nxt_msec_t timeout; 22427Smax.romanov@nginx.com nxt_msec_t res_timeout; 23507Smax.romanov@nginx.com nxt_msec_t idle_timeout; 24318Smax.romanov@nginx.com uint32_t requests; 25318Smax.romanov@nginx.com nxt_conf_value_t *limits_value; 26507Smax.romanov@nginx.com nxt_conf_value_t *processes_value; 27133Sigor@sysoev.ru } nxt_router_app_conf_t; 28133Sigor@sysoev.ru 29133Sigor@sysoev.ru 30133Sigor@sysoev.ru typedef struct { 31133Sigor@sysoev.ru nxt_str_t application; 32115Sigor@sysoev.ru } nxt_router_listener_conf_t; 33115Sigor@sysoev.ru 34115Sigor@sysoev.ru 35423Smax.romanov@nginx.com typedef struct nxt_msg_info_s { 36423Smax.romanov@nginx.com nxt_buf_t *buf; 37423Smax.romanov@nginx.com nxt_port_mmap_tracking_t tracking; 38423Smax.romanov@nginx.com nxt_work_handler_t completion_handler; 39423Smax.romanov@nginx.com } nxt_msg_info_t; 40423Smax.romanov@nginx.com 41423Smax.romanov@nginx.com 42167Smax.romanov@nginx.com typedef struct nxt_req_app_link_s nxt_req_app_link_t; 43141Smax.romanov@nginx.com 44141Smax.romanov@nginx.com 45318Smax.romanov@nginx.com typedef struct { 46431Sigor@sysoev.ru uint32_t stream; 47431Sigor@sysoev.ru nxt_app_t *app; 48431Sigor@sysoev.ru nxt_port_t *app_port; 49431Sigor@sysoev.ru nxt_app_parse_ctx_t *ap; 50431Sigor@sysoev.ru nxt_msg_info_t msg_info; 51431Sigor@sysoev.ru nxt_req_app_link_t *ra; 52431Sigor@sysoev.ru 53431Sigor@sysoev.ru nxt_queue_link_t link; /* for nxt_conn_t.requests */ 54318Smax.romanov@nginx.com } nxt_req_conn_link_t; 55318Smax.romanov@nginx.com 56318Smax.romanov@nginx.com 57167Smax.romanov@nginx.com struct nxt_req_app_link_s { 58318Smax.romanov@nginx.com uint32_t stream; 59425Smax.romanov@nginx.com nxt_atomic_t use_count; 60167Smax.romanov@nginx.com nxt_port_t *app_port; 61167Smax.romanov@nginx.com nxt_port_t *reply_port; 62167Smax.romanov@nginx.com nxt_app_parse_ctx_t *ap; 63423Smax.romanov@nginx.com nxt_msg_info_t msg_info; 64167Smax.romanov@nginx.com nxt_req_conn_link_t *rc; 65167Smax.romanov@nginx.com 66427Smax.romanov@nginx.com nxt_nsec_t res_time; 67427Smax.romanov@nginx.com 68425Smax.romanov@nginx.com nxt_queue_link_t link_app_requests; /* for nxt_app_t.requests */ 69425Smax.romanov@nginx.com nxt_queue_link_t link_port_pending; /* for nxt_port_t.pending_requests */ 70427Smax.romanov@nginx.com nxt_queue_link_t link_app_pending; /* for nxt_app_t.pending */ 71167Smax.romanov@nginx.com 72167Smax.romanov@nginx.com nxt_mp_t *mem_pool; 73167Smax.romanov@nginx.com nxt_work_t work; 74345Smax.romanov@nginx.com 75345Smax.romanov@nginx.com int err_code; 76345Smax.romanov@nginx.com const char *err_str; 77167Smax.romanov@nginx.com }; 78167Smax.romanov@nginx.com 79167Smax.romanov@nginx.com 80198Sigor@sysoev.ru typedef struct { 81198Sigor@sysoev.ru nxt_socket_conf_t *socket_conf; 82198Sigor@sysoev.ru nxt_router_temp_conf_t *temp_conf; 83198Sigor@sysoev.ru } nxt_socket_rpc_t; 84198Sigor@sysoev.ru 85198Sigor@sysoev.ru 86507Smax.romanov@nginx.com typedef struct { 87507Smax.romanov@nginx.com nxt_app_t *app; 88507Smax.romanov@nginx.com nxt_router_temp_conf_t *temp_conf; 89507Smax.romanov@nginx.com } nxt_app_rpc_t; 90507Smax.romanov@nginx.com 91507Smax.romanov@nginx.com 92427Smax.romanov@nginx.com struct nxt_port_select_state_s { 93427Smax.romanov@nginx.com nxt_app_t *app; 94427Smax.romanov@nginx.com nxt_req_app_link_t *ra; 95427Smax.romanov@nginx.com 96427Smax.romanov@nginx.com nxt_port_t *failed_port; 97427Smax.romanov@nginx.com int failed_port_use_delta; 98427Smax.romanov@nginx.com 99507Smax.romanov@nginx.com uint8_t start_process; /* 1 bit */ 100427Smax.romanov@nginx.com nxt_req_app_link_t *shared_ra; 101427Smax.romanov@nginx.com nxt_port_t *port; 102427Smax.romanov@nginx.com }; 103427Smax.romanov@nginx.com 104427Smax.romanov@nginx.com typedef struct nxt_port_select_state_s nxt_port_select_state_t; 105427Smax.romanov@nginx.com 106662Smax.romanov@nginx.com static void nxt_router_greet_controller(nxt_task_t *task, 107662Smax.romanov@nginx.com nxt_port_t *controller_port); 108662Smax.romanov@nginx.com 109427Smax.romanov@nginx.com static void nxt_router_port_select(nxt_task_t *task, 110427Smax.romanov@nginx.com nxt_port_select_state_t *state); 111427Smax.romanov@nginx.com 112427Smax.romanov@nginx.com static nxt_int_t nxt_router_port_post_select(nxt_task_t *task, 113427Smax.romanov@nginx.com nxt_port_select_state_t *state); 114427Smax.romanov@nginx.com 115507Smax.romanov@nginx.com static nxt_int_t nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app); 116343Smax.romanov@nginx.com 117425Smax.romanov@nginx.com nxt_inline void 118425Smax.romanov@nginx.com nxt_router_ra_inc_use(nxt_req_app_link_t *ra) 119425Smax.romanov@nginx.com { 120425Smax.romanov@nginx.com nxt_atomic_fetch_add(&ra->use_count, 1); 121425Smax.romanov@nginx.com } 122425Smax.romanov@nginx.com 123425Smax.romanov@nginx.com nxt_inline void 124425Smax.romanov@nginx.com nxt_router_ra_dec_use(nxt_req_app_link_t *ra) 125425Smax.romanov@nginx.com { 126538Svbart@nginx.com #if (NXT_DEBUG) 127425Smax.romanov@nginx.com int c; 128425Smax.romanov@nginx.com 129425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, -1); 130425Smax.romanov@nginx.com 131425Smax.romanov@nginx.com nxt_assert(c > 1); 132538Svbart@nginx.com #else 133538Svbart@nginx.com (void) nxt_atomic_fetch_add(&ra->use_count, -1); 134538Svbart@nginx.com #endif 135425Smax.romanov@nginx.com } 136425Smax.romanov@nginx.com 137425Smax.romanov@nginx.com static void nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i); 138425Smax.romanov@nginx.com 139139Sigor@sysoev.ru static nxt_router_temp_conf_t *nxt_router_temp_conf(nxt_task_t *task); 140198Sigor@sysoev.ru static void nxt_router_conf_apply(nxt_task_t *task, void *obj, void *data); 141198Sigor@sysoev.ru static void nxt_router_conf_ready(nxt_task_t *task, 142139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 143139Sigor@sysoev.ru static void nxt_router_conf_error(nxt_task_t *task, 144139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 145139Sigor@sysoev.ru static void nxt_router_conf_send(nxt_task_t *task, 146193Smax.romanov@nginx.com nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type); 14753Sigor@sysoev.ru 148115Sigor@sysoev.ru static nxt_int_t nxt_router_conf_create(nxt_task_t *task, 149115Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, u_char *start, u_char *end); 150133Sigor@sysoev.ru static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name); 151133Sigor@sysoev.ru static nxt_app_t *nxt_router_listener_application(nxt_router_temp_conf_t *tmcf, 152133Sigor@sysoev.ru nxt_str_t *name); 153198Sigor@sysoev.ru static void nxt_router_listen_socket_rpc_create(nxt_task_t *task, 154198Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, nxt_socket_conf_t *skcf); 155198Sigor@sysoev.ru static void nxt_router_listen_socket_ready(nxt_task_t *task, 156198Sigor@sysoev.ru nxt_port_recv_msg_t *msg, void *data); 157198Sigor@sysoev.ru static void nxt_router_listen_socket_error(nxt_task_t *task, 158198Sigor@sysoev.ru nxt_port_recv_msg_t *msg, void *data); 159507Smax.romanov@nginx.com static void nxt_router_app_rpc_create(nxt_task_t *task, 160507Smax.romanov@nginx.com nxt_router_temp_conf_t *tmcf, nxt_app_t *app); 161507Smax.romanov@nginx.com static void nxt_router_app_prefork_ready(nxt_task_t *task, 162507Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 163507Smax.romanov@nginx.com static void nxt_router_app_prefork_error(nxt_task_t *task, 164507Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 165359Sigor@sysoev.ru static nxt_socket_conf_t *nxt_router_socket_conf(nxt_task_t *task, 166359Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, nxt_str_t *name); 167359Sigor@sysoev.ru static nxt_int_t nxt_router_listen_socket_find(nxt_router_temp_conf_t *tmcf, 168359Sigor@sysoev.ru nxt_socket_conf_t *nskcf, nxt_sockaddr_t *sa); 16953Sigor@sysoev.ru 17053Sigor@sysoev.ru static nxt_int_t nxt_router_engines_create(nxt_task_t *task, 17153Sigor@sysoev.ru nxt_router_t *router, nxt_router_temp_conf_t *tmcf, 17253Sigor@sysoev.ru const nxt_event_interface_t *interface); 173115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_create(nxt_router_temp_conf_t *tmcf, 174115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 175115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_update(nxt_router_temp_conf_t *tmcf, 176115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 177115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_delete(nxt_router_temp_conf_t *tmcf, 178115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 179154Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_create(nxt_router_temp_conf_t *tmcf, 180154Sigor@sysoev.ru nxt_router_engine_conf_t *recf, nxt_queue_t *sockets, 181154Sigor@sysoev.ru nxt_work_handler_t handler); 182313Sigor@sysoev.ru static nxt_int_t nxt_router_engine_quit(nxt_router_temp_conf_t *tmcf, 183313Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 184139Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_delete(nxt_router_temp_conf_t *tmcf, 185139Sigor@sysoev.ru nxt_router_engine_conf_t *recf, nxt_queue_t *sockets); 18653Sigor@sysoev.ru 18753Sigor@sysoev.ru static nxt_int_t nxt_router_threads_create(nxt_task_t *task, nxt_runtime_t *rt, 18853Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 18953Sigor@sysoev.ru static nxt_int_t nxt_router_thread_create(nxt_task_t *task, nxt_runtime_t *rt, 19053Sigor@sysoev.ru nxt_event_engine_t *engine); 191343Smax.romanov@nginx.com static void nxt_router_apps_sort(nxt_task_t *task, nxt_router_t *router, 192133Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 19353Sigor@sysoev.ru 194315Sigor@sysoev.ru static void nxt_router_engines_post(nxt_router_t *router, 195315Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 196315Sigor@sysoev.ru static void nxt_router_engine_post(nxt_event_engine_t *engine, 197315Sigor@sysoev.ru nxt_work_t *jobs); 19853Sigor@sysoev.ru 19953Sigor@sysoev.ru static void nxt_router_thread_start(void *data); 20053Sigor@sysoev.ru static void nxt_router_listen_socket_create(nxt_task_t *task, void *obj, 20153Sigor@sysoev.ru void *data); 20253Sigor@sysoev.ru static void nxt_router_listen_socket_update(nxt_task_t *task, void *obj, 20353Sigor@sysoev.ru void *data); 20453Sigor@sysoev.ru static void nxt_router_listen_socket_delete(nxt_task_t *task, void *obj, 20553Sigor@sysoev.ru void *data); 206313Sigor@sysoev.ru static void nxt_router_worker_thread_quit(nxt_task_t *task, void *obj, 207313Sigor@sysoev.ru void *data); 20853Sigor@sysoev.ru static void nxt_router_listen_socket_close(nxt_task_t *task, void *obj, 20953Sigor@sysoev.ru void *data); 21053Sigor@sysoev.ru static void nxt_router_thread_exit_handler(nxt_task_t *task, void *obj, 21153Sigor@sysoev.ru void *data); 212359Sigor@sysoev.ru static void nxt_router_listen_socket_release(nxt_task_t *task, 213359Sigor@sysoev.ru nxt_socket_conf_t *skcf); 21453Sigor@sysoev.ru 215630Svbart@nginx.com static void nxt_router_access_log_writer(nxt_task_t *task, 216630Svbart@nginx.com nxt_http_request_t *r, nxt_router_access_log_t *access_log); 217630Svbart@nginx.com static u_char *nxt_router_access_log_date(u_char *buf, nxt_realtime_t *now, 218630Svbart@nginx.com struct tm *tm, size_t size, const char *format); 219630Svbart@nginx.com static void nxt_router_access_log_open(nxt_task_t *task, 220630Svbart@nginx.com nxt_router_temp_conf_t *tmcf); 221630Svbart@nginx.com static void nxt_router_access_log_ready(nxt_task_t *task, 222630Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 223630Svbart@nginx.com static void nxt_router_access_log_error(nxt_task_t *task, 224630Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 225630Svbart@nginx.com static void nxt_router_access_log_release(nxt_task_t *task, 226630Svbart@nginx.com nxt_thread_spinlock_t *lock, nxt_router_access_log_t *access_log); 227651Svbart@nginx.com static void nxt_router_access_log_reopen_completion(nxt_task_t *task, void *obj, 228651Svbart@nginx.com void *data); 229631Svbart@nginx.com static void nxt_router_access_log_reopen_ready(nxt_task_t *task, 230631Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 231631Svbart@nginx.com static void nxt_router_access_log_reopen_error(nxt_task_t *task, 232631Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 233630Svbart@nginx.com 234343Smax.romanov@nginx.com static void nxt_router_app_port_ready(nxt_task_t *task, 235343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 236343Smax.romanov@nginx.com static void nxt_router_app_port_error(nxt_task_t *task, 237343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 238343Smax.romanov@nginx.com 239507Smax.romanov@nginx.com static void nxt_router_app_quit(nxt_task_t *task, nxt_app_t *app); 240343Smax.romanov@nginx.com static void nxt_router_app_port_release(nxt_task_t *task, nxt_port_t *port, 241343Smax.romanov@nginx.com uint32_t request_failed, uint32_t got_response); 242427Smax.romanov@nginx.com static nxt_int_t nxt_router_app_port(nxt_task_t *task, nxt_app_t *app, 243427Smax.romanov@nginx.com nxt_req_app_link_t *ra); 244141Smax.romanov@nginx.com 245425Smax.romanov@nginx.com static void nxt_router_app_prepare_request(nxt_task_t *task, 246343Smax.romanov@nginx.com nxt_req_app_link_t *ra); 247*743Smax.romanov@nginx.com static nxt_buf_t *nxt_router_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 248*743Smax.romanov@nginx.com nxt_port_t *port, const nxt_str_t *prefix); 249510Salexander.borisov@nginx.com 250318Smax.romanov@nginx.com static void nxt_router_app_timeout(nxt_task_t *task, void *obj, void *data); 251507Smax.romanov@nginx.com static void nxt_router_adjust_idle_timer(nxt_task_t *task, void *obj, 252507Smax.romanov@nginx.com void *data); 253507Smax.romanov@nginx.com static void nxt_router_app_idle_timeout(nxt_task_t *task, void *obj, 254507Smax.romanov@nginx.com void *data); 255507Smax.romanov@nginx.com static void nxt_router_app_release_handler(nxt_task_t *task, void *obj, 256507Smax.romanov@nginx.com void *data); 257431Sigor@sysoev.ru 258431Sigor@sysoev.ru static const nxt_http_request_state_t nxt_http_request_send_state; 259431Sigor@sysoev.ru static void nxt_http_request_send_body(nxt_task_t *task, void *obj, void *data); 260141Smax.romanov@nginx.com 261119Smax.romanov@nginx.com static nxt_router_t *nxt_router; 26220Sigor@sysoev.ru 263*743Smax.romanov@nginx.com static const nxt_str_t http_prefix = nxt_string("HTTP_"); 264*743Smax.romanov@nginx.com static const nxt_str_t empty_prefix = nxt_string(""); 265*743Smax.romanov@nginx.com 266*743Smax.romanov@nginx.com static const nxt_str_t *nxt_app_msg_prefix[] = { 267*743Smax.romanov@nginx.com &http_prefix, 268*743Smax.romanov@nginx.com &http_prefix, 269*743Smax.romanov@nginx.com &empty_prefix, 270*743Smax.romanov@nginx.com &http_prefix, 271*743Smax.romanov@nginx.com &http_prefix, 272216Sigor@sysoev.ru }; 273216Sigor@sysoev.ru 274216Sigor@sysoev.ru 275662Smax.romanov@nginx.com nxt_port_handlers_t nxt_router_process_port_handlers = { 276662Smax.romanov@nginx.com .quit = nxt_worker_process_quit_handler, 277662Smax.romanov@nginx.com .new_port = nxt_router_new_port_handler, 278662Smax.romanov@nginx.com .change_file = nxt_port_change_log_file_handler, 279662Smax.romanov@nginx.com .mmap = nxt_port_mmap_handler, 280662Smax.romanov@nginx.com .data = nxt_router_conf_data_handler, 281662Smax.romanov@nginx.com .remove_pid = nxt_router_remove_pid_handler, 282662Smax.romanov@nginx.com .access_log = nxt_router_access_log_reopen_handler, 283662Smax.romanov@nginx.com .rpc_ready = nxt_port_rpc_handler, 284662Smax.romanov@nginx.com .rpc_error = nxt_port_rpc_handler, 285662Smax.romanov@nginx.com }; 286662Smax.romanov@nginx.com 287662Smax.romanov@nginx.com 28820Sigor@sysoev.ru nxt_int_t 289141Smax.romanov@nginx.com nxt_router_start(nxt_task_t *task, void *data) 29020Sigor@sysoev.ru { 291141Smax.romanov@nginx.com nxt_int_t ret; 292662Smax.romanov@nginx.com nxt_port_t *controller_port; 293141Smax.romanov@nginx.com nxt_router_t *router; 294141Smax.romanov@nginx.com nxt_runtime_t *rt; 295141Smax.romanov@nginx.com 296141Smax.romanov@nginx.com rt = task->thread->runtime; 29753Sigor@sysoev.ru 298431Sigor@sysoev.ru ret = nxt_http_init(task, rt); 29988Smax.romanov@nginx.com if (nxt_slow_path(ret != NXT_OK)) { 30088Smax.romanov@nginx.com return ret; 30188Smax.romanov@nginx.com } 30288Smax.romanov@nginx.com 30353Sigor@sysoev.ru router = nxt_zalloc(sizeof(nxt_router_t)); 30453Sigor@sysoev.ru if (nxt_slow_path(router == NULL)) { 30553Sigor@sysoev.ru return NXT_ERROR; 30653Sigor@sysoev.ru } 30753Sigor@sysoev.ru 30853Sigor@sysoev.ru nxt_queue_init(&router->engines); 30953Sigor@sysoev.ru nxt_queue_init(&router->sockets); 310133Sigor@sysoev.ru nxt_queue_init(&router->apps); 31153Sigor@sysoev.ru 312119Smax.romanov@nginx.com nxt_router = router; 313119Smax.romanov@nginx.com 314662Smax.romanov@nginx.com controller_port = rt->port_by_type[NXT_PROCESS_CONTROLLER]; 315662Smax.romanov@nginx.com if (controller_port != NULL) { 316662Smax.romanov@nginx.com nxt_router_greet_controller(task, controller_port); 317662Smax.romanov@nginx.com } 318662Smax.romanov@nginx.com 319115Sigor@sysoev.ru return NXT_OK; 320115Sigor@sysoev.ru } 321115Sigor@sysoev.ru 322115Sigor@sysoev.ru 323343Smax.romanov@nginx.com static void 324662Smax.romanov@nginx.com nxt_router_greet_controller(nxt_task_t *task, nxt_port_t *controller_port) 325662Smax.romanov@nginx.com { 326662Smax.romanov@nginx.com nxt_port_socket_write(task, controller_port, NXT_PORT_MSG_PROCESS_READY, 327662Smax.romanov@nginx.com -1, 0, 0, NULL); 328662Smax.romanov@nginx.com } 329662Smax.romanov@nginx.com 330662Smax.romanov@nginx.com 331662Smax.romanov@nginx.com static void 332507Smax.romanov@nginx.com nxt_router_start_app_process_handler(nxt_task_t *task, nxt_port_t *port, 333507Smax.romanov@nginx.com void *data) 334167Smax.romanov@nginx.com { 335343Smax.romanov@nginx.com size_t size; 336343Smax.romanov@nginx.com uint32_t stream; 337430Sigor@sysoev.ru nxt_mp_t *mp; 338648Svbart@nginx.com nxt_int_t ret; 339343Smax.romanov@nginx.com nxt_app_t *app; 340343Smax.romanov@nginx.com nxt_buf_t *b; 341343Smax.romanov@nginx.com nxt_port_t *main_port; 342343Smax.romanov@nginx.com nxt_runtime_t *rt; 343343Smax.romanov@nginx.com 344343Smax.romanov@nginx.com app = data; 345167Smax.romanov@nginx.com 346167Smax.romanov@nginx.com rt = task->thread->runtime; 347240Sigor@sysoev.ru main_port = rt->port_by_type[NXT_PROCESS_MAIN]; 348167Smax.romanov@nginx.com 349507Smax.romanov@nginx.com nxt_debug(task, "app '%V' %p start process", &app->name, app); 350343Smax.romanov@nginx.com 351343Smax.romanov@nginx.com size = app->name.length + 1 + app->conf.length; 352343Smax.romanov@nginx.com 353343Smax.romanov@nginx.com b = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool, size); 354343Smax.romanov@nginx.com 355343Smax.romanov@nginx.com if (nxt_slow_path(b == NULL)) { 356343Smax.romanov@nginx.com goto failed; 357167Smax.romanov@nginx.com } 358167Smax.romanov@nginx.com 359343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->name); 360343Smax.romanov@nginx.com *b->mem.free++ = '\0'; 361343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->conf); 362343Smax.romanov@nginx.com 363343Smax.romanov@nginx.com stream = nxt_port_rpc_register_handler(task, port, 364343Smax.romanov@nginx.com nxt_router_app_port_ready, 365343Smax.romanov@nginx.com nxt_router_app_port_error, 366343Smax.romanov@nginx.com -1, app); 367343Smax.romanov@nginx.com 368343Smax.romanov@nginx.com if (nxt_slow_path(stream == 0)) { 369343Smax.romanov@nginx.com goto failed; 370343Smax.romanov@nginx.com } 371343Smax.romanov@nginx.com 372648Svbart@nginx.com ret = nxt_port_socket_write(task, main_port, NXT_PORT_MSG_START_WORKER, -1, 373648Svbart@nginx.com stream, port->id, b); 374648Svbart@nginx.com 375648Svbart@nginx.com if (nxt_slow_path(ret != NXT_OK)) { 376648Svbart@nginx.com nxt_port_rpc_cancel(task, port, stream); 377648Svbart@nginx.com goto failed; 378648Svbart@nginx.com } 379343Smax.romanov@nginx.com 380343Smax.romanov@nginx.com return; 381343Smax.romanov@nginx.com 382343Smax.romanov@nginx.com failed: 383343Smax.romanov@nginx.com 384648Svbart@nginx.com if (b != NULL) { 385648Svbart@nginx.com mp = b->data; 386648Svbart@nginx.com nxt_mp_free(mp, b); 387648Svbart@nginx.com nxt_mp_release(mp); 388648Svbart@nginx.com } 389648Svbart@nginx.com 390343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 391343Smax.romanov@nginx.com 392507Smax.romanov@nginx.com app->pending_processes--; 393343Smax.romanov@nginx.com 394343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 395343Smax.romanov@nginx.com 396343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 397167Smax.romanov@nginx.com } 398167Smax.romanov@nginx.com 399167Smax.romanov@nginx.com 400343Smax.romanov@nginx.com static nxt_int_t 401507Smax.romanov@nginx.com nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app) 402141Smax.romanov@nginx.com { 403343Smax.romanov@nginx.com nxt_int_t res; 404343Smax.romanov@nginx.com nxt_port_t *router_port; 405343Smax.romanov@nginx.com nxt_runtime_t *rt; 406343Smax.romanov@nginx.com 407343Smax.romanov@nginx.com rt = task->thread->runtime; 408343Smax.romanov@nginx.com router_port = rt->port_by_type[NXT_PROCESS_ROUTER]; 409343Smax.romanov@nginx.com 410343Smax.romanov@nginx.com nxt_router_app_use(task, app, 1); 411343Smax.romanov@nginx.com 412507Smax.romanov@nginx.com res = nxt_port_post(task, router_port, nxt_router_start_app_process_handler, 413343Smax.romanov@nginx.com app); 414343Smax.romanov@nginx.com 415343Smax.romanov@nginx.com if (res == NXT_OK) { 416343Smax.romanov@nginx.com return res; 417318Smax.romanov@nginx.com } 418318Smax.romanov@nginx.com 419343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 420343Smax.romanov@nginx.com 421507Smax.romanov@nginx.com app->pending_processes--; 422343Smax.romanov@nginx.com 423343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 424343Smax.romanov@nginx.com 425343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 426343Smax.romanov@nginx.com 427343Smax.romanov@nginx.com return NXT_ERROR; 428318Smax.romanov@nginx.com } 429318Smax.romanov@nginx.com 430318Smax.romanov@nginx.com 431351Smax.romanov@nginx.com nxt_inline void 432351Smax.romanov@nginx.com nxt_router_ra_init(nxt_task_t *task, nxt_req_app_link_t *ra, 433351Smax.romanov@nginx.com nxt_req_conn_link_t *rc) 434167Smax.romanov@nginx.com { 435318Smax.romanov@nginx.com nxt_event_engine_t *engine; 436351Smax.romanov@nginx.com 437318Smax.romanov@nginx.com engine = task->thread->engine; 438167Smax.romanov@nginx.com 439167Smax.romanov@nginx.com nxt_memzero(ra, sizeof(nxt_req_app_link_t)); 440167Smax.romanov@nginx.com 441318Smax.romanov@nginx.com ra->stream = rc->stream; 442425Smax.romanov@nginx.com ra->use_count = 1; 443167Smax.romanov@nginx.com ra->rc = rc; 444318Smax.romanov@nginx.com rc->ra = ra; 445318Smax.romanov@nginx.com ra->reply_port = engine->port; 446351Smax.romanov@nginx.com ra->ap = rc->ap; 447167Smax.romanov@nginx.com 448167Smax.romanov@nginx.com ra->work.handler = NULL; 449318Smax.romanov@nginx.com ra->work.task = &engine->task; 450167Smax.romanov@nginx.com ra->work.obj = ra; 451318Smax.romanov@nginx.com ra->work.data = engine; 452351Smax.romanov@nginx.com } 453351Smax.romanov@nginx.com 454351Smax.romanov@nginx.com 455351Smax.romanov@nginx.com nxt_inline nxt_req_app_link_t * 456351Smax.romanov@nginx.com nxt_router_ra_create(nxt_task_t *task, nxt_req_app_link_t *ra_src) 457351Smax.romanov@nginx.com { 458351Smax.romanov@nginx.com nxt_mp_t *mp; 459351Smax.romanov@nginx.com nxt_req_app_link_t *ra; 460351Smax.romanov@nginx.com 461425Smax.romanov@nginx.com if (ra_src->mem_pool != NULL) { 462425Smax.romanov@nginx.com return ra_src; 463425Smax.romanov@nginx.com } 464425Smax.romanov@nginx.com 465351Smax.romanov@nginx.com mp = ra_src->ap->mem_pool; 466351Smax.romanov@nginx.com 467430Sigor@sysoev.ru ra = nxt_mp_alloc(mp, sizeof(nxt_req_app_link_t)); 468351Smax.romanov@nginx.com 469351Smax.romanov@nginx.com if (nxt_slow_path(ra == NULL)) { 470351Smax.romanov@nginx.com 471351Smax.romanov@nginx.com ra_src->rc->ra = NULL; 472351Smax.romanov@nginx.com ra_src->rc = NULL; 473351Smax.romanov@nginx.com 474351Smax.romanov@nginx.com return NULL; 475351Smax.romanov@nginx.com } 476351Smax.romanov@nginx.com 477430Sigor@sysoev.ru nxt_mp_retain(mp); 478430Sigor@sysoev.ru 479351Smax.romanov@nginx.com nxt_router_ra_init(task, ra, ra_src->rc); 480351Smax.romanov@nginx.com 481351Smax.romanov@nginx.com ra->mem_pool = mp; 482167Smax.romanov@nginx.com 483167Smax.romanov@nginx.com return ra; 484167Smax.romanov@nginx.com } 485167Smax.romanov@nginx.com 486167Smax.romanov@nginx.com 487423Smax.romanov@nginx.com nxt_inline nxt_bool_t 488423Smax.romanov@nginx.com nxt_router_msg_cancel(nxt_task_t *task, nxt_msg_info_t *msg_info, 489423Smax.romanov@nginx.com uint32_t stream) 490423Smax.romanov@nginx.com { 491423Smax.romanov@nginx.com nxt_buf_t *b, *next; 492423Smax.romanov@nginx.com nxt_bool_t cancelled; 493423Smax.romanov@nginx.com 494423Smax.romanov@nginx.com if (msg_info->buf == NULL) { 495423Smax.romanov@nginx.com return 0; 496423Smax.romanov@nginx.com } 497423Smax.romanov@nginx.com 498423Smax.romanov@nginx.com cancelled = nxt_port_mmap_tracking_cancel(task, &msg_info->tracking, 499423Smax.romanov@nginx.com stream); 500423Smax.romanov@nginx.com 501423Smax.romanov@nginx.com if (cancelled) { 502423Smax.romanov@nginx.com nxt_debug(task, "stream #%uD: cancelled by router", stream); 503423Smax.romanov@nginx.com } 504423Smax.romanov@nginx.com 505423Smax.romanov@nginx.com for (b = msg_info->buf; b != NULL; b = next) { 506423Smax.romanov@nginx.com next = b->next; 507423Smax.romanov@nginx.com 508423Smax.romanov@nginx.com b->completion_handler = msg_info->completion_handler; 509423Smax.romanov@nginx.com 510423Smax.romanov@nginx.com if (b->is_port_mmap_sent) { 511423Smax.romanov@nginx.com b->is_port_mmap_sent = cancelled == 0; 512423Smax.romanov@nginx.com b->completion_handler(task, b, b->parent); 513423Smax.romanov@nginx.com } 514423Smax.romanov@nginx.com } 515423Smax.romanov@nginx.com 516423Smax.romanov@nginx.com msg_info->buf = NULL; 517423Smax.romanov@nginx.com 518423Smax.romanov@nginx.com return cancelled; 519423Smax.romanov@nginx.com } 520423Smax.romanov@nginx.com 521423Smax.romanov@nginx.com 522167Smax.romanov@nginx.com static void 523425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra); 524425Smax.romanov@nginx.com 525425Smax.romanov@nginx.com 526425Smax.romanov@nginx.com static void 527425Smax.romanov@nginx.com nxt_router_ra_update_peer_handler(nxt_task_t *task, void *obj, void *data) 528167Smax.romanov@nginx.com { 529425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 530425Smax.romanov@nginx.com 531425Smax.romanov@nginx.com ra = obj; 532425Smax.romanov@nginx.com 533425Smax.romanov@nginx.com nxt_router_ra_update_peer(task, ra); 534425Smax.romanov@nginx.com 535425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 536425Smax.romanov@nginx.com } 537425Smax.romanov@nginx.com 538425Smax.romanov@nginx.com 539425Smax.romanov@nginx.com static void 540425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra) 541425Smax.romanov@nginx.com { 542343Smax.romanov@nginx.com nxt_event_engine_t *engine; 543343Smax.romanov@nginx.com nxt_req_conn_link_t *rc; 544318Smax.romanov@nginx.com 545425Smax.romanov@nginx.com engine = ra->work.data; 546318Smax.romanov@nginx.com 547343Smax.romanov@nginx.com if (task->thread->engine != engine) { 548425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 549425Smax.romanov@nginx.com 550425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_update_peer_handler; 551318Smax.romanov@nginx.com ra->work.task = &engine->task; 552318Smax.romanov@nginx.com ra->work.next = NULL; 553318Smax.romanov@nginx.com 554425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post update peer to %p", 555318Smax.romanov@nginx.com ra->stream, engine); 556318Smax.romanov@nginx.com 557318Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 558318Smax.romanov@nginx.com 559318Smax.romanov@nginx.com return; 560318Smax.romanov@nginx.com } 561318Smax.romanov@nginx.com 562425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD update peer", ra->stream); 563425Smax.romanov@nginx.com 564425Smax.romanov@nginx.com rc = ra->rc; 565425Smax.romanov@nginx.com 566425Smax.romanov@nginx.com if (rc != NULL && ra->app_port != NULL) { 567425Smax.romanov@nginx.com nxt_port_rpc_ex_set_peer(task, engine->port, rc, ra->app_port->pid); 568425Smax.romanov@nginx.com } 569425Smax.romanov@nginx.com 570425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 571425Smax.romanov@nginx.com } 572425Smax.romanov@nginx.com 573425Smax.romanov@nginx.com 574425Smax.romanov@nginx.com static void 575425Smax.romanov@nginx.com nxt_router_ra_release(nxt_task_t *task, nxt_req_app_link_t *ra) 576425Smax.romanov@nginx.com { 577431Sigor@sysoev.ru nxt_mp_t *mp; 578431Sigor@sysoev.ru nxt_req_conn_link_t *rc; 579425Smax.romanov@nginx.com 580425Smax.romanov@nginx.com nxt_assert(task->thread->engine == ra->work.data); 581425Smax.romanov@nginx.com nxt_assert(ra->use_count == 0); 582425Smax.romanov@nginx.com 583343Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD release", ra->stream); 584343Smax.romanov@nginx.com 585343Smax.romanov@nginx.com rc = ra->rc; 586343Smax.romanov@nginx.com 587343Smax.romanov@nginx.com if (rc != NULL) { 588423Smax.romanov@nginx.com if (nxt_slow_path(ra->err_code != 0)) { 589431Sigor@sysoev.ru nxt_http_request_error(task, rc->ap->request, ra->err_code); 590423Smax.romanov@nginx.com 591423Smax.romanov@nginx.com } else { 592423Smax.romanov@nginx.com rc->app_port = ra->app_port; 593423Smax.romanov@nginx.com rc->msg_info = ra->msg_info; 594423Smax.romanov@nginx.com 595425Smax.romanov@nginx.com if (rc->app->timeout != 0) { 596431Sigor@sysoev.ru rc->ap->timer.handler = nxt_router_app_timeout; 597615Smax.romanov@nginx.com rc->ap->timer_data = rc; 598431Sigor@sysoev.ru nxt_timer_add(task->thread->engine, &rc->ap->timer, 599425Smax.romanov@nginx.com rc->app->timeout); 600425Smax.romanov@nginx.com } 601425Smax.romanov@nginx.com 602423Smax.romanov@nginx.com ra->app_port = NULL; 603423Smax.romanov@nginx.com ra->msg_info.buf = NULL; 604423Smax.romanov@nginx.com } 605343Smax.romanov@nginx.com 606343Smax.romanov@nginx.com rc->ra = NULL; 607343Smax.romanov@nginx.com ra->rc = NULL; 608343Smax.romanov@nginx.com } 609343Smax.romanov@nginx.com 610343Smax.romanov@nginx.com if (ra->app_port != NULL) { 611343Smax.romanov@nginx.com nxt_router_app_port_release(task, ra->app_port, 0, 1); 612343Smax.romanov@nginx.com 613343Smax.romanov@nginx.com ra->app_port = NULL; 614167Smax.romanov@nginx.com } 615167Smax.romanov@nginx.com 616423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &ra->msg_info, ra->stream); 617423Smax.romanov@nginx.com 618430Sigor@sysoev.ru mp = ra->mem_pool; 619430Sigor@sysoev.ru 620430Sigor@sysoev.ru if (mp != NULL) { 621430Sigor@sysoev.ru nxt_mp_free(mp, ra); 622430Sigor@sysoev.ru nxt_mp_release(mp); 623351Smax.romanov@nginx.com } 624167Smax.romanov@nginx.com } 625167Smax.romanov@nginx.com 626167Smax.romanov@nginx.com 627425Smax.romanov@nginx.com static void 628425Smax.romanov@nginx.com nxt_router_ra_release_handler(nxt_task_t *task, void *obj, void *data) 629425Smax.romanov@nginx.com { 630425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 631425Smax.romanov@nginx.com 632425Smax.romanov@nginx.com ra = obj; 633425Smax.romanov@nginx.com 634425Smax.romanov@nginx.com nxt_assert(ra->work.data == data); 635425Smax.romanov@nginx.com 636425Smax.romanov@nginx.com nxt_atomic_fetch_add(&ra->use_count, -1); 637425Smax.romanov@nginx.com 638425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 639425Smax.romanov@nginx.com } 640425Smax.romanov@nginx.com 641425Smax.romanov@nginx.com 642425Smax.romanov@nginx.com static void 643425Smax.romanov@nginx.com nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i) 644425Smax.romanov@nginx.com { 645425Smax.romanov@nginx.com int c; 646425Smax.romanov@nginx.com nxt_event_engine_t *engine; 647425Smax.romanov@nginx.com 648425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, i); 649425Smax.romanov@nginx.com 650425Smax.romanov@nginx.com if (i < 0 && c == -i) { 651425Smax.romanov@nginx.com engine = ra->work.data; 652425Smax.romanov@nginx.com 653425Smax.romanov@nginx.com if (task->thread->engine == engine) { 654425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 655425Smax.romanov@nginx.com 656425Smax.romanov@nginx.com return; 657425Smax.romanov@nginx.com } 658425Smax.romanov@nginx.com 659425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 660425Smax.romanov@nginx.com 661425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_release_handler; 662425Smax.romanov@nginx.com ra->work.task = &engine->task; 663425Smax.romanov@nginx.com ra->work.next = NULL; 664425Smax.romanov@nginx.com 665425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post release to %p", 666425Smax.romanov@nginx.com ra->stream, engine); 667425Smax.romanov@nginx.com 668425Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 669425Smax.romanov@nginx.com } 670425Smax.romanov@nginx.com } 671425Smax.romanov@nginx.com 672425Smax.romanov@nginx.com 673423Smax.romanov@nginx.com nxt_inline void 674521Szelenkov@nginx.com nxt_router_ra_error(nxt_req_app_link_t *ra, int code, const char *str) 675345Smax.romanov@nginx.com { 676423Smax.romanov@nginx.com ra->app_port = NULL; 677423Smax.romanov@nginx.com ra->err_code = code; 678423Smax.romanov@nginx.com ra->err_str = str; 679345Smax.romanov@nginx.com } 680345Smax.romanov@nginx.com 681345Smax.romanov@nginx.com 682427Smax.romanov@nginx.com nxt_inline void 683427Smax.romanov@nginx.com nxt_router_ra_pending(nxt_task_t *task, nxt_app_t *app, nxt_req_app_link_t *ra) 684427Smax.romanov@nginx.com { 685427Smax.romanov@nginx.com nxt_queue_insert_tail(&ra->app_port->pending_requests, 686427Smax.romanov@nginx.com &ra->link_port_pending); 687427Smax.romanov@nginx.com nxt_queue_insert_tail(&app->pending, &ra->link_app_pending); 688427Smax.romanov@nginx.com 689427Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 690427Smax.romanov@nginx.com 691427Smax.romanov@nginx.com ra->res_time = nxt_thread_monotonic_time(task->thread) + app->res_timeout; 692427Smax.romanov@nginx.com 693427Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD enqueue to pending_requests", ra->stream); 694427Smax.romanov@nginx.com } 695427Smax.romanov@nginx.com 696427Smax.romanov@nginx.com 697425Smax.romanov@nginx.com nxt_inline nxt_bool_t 698425Smax.romanov@nginx.com nxt_queue_chk_remove(nxt_queue_link_t *lnk) 699425Smax.romanov@nginx.com { 700425Smax.romanov@nginx.com if (lnk->next != NULL) { 701425Smax.romanov@nginx.com nxt_queue_remove(lnk); 702425Smax.romanov@nginx.com 703425Smax.romanov@nginx.com lnk->next = NULL; 704425Smax.romanov@nginx.com 705425Smax.romanov@nginx.com return 1; 706425Smax.romanov@nginx.com } 707425Smax.romanov@nginx.com 708425Smax.romanov@nginx.com return 0; 709425Smax.romanov@nginx.com } 710425Smax.romanov@nginx.com 711425Smax.romanov@nginx.com 712343Smax.romanov@nginx.com nxt_inline void 713343Smax.romanov@nginx.com nxt_router_rc_unlink(nxt_task_t *task, nxt_req_conn_link_t *rc) 714343Smax.romanov@nginx.com { 715425Smax.romanov@nginx.com int ra_use_delta; 716343Smax.romanov@nginx.com nxt_req_app_link_t *ra; 717343Smax.romanov@nginx.com 718343Smax.romanov@nginx.com if (rc->app_port != NULL) { 719343Smax.romanov@nginx.com nxt_router_app_port_release(task, rc->app_port, 0, 1); 720343Smax.romanov@nginx.com 721343Smax.romanov@nginx.com rc->app_port = NULL; 722343Smax.romanov@nginx.com } 723343Smax.romanov@nginx.com 724423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &rc->msg_info, rc->stream); 725423Smax.romanov@nginx.com 726343Smax.romanov@nginx.com ra = rc->ra; 727343Smax.romanov@nginx.com 728343Smax.romanov@nginx.com if (ra != NULL) { 729343Smax.romanov@nginx.com rc->ra = NULL; 730343Smax.romanov@nginx.com ra->rc = NULL; 731343Smax.romanov@nginx.com 732425Smax.romanov@nginx.com ra_use_delta = 0; 733425Smax.romanov@nginx.com 734343Smax.romanov@nginx.com nxt_thread_mutex_lock(&rc->app->mutex); 735343Smax.romanov@nginx.com 736425Smax.romanov@nginx.com if (ra->link_app_requests.next == NULL 737427Smax.romanov@nginx.com && ra->link_port_pending.next == NULL 738427Smax.romanov@nginx.com && ra->link_app_pending.next == NULL) 739425Smax.romanov@nginx.com { 740425Smax.romanov@nginx.com ra = NULL; 741343Smax.romanov@nginx.com 742343Smax.romanov@nginx.com } else { 743425Smax.romanov@nginx.com ra_use_delta -= nxt_queue_chk_remove(&ra->link_app_requests); 744425Smax.romanov@nginx.com ra_use_delta -= nxt_queue_chk_remove(&ra->link_port_pending); 745427Smax.romanov@nginx.com nxt_queue_chk_remove(&ra->link_app_pending); 746343Smax.romanov@nginx.com } 747343Smax.romanov@nginx.com 748343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&rc->app->mutex); 749425Smax.romanov@nginx.com 750425Smax.romanov@nginx.com if (ra != NULL) { 751425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, ra_use_delta); 752425Smax.romanov@nginx.com } 753343Smax.romanov@nginx.com } 754343Smax.romanov@nginx.com 755343Smax.romanov@nginx.com if (rc->app != NULL) { 756343Smax.romanov@nginx.com nxt_router_app_use(task, rc->app, -1); 757343Smax.romanov@nginx.com 758343Smax.romanov@nginx.com rc->app = NULL; 759343Smax.romanov@nginx.com } 760343Smax.romanov@nginx.com 761346Smax.romanov@nginx.com if (rc->ap != NULL) { 762615Smax.romanov@nginx.com rc->ap->timer_data = NULL; 763615Smax.romanov@nginx.com 764346Smax.romanov@nginx.com nxt_app_http_req_done(task, rc->ap); 765346Smax.romanov@nginx.com 766346Smax.romanov@nginx.com rc->ap = NULL; 767346Smax.romanov@nginx.com } 768343Smax.romanov@nginx.com } 769343Smax.romanov@nginx.com 770343Smax.romanov@nginx.com 771141Smax.romanov@nginx.com void 772141Smax.romanov@nginx.com nxt_router_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) 773141Smax.romanov@nginx.com { 774141Smax.romanov@nginx.com nxt_port_new_port_handler(task, msg); 775141Smax.romanov@nginx.com 776670Smax.romanov@nginx.com if (msg->u.new_port != NULL 777670Smax.romanov@nginx.com && msg->u.new_port->type == NXT_PROCESS_CONTROLLER) 778670Smax.romanov@nginx.com { 779662Smax.romanov@nginx.com nxt_router_greet_controller(task, msg->u.new_port); 780662Smax.romanov@nginx.com } 781662Smax.romanov@nginx.com 782192Smax.romanov@nginx.com if (msg->port_msg.stream == 0) { 783141Smax.romanov@nginx.com return; 784141Smax.romanov@nginx.com } 785141Smax.romanov@nginx.com 786426Smax.romanov@nginx.com if (msg->u.new_port == NULL 787426Smax.romanov@nginx.com || msg->u.new_port->type != NXT_PROCESS_WORKER) 788347Smax.romanov@nginx.com { 789192Smax.romanov@nginx.com msg->port_msg.type = _NXT_PORT_MSG_RPC_ERROR; 790141Smax.romanov@nginx.com } 791192Smax.romanov@nginx.com 792192Smax.romanov@nginx.com nxt_port_rpc_handler(task, msg); 793141Smax.romanov@nginx.com } 794141Smax.romanov@nginx.com 795141Smax.romanov@nginx.com 796139Sigor@sysoev.ru void 797139Sigor@sysoev.ru nxt_router_conf_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) 798115Sigor@sysoev.ru { 799198Sigor@sysoev.ru nxt_int_t ret; 800139Sigor@sysoev.ru nxt_buf_t *b; 801139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf; 802139Sigor@sysoev.ru 803139Sigor@sysoev.ru tmcf = nxt_router_temp_conf(task); 804139Sigor@sysoev.ru if (nxt_slow_path(tmcf == NULL)) { 805139Sigor@sysoev.ru return; 80653Sigor@sysoev.ru } 80753Sigor@sysoev.ru 808494Spluknet@nginx.com nxt_debug(task, "nxt_router_conf_data_handler(%O): %*s", 809423Smax.romanov@nginx.com nxt_buf_used_size(msg->buf), 810493