120Sigor@sysoev.ru 220Sigor@sysoev.ru /* 320Sigor@sysoev.ru * Copyright (C) Igor Sysoev 420Sigor@sysoev.ru * Copyright (C) Valentin V. Bartenev 520Sigor@sysoev.ru * Copyright (C) NGINX, Inc. 620Sigor@sysoev.ru */ 720Sigor@sysoev.ru 853Sigor@sysoev.ru #include <nxt_router.h> 9115Sigor@sysoev.ru #include <nxt_conf.h> 10774Svbart@nginx.com #if (NXT_TLS) 11774Svbart@nginx.com #include <nxt_cert.h> 12774Svbart@nginx.com #endif 13431Sigor@sysoev.ru #include <nxt_http.h> 14743Smax.romanov@nginx.com #include <nxt_port_memory_int.h> 15743Smax.romanov@nginx.com #include <nxt_unit_request.h> 16743Smax.romanov@nginx.com #include <nxt_unit_response.h> 1720Sigor@sysoev.ru 1820Sigor@sysoev.ru 19115Sigor@sysoev.ru typedef struct { 20318Smax.romanov@nginx.com nxt_str_t type; 21507Smax.romanov@nginx.com uint32_t processes; 22507Smax.romanov@nginx.com uint32_t max_processes; 23507Smax.romanov@nginx.com uint32_t spare_processes; 24318Smax.romanov@nginx.com nxt_msec_t timeout; 25427Smax.romanov@nginx.com nxt_msec_t res_timeout; 26507Smax.romanov@nginx.com nxt_msec_t idle_timeout; 27318Smax.romanov@nginx.com uint32_t requests; 28318Smax.romanov@nginx.com nxt_conf_value_t *limits_value; 29507Smax.romanov@nginx.com nxt_conf_value_t *processes_value; 30133Sigor@sysoev.ru } nxt_router_app_conf_t; 31133Sigor@sysoev.ru 32133Sigor@sysoev.ru 33133Sigor@sysoev.ru typedef struct { 34964Sigor@sysoev.ru nxt_str_t pass; 35964Sigor@sysoev.ru nxt_str_t application; 36115Sigor@sysoev.ru } nxt_router_listener_conf_t; 37115Sigor@sysoev.ru 38115Sigor@sysoev.ru 39774Svbart@nginx.com #if (NXT_TLS) 40774Svbart@nginx.com 41774Svbart@nginx.com typedef struct { 42774Svbart@nginx.com nxt_str_t name; 43774Svbart@nginx.com nxt_socket_conf_t *conf; 44774Svbart@nginx.com 45774Svbart@nginx.com nxt_queue_link_t link; /* for nxt_socket_conf_t.tls */ 46774Svbart@nginx.com } nxt_router_tlssock_t; 47774Svbart@nginx.com 48774Svbart@nginx.com #endif 49774Svbart@nginx.com 50774Svbart@nginx.com 51423Smax.romanov@nginx.com typedef struct nxt_msg_info_s { 52423Smax.romanov@nginx.com nxt_buf_t *buf; 53423Smax.romanov@nginx.com nxt_port_mmap_tracking_t tracking; 54423Smax.romanov@nginx.com nxt_work_handler_t completion_handler; 55423Smax.romanov@nginx.com } nxt_msg_info_t; 56423Smax.romanov@nginx.com 57423Smax.romanov@nginx.com 58167Smax.romanov@nginx.com typedef struct nxt_req_app_link_s nxt_req_app_link_t; 59141Smax.romanov@nginx.com 60141Smax.romanov@nginx.com 61318Smax.romanov@nginx.com typedef struct { 62431Sigor@sysoev.ru uint32_t stream; 63431Sigor@sysoev.ru nxt_app_t *app; 64431Sigor@sysoev.ru nxt_port_t *app_port; 65*1007Salexander.borisov@nginx.com nxt_http_request_t *request; 66431Sigor@sysoev.ru nxt_msg_info_t msg_info; 67431Sigor@sysoev.ru nxt_req_app_link_t *ra; 68431Sigor@sysoev.ru 69431Sigor@sysoev.ru nxt_queue_link_t link; /* for nxt_conn_t.requests */ 70318Smax.romanov@nginx.com } nxt_req_conn_link_t; 71318Smax.romanov@nginx.com 72318Smax.romanov@nginx.com 73167Smax.romanov@nginx.com struct nxt_req_app_link_s { 74318Smax.romanov@nginx.com uint32_t stream; 75425Smax.romanov@nginx.com nxt_atomic_t use_count; 76167Smax.romanov@nginx.com nxt_port_t *app_port; 77167Smax.romanov@nginx.com nxt_port_t *reply_port; 78*1007Salexander.borisov@nginx.com nxt_http_request_t *request; 79423Smax.romanov@nginx.com nxt_msg_info_t msg_info; 80167Smax.romanov@nginx.com nxt_req_conn_link_t *rc; 81167Smax.romanov@nginx.com 82427Smax.romanov@nginx.com nxt_nsec_t res_time; 83427Smax.romanov@nginx.com 84425Smax.romanov@nginx.com nxt_queue_link_t link_app_requests; /* for nxt_app_t.requests */ 85425Smax.romanov@nginx.com nxt_queue_link_t link_port_pending; /* for nxt_port_t.pending_requests */ 86427Smax.romanov@nginx.com nxt_queue_link_t link_app_pending; /* for nxt_app_t.pending */ 87167Smax.romanov@nginx.com 88167Smax.romanov@nginx.com nxt_mp_t *mem_pool; 89167Smax.romanov@nginx.com nxt_work_t work; 90345Smax.romanov@nginx.com 91345Smax.romanov@nginx.com int err_code; 92345Smax.romanov@nginx.com const char *err_str; 93167Smax.romanov@nginx.com }; 94167Smax.romanov@nginx.com 95167Smax.romanov@nginx.com 96198Sigor@sysoev.ru typedef struct { 97198Sigor@sysoev.ru nxt_socket_conf_t *socket_conf; 98198Sigor@sysoev.ru nxt_router_temp_conf_t *temp_conf; 99198Sigor@sysoev.ru } nxt_socket_rpc_t; 100198Sigor@sysoev.ru 101198Sigor@sysoev.ru 102507Smax.romanov@nginx.com typedef struct { 103507Smax.romanov@nginx.com nxt_app_t *app; 104507Smax.romanov@nginx.com nxt_router_temp_conf_t *temp_conf; 105507Smax.romanov@nginx.com } nxt_app_rpc_t; 106507Smax.romanov@nginx.com 107507Smax.romanov@nginx.com 108427Smax.romanov@nginx.com struct nxt_port_select_state_s { 109427Smax.romanov@nginx.com nxt_app_t *app; 110427Smax.romanov@nginx.com nxt_req_app_link_t *ra; 111427Smax.romanov@nginx.com 112427Smax.romanov@nginx.com nxt_port_t *failed_port; 113427Smax.romanov@nginx.com int failed_port_use_delta; 114427Smax.romanov@nginx.com 115507Smax.romanov@nginx.com uint8_t start_process; /* 1 bit */ 116427Smax.romanov@nginx.com nxt_req_app_link_t *shared_ra; 117427Smax.romanov@nginx.com nxt_port_t *port; 118427Smax.romanov@nginx.com }; 119427Smax.romanov@nginx.com 120427Smax.romanov@nginx.com typedef struct nxt_port_select_state_s nxt_port_select_state_t; 121427Smax.romanov@nginx.com 122662Smax.romanov@nginx.com static void nxt_router_greet_controller(nxt_task_t *task, 123662Smax.romanov@nginx.com nxt_port_t *controller_port); 124662Smax.romanov@nginx.com 125427Smax.romanov@nginx.com static void nxt_router_port_select(nxt_task_t *task, 126427Smax.romanov@nginx.com nxt_port_select_state_t *state); 127427Smax.romanov@nginx.com 128427Smax.romanov@nginx.com static nxt_int_t nxt_router_port_post_select(nxt_task_t *task, 129427Smax.romanov@nginx.com nxt_port_select_state_t *state); 130427Smax.romanov@nginx.com 131507Smax.romanov@nginx.com static nxt_int_t nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app); 132343Smax.romanov@nginx.com 133425Smax.romanov@nginx.com nxt_inline void 134425Smax.romanov@nginx.com nxt_router_ra_inc_use(nxt_req_app_link_t *ra) 135425Smax.romanov@nginx.com { 136425Smax.romanov@nginx.com nxt_atomic_fetch_add(&ra->use_count, 1); 137425Smax.romanov@nginx.com } 138425Smax.romanov@nginx.com 139425Smax.romanov@nginx.com nxt_inline void 140425Smax.romanov@nginx.com nxt_router_ra_dec_use(nxt_req_app_link_t *ra) 141425Smax.romanov@nginx.com { 142538Svbart@nginx.com #if (NXT_DEBUG) 143425Smax.romanov@nginx.com int c; 144425Smax.romanov@nginx.com 145425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, -1); 146425Smax.romanov@nginx.com 147425Smax.romanov@nginx.com nxt_assert(c > 1); 148538Svbart@nginx.com #else 149538Svbart@nginx.com (void) nxt_atomic_fetch_add(&ra->use_count, -1); 150538Svbart@nginx.com #endif 151425Smax.romanov@nginx.com } 152425Smax.romanov@nginx.com 153425Smax.romanov@nginx.com static void nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i); 154425Smax.romanov@nginx.com 155139Sigor@sysoev.ru static nxt_router_temp_conf_t *nxt_router_temp_conf(nxt_task_t *task); 156198Sigor@sysoev.ru static void nxt_router_conf_apply(nxt_task_t *task, void *obj, void *data); 157198Sigor@sysoev.ru static void nxt_router_conf_ready(nxt_task_t *task, 158139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 159139Sigor@sysoev.ru static void nxt_router_conf_error(nxt_task_t *task, 160139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 161139Sigor@sysoev.ru static void nxt_router_conf_send(nxt_task_t *task, 162193Smax.romanov@nginx.com nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type); 16353Sigor@sysoev.ru 164115Sigor@sysoev.ru static nxt_int_t nxt_router_conf_create(nxt_task_t *task, 165115Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, u_char *start, u_char *end); 166133Sigor@sysoev.ru static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name); 167198Sigor@sysoev.ru static void nxt_router_listen_socket_rpc_create(nxt_task_t *task, 168198Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, nxt_socket_conf_t *skcf); 169198Sigor@sysoev.ru static void nxt_router_listen_socket_ready(nxt_task_t *task, 170198Sigor@sysoev.ru nxt_port_recv_msg_t *msg, void *data); 171198Sigor@sysoev.ru static void nxt_router_listen_socket_error(nxt_task_t *task, 172198Sigor@sysoev.ru nxt_port_recv_msg_t *msg, void *data); 173774Svbart@nginx.com #if (NXT_TLS) 174774Svbart@nginx.com static void nxt_router_tls_rpc_create(nxt_task_t *task, 175774Svbart@nginx.com nxt_router_temp_conf_t *tmcf, nxt_router_tlssock_t *tls); 176774Svbart@nginx.com static void nxt_router_tls_rpc_handler(nxt_task_t *task, 177774Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 178774Svbart@nginx.com #endif 179507Smax.romanov@nginx.com static void nxt_router_app_rpc_create(nxt_task_t *task, 180507Smax.romanov@nginx.com nxt_router_temp_conf_t *tmcf, nxt_app_t *app); 181507Smax.romanov@nginx.com static void nxt_router_app_prefork_ready(nxt_task_t *task, 182507Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 183507Smax.romanov@nginx.com static void nxt_router_app_prefork_error(nxt_task_t *task, 184507Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 185359Sigor@sysoev.ru static nxt_socket_conf_t *nxt_router_socket_conf(nxt_task_t *task, 186359Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, nxt_str_t *name); 187359Sigor@sysoev.ru static nxt_int_t nxt_router_listen_socket_find(nxt_router_temp_conf_t *tmcf, 188359Sigor@sysoev.ru nxt_socket_conf_t *nskcf, nxt_sockaddr_t *sa); 18953Sigor@sysoev.ru 19053Sigor@sysoev.ru static nxt_int_t nxt_router_engines_create(nxt_task_t *task, 19153Sigor@sysoev.ru nxt_router_t *router, nxt_router_temp_conf_t *tmcf, 19253Sigor@sysoev.ru const nxt_event_interface_t *interface); 193115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_create(nxt_router_temp_conf_t *tmcf, 194115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 195115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_update(nxt_router_temp_conf_t *tmcf, 196115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 197115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_delete(nxt_router_temp_conf_t *tmcf, 198115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 199154Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_create(nxt_router_temp_conf_t *tmcf, 200154Sigor@sysoev.ru nxt_router_engine_conf_t *recf, nxt_queue_t *sockets, 201154Sigor@sysoev.ru nxt_work_handler_t handler); 202313Sigor@sysoev.ru static nxt_int_t nxt_router_engine_quit(nxt_router_temp_conf_t *tmcf, 203313Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 204139Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_delete(nxt_router_temp_conf_t *tmcf, 205139Sigor@sysoev.ru nxt_router_engine_conf_t *recf, nxt_queue_t *sockets); 20653Sigor@sysoev.ru 20753Sigor@sysoev.ru static nxt_int_t nxt_router_threads_create(nxt_task_t *task, nxt_runtime_t *rt, 20853Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 20953Sigor@sysoev.ru static nxt_int_t nxt_router_thread_create(nxt_task_t *task, nxt_runtime_t *rt, 21053Sigor@sysoev.ru nxt_event_engine_t *engine); 211343Smax.romanov@nginx.com static void nxt_router_apps_sort(nxt_task_t *task, nxt_router_t *router, 212133Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 21353Sigor@sysoev.ru 214315Sigor@sysoev.ru static void nxt_router_engines_post(nxt_router_t *router, 215315Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 216315Sigor@sysoev.ru static void nxt_router_engine_post(nxt_event_engine_t *engine, 217315Sigor@sysoev.ru nxt_work_t *jobs); 21853Sigor@sysoev.ru 21953Sigor@sysoev.ru static void nxt_router_thread_start(void *data); 22053Sigor@sysoev.ru static void nxt_router_listen_socket_create(nxt_task_t *task, void *obj, 22153Sigor@sysoev.ru void *data); 22253Sigor@sysoev.ru static void nxt_router_listen_socket_update(nxt_task_t *task, void *obj, 22353Sigor@sysoev.ru void *data); 22453Sigor@sysoev.ru static void nxt_router_listen_socket_delete(nxt_task_t *task, void *obj, 22553Sigor@sysoev.ru void *data); 226313Sigor@sysoev.ru static void nxt_router_worker_thread_quit(nxt_task_t *task, void *obj, 227313Sigor@sysoev.ru void *data); 22853Sigor@sysoev.ru static void nxt_router_listen_socket_close(nxt_task_t *task, void *obj, 22953Sigor@sysoev.ru void *data); 23053Sigor@sysoev.ru static void nxt_router_thread_exit_handler(nxt_task_t *task, void *obj, 23153Sigor@sysoev.ru void *data); 232359Sigor@sysoev.ru static void nxt_router_listen_socket_release(nxt_task_t *task, 233359Sigor@sysoev.ru nxt_socket_conf_t *skcf); 23453Sigor@sysoev.ru 235630Svbart@nginx.com static void nxt_router_access_log_writer(nxt_task_t *task, 236630Svbart@nginx.com nxt_http_request_t *r, nxt_router_access_log_t *access_log); 237630Svbart@nginx.com static u_char *nxt_router_access_log_date(u_char *buf, nxt_realtime_t *now, 238630Svbart@nginx.com struct tm *tm, size_t size, const char *format); 239630Svbart@nginx.com static void nxt_router_access_log_open(nxt_task_t *task, 240630Svbart@nginx.com nxt_router_temp_conf_t *tmcf); 241630Svbart@nginx.com static void nxt_router_access_log_ready(nxt_task_t *task, 242630Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 243630Svbart@nginx.com static void nxt_router_access_log_error(nxt_task_t *task, 244630Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 245630Svbart@nginx.com static void nxt_router_access_log_release(nxt_task_t *task, 246630Svbart@nginx.com nxt_thread_spinlock_t *lock, nxt_router_access_log_t *access_log); 247651Svbart@nginx.com static void nxt_router_access_log_reopen_completion(nxt_task_t *task, void *obj, 248651Svbart@nginx.com void *data); 249631Svbart@nginx.com static void nxt_router_access_log_reopen_ready(nxt_task_t *task, 250631Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 251631Svbart@nginx.com static void nxt_router_access_log_reopen_error(nxt_task_t *task, 252631Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 253630Svbart@nginx.com 254343Smax.romanov@nginx.com static void nxt_router_app_port_ready(nxt_task_t *task, 255343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 256343Smax.romanov@nginx.com static void nxt_router_app_port_error(nxt_task_t *task, 257343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 258343Smax.romanov@nginx.com 259753Smax.romanov@nginx.com static void nxt_router_app_unlink(nxt_task_t *task, nxt_app_t *app); 260343Smax.romanov@nginx.com static void nxt_router_app_port_release(nxt_task_t *task, nxt_port_t *port, 261343Smax.romanov@nginx.com uint32_t request_failed, uint32_t got_response); 262427Smax.romanov@nginx.com static nxt_int_t nxt_router_app_port(nxt_task_t *task, nxt_app_t *app, 263427Smax.romanov@nginx.com nxt_req_app_link_t *ra); 264141Smax.romanov@nginx.com 265425Smax.romanov@nginx.com static void nxt_router_app_prepare_request(nxt_task_t *task, 266343Smax.romanov@nginx.com nxt_req_app_link_t *ra); 267*1007Salexander.borisov@nginx.com static nxt_buf_t *nxt_router_prepare_msg(nxt_task_t *task, 268*1007Salexander.borisov@nginx.com nxt_http_request_t *r, nxt_port_t *port, const nxt_str_t *prefix); 269510Salexander.borisov@nginx.com 270318Smax.romanov@nginx.com static void nxt_router_app_timeout(nxt_task_t *task, void *obj, void *data); 271507Smax.romanov@nginx.com static void nxt_router_adjust_idle_timer(nxt_task_t *task, void *obj, 272507Smax.romanov@nginx.com void *data); 273507Smax.romanov@nginx.com static void nxt_router_app_idle_timeout(nxt_task_t *task, void *obj, 274507Smax.romanov@nginx.com void *data); 275753Smax.romanov@nginx.com static void nxt_router_app_joint_release_handler(nxt_task_t *task, void *obj, 276507Smax.romanov@nginx.com void *data); 277753Smax.romanov@nginx.com static void nxt_router_free_app(nxt_task_t *task, void *obj, void *data); 278431Sigor@sysoev.ru 279431Sigor@sysoev.ru static const nxt_http_request_state_t nxt_http_request_send_state; 280431Sigor@sysoev.ru static void nxt_http_request_send_body(nxt_task_t *task, void *obj, void *data); 281141Smax.romanov@nginx.com 282753Smax.romanov@nginx.com static void nxt_router_app_joint_use(nxt_task_t *task, 283753Smax.romanov@nginx.com nxt_app_joint_t *app_joint, int i); 284753Smax.romanov@nginx.com 285*1007Salexander.borisov@nginx.com static nxt_int_t nxt_router_http_request_done(nxt_task_t *task, 286*1007Salexander.borisov@nginx.com nxt_http_request_t *r); 287*1007Salexander.borisov@nginx.com static void nxt_router_http_request_release(nxt_task_t *task, void *obj, 288*1007Salexander.borisov@nginx.com void *data); 289*1007Salexander.borisov@nginx.com 290119Smax.romanov@nginx.com static nxt_router_t *nxt_router; 29120Sigor@sysoev.ru 292743Smax.romanov@nginx.com static const nxt_str_t http_prefix = nxt_string("HTTP_"); 293743Smax.romanov@nginx.com static const nxt_str_t empty_prefix = nxt_string(""); 294743Smax.romanov@nginx.com 295743Smax.romanov@nginx.com static const nxt_str_t *nxt_app_msg_prefix[] = { 296804Svbart@nginx.com &empty_prefix, 297743Smax.romanov@nginx.com &http_prefix, 298743Smax.romanov@nginx.com &http_prefix, 299743Smax.romanov@nginx.com &http_prefix, 300743Smax.romanov@nginx.com &http_prefix, 301977Smax.romanov@gmail.com &empty_prefix, 302216Sigor@sysoev.ru }; 303216Sigor@sysoev.ru 304216Sigor@sysoev.ru 305662Smax.romanov@nginx.com nxt_port_handlers_t nxt_router_process_port_handlers = { 306662Smax.romanov@nginx.com .quit = nxt_worker_process_quit_handler, 307662Smax.romanov@nginx.com .new_port = nxt_router_new_port_handler, 308662Smax.romanov@nginx.com .change_file = nxt_port_change_log_file_handler, 309662Smax.romanov@nginx.com .mmap = nxt_port_mmap_handler, 310662Smax.romanov@nginx.com .data = nxt_router_conf_data_handler, 311662Smax.romanov@nginx.com .remove_pid = nxt_router_remove_pid_handler, 312662Smax.romanov@nginx.com .access_log = nxt_router_access_log_reopen_handler, 313662Smax.romanov@nginx.com .rpc_ready = nxt_port_rpc_handler, 314662Smax.romanov@nginx.com .rpc_error = nxt_port_rpc_handler, 315662Smax.romanov@nginx.com }; 316662Smax.romanov@nginx.com 317662Smax.romanov@nginx.com 31820Sigor@sysoev.ru nxt_int_t 319141Smax.romanov@nginx.com nxt_router_start(nxt_task_t *task, void *data) 32020Sigor@sysoev.ru { 321141Smax.romanov@nginx.com nxt_int_t ret; 322662Smax.romanov@nginx.com nxt_port_t *controller_port; 323141Smax.romanov@nginx.com nxt_router_t *router; 324141Smax.romanov@nginx.com nxt_runtime_t *rt; 325141Smax.romanov@nginx.com 326141Smax.romanov@nginx.com rt = task->thread->runtime; 32753Sigor@sysoev.ru 328771Sigor@sysoev.ru #if (NXT_TLS) 329771Sigor@sysoev.ru rt->tls = nxt_service_get(rt->services, "SSL/TLS", "OpenSSL"); 330771Sigor@sysoev.ru if (nxt_slow_path(rt->tls == NULL)) { 331771Sigor@sysoev.ru return NXT_ERROR; 332771Sigor@sysoev.ru } 333771Sigor@sysoev.ru 334771Sigor@sysoev.ru ret = rt->tls->library_init(task); 335771Sigor@sysoev.ru if (nxt_slow_path(ret != NXT_OK)) { 336771Sigor@sysoev.ru return ret; 337771Sigor@sysoev.ru } 338771Sigor@sysoev.ru #endif 339771Sigor@sysoev.ru 340431Sigor@sysoev.ru ret = nxt_http_init(task, rt); 34188Smax.romanov@nginx.com if (nxt_slow_path(ret != NXT_OK)) { 34288Smax.romanov@nginx.com return ret; 34388Smax.romanov@nginx.com } 34488Smax.romanov@nginx.com 34553Sigor@sysoev.ru router = nxt_zalloc(sizeof(nxt_router_t)); 34653Sigor@sysoev.ru if (nxt_slow_path(router == NULL)) { 34753Sigor@sysoev.ru return NXT_ERROR; 34853Sigor@sysoev.ru } 34953Sigor@sysoev.ru 35053Sigor@sysoev.ru nxt_queue_init(&router->engines); 35153Sigor@sysoev.ru nxt_queue_init(&router->sockets); 352133Sigor@sysoev.ru nxt_queue_init(&router->apps); 35353Sigor@sysoev.ru 354119Smax.romanov@nginx.com nxt_router = router; 355119Smax.romanov@nginx.com 356662Smax.romanov@nginx.com controller_port = rt->port_by_type[NXT_PROCESS_CONTROLLER]; 357662Smax.romanov@nginx.com if (controller_port != NULL) { 358662Smax.romanov@nginx.com nxt_router_greet_controller(task, controller_port); 359662Smax.romanov@nginx.com } 360662Smax.romanov@nginx.com 361115Sigor@sysoev.ru return NXT_OK; 362115Sigor@sysoev.ru } 363115Sigor@sysoev.ru 364115Sigor@sysoev.ru 365343Smax.romanov@nginx.com static void 366662Smax.romanov@nginx.com nxt_router_greet_controller(nxt_task_t *task, nxt_port_t *controller_port) 367662Smax.romanov@nginx.com { 368662Smax.romanov@nginx.com nxt_port_socket_write(task, controller_port, NXT_PORT_MSG_PROCESS_READY, 369662Smax.romanov@nginx.com -1, 0, 0, NULL); 370662Smax.romanov@nginx.com } 371662Smax.romanov@nginx.com 372662Smax.romanov@nginx.com 373662Smax.romanov@nginx.com static void 374507Smax.romanov@nginx.com nxt_router_start_app_process_handler(nxt_task_t *task, nxt_port_t *port, 375507Smax.romanov@nginx.com void *data) 376167Smax.romanov@nginx.com { 377343Smax.romanov@nginx.com size_t size; 378343Smax.romanov@nginx.com uint32_t stream; 379430Sigor@sysoev.ru nxt_mp_t *mp; 380648Svbart@nginx.com nxt_int_t ret; 381343Smax.romanov@nginx.com nxt_app_t *app; 382343Smax.romanov@nginx.com nxt_buf_t *b; 383343Smax.romanov@nginx.com nxt_port_t *main_port; 384343Smax.romanov@nginx.com nxt_runtime_t *rt; 385343Smax.romanov@nginx.com 386343Smax.romanov@nginx.com app = data; 387167Smax.romanov@nginx.com 388167Smax.romanov@nginx.com rt = task->thread->runtime; 389240Sigor@sysoev.ru main_port = rt->port_by_type[NXT_PROCESS_MAIN]; 390167Smax.romanov@nginx.com 391507Smax.romanov@nginx.com nxt_debug(task, "app '%V' %p start process", &app->name, app); 392343Smax.romanov@nginx.com 393343Smax.romanov@nginx.com size = app->name.length + 1 + app->conf.length; 394343Smax.romanov@nginx.com 395343Smax.romanov@nginx.com b = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool, size); 396343Smax.romanov@nginx.com 397343Smax.romanov@nginx.com if (nxt_slow_path(b == NULL)) { 398343Smax.romanov@nginx.com goto failed; 399167Smax.romanov@nginx.com } 400167Smax.romanov@nginx.com 401343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->name); 402343Smax.romanov@nginx.com *b->mem.free++ = '\0'; 403343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->conf); 404343Smax.romanov@nginx.com 405753Smax.romanov@nginx.com nxt_router_app_joint_use(task, app->joint, 1); 406753Smax.romanov@nginx.com 407343Smax.romanov@nginx.com stream = nxt_port_rpc_register_handler(task, port, 408343Smax.romanov@nginx.com nxt_router_app_port_ready, 409343Smax.romanov@nginx.com nxt_router_app_port_error, 410753Smax.romanov@nginx.com -1, app->joint); 411343Smax.romanov@nginx.com 412343Smax.romanov@nginx.com if (nxt_slow_path(stream == 0)) { 413753Smax.romanov@nginx.com nxt_router_app_joint_use(task, app->joint, -1); 414753Smax.romanov@nginx.com 415343Smax.romanov@nginx.com goto failed; 416343Smax.romanov@nginx.com } 417343Smax.romanov@nginx.com 418648Svbart@nginx.com ret = nxt_port_socket_write(task, main_port, NXT_PORT_MSG_START_WORKER, -1, 419648Svbart@nginx.com stream, port->id, b); 420648Svbart@nginx.com 421648Svbart@nginx.com if (nxt_slow_path(ret != NXT_OK)) { 422648Svbart@nginx.com nxt_port_rpc_cancel(task, port, stream); 423753Smax.romanov@nginx.com 424753Smax.romanov@nginx.com nxt_router_app_joint_use(task, app->joint, -1); 425753Smax.romanov@nginx.com 426648Svbart@nginx.com goto failed; 427648Svbart@nginx.com } 428343Smax.romanov@nginx.com 429753Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 430753Smax.romanov@nginx.com 431343Smax.romanov@nginx.com return; 432343Smax.romanov@nginx.com 433343Smax.romanov@nginx.com failed: 434343Smax.romanov@nginx.com 435648Svbart@nginx.com if (b != NULL) { 436648Svbart@nginx.com mp = b->data; 437648Svbart@nginx.com nxt_mp_free(mp, b); 438648Svbart@nginx.com nxt_mp_release(mp); 439648Svbart@nginx.com } 440648Svbart@nginx.com 441343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 442343Smax.romanov@nginx.com 443507Smax.romanov@nginx.com app->pending_processes--; 444343Smax.romanov@nginx.com 445343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 446343Smax.romanov@nginx.com 447343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 448167Smax.romanov@nginx.com } 449167Smax.romanov@nginx.com 450167Smax.romanov@nginx.com 451753Smax.romanov@nginx.com static void 452753Smax.romanov@nginx.com nxt_router_app_joint_use(nxt_task_t *task, nxt_app_joint_t *app_joint, int i) 453753Smax.romanov@nginx.com { 454753Smax.romanov@nginx.com app_joint->use_count += i; 455753Smax.romanov@nginx.com 456753Smax.romanov@nginx.com if (app_joint->use_count == 0) { 457753Smax.romanov@nginx.com nxt_assert(app_joint->app == NULL); 458753Smax.romanov@nginx.com 459753Smax.romanov@nginx.com nxt_free(app_joint); 460753Smax.romanov@nginx.com } 461753Smax.romanov@nginx.com } 462753Smax.romanov@nginx.com 463753Smax.romanov@nginx.com 464343Smax.romanov@nginx.com static nxt_int_t 465507Smax.romanov@nginx.com nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app) 466141Smax.romanov@nginx.com { 467343Smax.romanov@nginx.com nxt_int_t res; 468343Smax.romanov@nginx.com nxt_port_t *router_port; 469343Smax.romanov@nginx.com nxt_runtime_t *rt; 470343Smax.romanov@nginx.com 471343Smax.romanov@nginx.com rt = task->thread->runtime; 472343Smax.romanov@nginx.com router_port = rt->port_by_type[NXT_PROCESS_ROUTER]; 473343Smax.romanov@nginx.com 474343Smax.romanov@nginx.com nxt_router_app_use(task, app, 1); 475343Smax.romanov@nginx.com 476507Smax.romanov@nginx.com res = nxt_port_post(task, router_port, nxt_router_start_app_process_handler, 477343Smax.romanov@nginx.com app); 478343Smax.romanov@nginx.com 479343Smax.romanov@nginx.com if (res == NXT_OK) { 480343Smax.romanov@nginx.com return res; 481318Smax.romanov@nginx.com } 482318Smax.romanov@nginx.com 483343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 484343Smax.romanov@nginx.com 485507Smax.romanov@nginx.com app->pending_processes--; 486343Smax.romanov@nginx.com 487343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 488343Smax.romanov@nginx.com 489343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 490343Smax.romanov@nginx.com 491343Smax.romanov@nginx.com return NXT_ERROR; 492318Smax.romanov@nginx.com } 493318Smax.romanov@nginx.com 494318Smax.romanov@nginx.com 495351Smax.romanov@nginx.com nxt_inline void 496351Smax.romanov@nginx.com nxt_router_ra_init(nxt_task_t *task, nxt_req_app_link_t *ra, 497351Smax.romanov@nginx.com nxt_req_conn_link_t *rc) 498167Smax.romanov@nginx.com { 499318Smax.romanov@nginx.com nxt_event_engine_t *engine; 500351Smax.romanov@nginx.com 501318Smax.romanov@nginx.com engine = task->thread->engine; 502167Smax.romanov@nginx.com 503167Smax.romanov@nginx.com nxt_memzero(ra, sizeof(nxt_req_app_link_t)); 504167Smax.romanov@nginx.com 505318Smax.romanov@nginx.com ra->stream = rc->stream; 506425Smax.romanov@nginx.com ra->use_count = 1; 507167Smax.romanov@nginx.com ra->rc = rc; 508318Smax.romanov@nginx.com rc->ra = ra; 509318Smax.romanov@nginx.com ra->reply_port = engine->port; 510*1007Salexander.borisov@nginx.com ra->request = rc->request; 511167Smax.romanov@nginx.com 512167Smax.romanov@nginx.com ra->work.handler = NULL; 513318Smax.romanov@nginx.com ra->work.task = &engine->task; 514167Smax.romanov@nginx.com ra->work.obj = ra; 515318Smax.romanov@nginx.com ra->work.data = engine; 516351Smax.romanov@nginx.com } 517351Smax.romanov@nginx.com 518351Smax.romanov@nginx.com 519351Smax.romanov@nginx.com nxt_inline nxt_req_app_link_t * 520351Smax.romanov@nginx.com nxt_router_ra_create(nxt_task_t *task, nxt_req_app_link_t *ra_src) 521351Smax.romanov@nginx.com { 522351Smax.romanov@nginx.com nxt_mp_t *mp; 523351Smax.romanov@nginx.com nxt_req_app_link_t *ra; 524351Smax.romanov@nginx.com 525425Smax.romanov@nginx.com if (ra_src->mem_pool != NULL) { 526425Smax.romanov@nginx.com return ra_src; 527425Smax.romanov@nginx.com } 528425Smax.romanov@nginx.com 529*1007Salexander.borisov@nginx.com mp = ra_src->request->mem_pool; 530351Smax.romanov@nginx.com 531430Sigor@sysoev.ru ra = nxt_mp_alloc(mp, sizeof(nxt_req_app_link_t)); 532351Smax.romanov@nginx.com 533351Smax.romanov@nginx.com if (nxt_slow_path(ra == NULL)) { 534351Smax.romanov@nginx.com 535351Smax.romanov@nginx.com ra_src->rc->ra = NULL; 536351Smax.romanov@nginx.com ra_src->rc = NULL; 537351Smax.romanov@nginx.com 538351Smax.romanov@nginx.com return NULL; 539351Smax.romanov@nginx.com } 540351Smax.romanov@nginx.com 541430Sigor@sysoev.ru nxt_mp_retain(mp); 542430Sigor@sysoev.ru 543351Smax.romanov@nginx.com nxt_router_ra_init(task, ra, ra_src->rc); 544351Smax.romanov@nginx.com 545351Smax.romanov@nginx.com ra->mem_pool = mp; 546167Smax.romanov@nginx.com 547167Smax.romanov@nginx.com return ra; 548167Smax.romanov@nginx.com } 549167Smax.romanov@nginx.com 550167Smax.romanov@nginx.com 551423Smax.romanov@nginx.com nxt_inline nxt_bool_t 552423Smax.romanov@nginx.com nxt_router_msg_cancel(nxt_task_t *task, nxt_msg_info_t *msg_info, 553423Smax.romanov@nginx.com uint32_t stream) 554423Smax.romanov@nginx.com { 555423Smax.romanov@nginx.com nxt_buf_t *b, *next; 556423Smax.romanov@nginx.com nxt_bool_t cancelled; 557423Smax.romanov@nginx.com 558423Smax.romanov@nginx.com if (msg_info->buf == NULL) { 559423Smax.romanov@nginx.com return 0; 560423Smax.romanov@nginx.com } 561423Smax.romanov@nginx.com 562423Smax.romanov@nginx.com cancelled = nxt_port_mmap_tracking_cancel(task, &msg_info->tracking, 563423Smax.romanov@nginx.com stream); 564423Smax.romanov@nginx.com 565423Smax.romanov@nginx.com if (cancelled) { 566423Smax.romanov@nginx.com nxt_debug(task, "stream #%uD: cancelled by router", stream); 567423Smax.romanov@nginx.com } 568423Smax.romanov@nginx.com 569423Smax.romanov@nginx.com for (b = msg_info->buf; b != NULL; b = next) { 570423Smax.romanov@nginx.com next = b->next; 571423Smax.romanov@nginx.com 572423Smax.romanov@nginx.com b->completion_handler = msg_info->completion_handler; 573423Smax.romanov@nginx.com 574423Smax.romanov@nginx.com if (b->is_port_mmap_sent) { 575423Smax.romanov@nginx.com b->is_port_mmap_sent = cancelled == 0; 576423Smax.romanov@nginx.com b->completion_handler(task, b, b->parent); 577423Smax.romanov@nginx.com } 578423Smax.romanov@nginx.com } 579423Smax.romanov@nginx.com 580423Smax.romanov@nginx.com msg_info->buf = NULL; 581423Smax.romanov@nginx.com 582423Smax.romanov@nginx.com return cancelled; 583423Smax.romanov@nginx.com } 584423Smax.romanov@nginx.com 585423Smax.romanov@nginx.com 586167Smax.romanov@nginx.com static void 587425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra); 588425Smax.romanov@nginx.com 589425Smax.romanov@nginx.com 590425Smax.romanov@nginx.com static void 591425Smax.romanov@nginx.com nxt_router_ra_update_peer_handler(nxt_task_t *task, void *obj, void *data) 592167Smax.romanov@nginx.com { 593425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 594425Smax.romanov@nginx.com 595425Smax.romanov@nginx.com ra = obj; 596425Smax.romanov@nginx.com 597425Smax.romanov@nginx.com nxt_router_ra_update_peer(task, ra); 598425Smax.romanov@nginx.com 599425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 600425Smax.romanov@nginx.com } 601425Smax.romanov@nginx.com 602425Smax.romanov@nginx.com 603425Smax.romanov@nginx.com static void 604425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra) 605425Smax.romanov@nginx.com { 606343Smax.romanov@nginx.com nxt_event_engine_t *engine; 607343Smax.romanov@nginx.com nxt_req_conn_link_t *rc; 608318Smax.romanov@nginx.com 609425Smax.romanov@nginx.com engine = ra->work.data; 610318Smax.romanov@nginx.com 611343Smax.romanov@nginx.com if (task->thread->engine != engine) { 612425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 613425Smax.romanov@nginx.com 614425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_update_peer_handler; 615318Smax.romanov@nginx.com ra->work.task = &engine->task; 616318Smax.romanov@nginx.com ra->work.next = NULL; 617318Smax.romanov@nginx.com 618425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post update peer to %p", 619318Smax.romanov@nginx.com ra->stream, engine); 620318Smax.romanov@nginx.com 621318Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 622318Smax.romanov@nginx.com 623318Smax.romanov@nginx.com return; 624318Smax.romanov@nginx.com } 625318Smax.romanov@nginx.com 626425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD update peer", ra->stream); 627425Smax.romanov@nginx.com 628425Smax.romanov@nginx.com rc = ra->rc; 629425Smax.romanov@nginx.com 630425Smax.romanov@nginx.com if (rc != NULL && ra->app_port != NULL) { 631425Smax.romanov@nginx.com nxt_port_rpc_ex_set_peer(task, engine->port, rc, ra->app_port->pid); 632425Smax.romanov@nginx.com } 633425Smax.romanov@nginx.com 634425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 635425Smax.romanov@nginx.com } 636425Smax.romanov@nginx.com 637425Smax.romanov@nginx.com 638425Smax.romanov@nginx.com static void 639425Smax.romanov@nginx.com nxt_router_ra_release(nxt_task_t *task, nxt_req_app_link_t *ra) 640425Smax.romanov@nginx.com { 641431Sigor@sysoev.ru nxt_mp_t *mp; 642431Sigor@sysoev.ru nxt_req_conn_link_t *rc; 643425Smax.romanov@nginx.com 644425Smax.romanov@nginx.com nxt_assert(task->thread->engine == ra->work.data); 645425Smax.romanov@nginx.com nxt_assert(ra->use_count == 0); 646425Smax.romanov@nginx.com 647343Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD release", ra->stream); 648343Smax.romanov@nginx.com 649343Smax.romanov@nginx.com rc = ra->rc; 650343Smax.romanov@nginx.com 651343Smax.romanov@nginx.com if (rc != NULL) { 652423Smax.romanov@nginx.com if (nxt_slow_path(ra->err_code != 0)) { 653*1007Salexander.borisov@nginx.com nxt_http_request_error(task, rc->request, ra->err_code); 654423Smax.romanov@nginx.com 655423Smax.romanov@nginx.com } else { 656423Smax.romanov@nginx.com rc->app_port = ra->app_port; 657423Smax.romanov@nginx.com rc->msg_info = ra->msg_info; 658423Smax.romanov@nginx.com 659425Smax.romanov@nginx.com if (rc->app->timeout != 0) { 660*1007Salexander.borisov@nginx.com rc->request->timer.handler = nxt_router_app_timeout; 661*1007Salexander.borisov@nginx.com rc->request->timer_data = rc; 662*1007Salexander.borisov@nginx.com nxt_timer_add(task->thread->engine, &rc->request->timer, 663425Smax.romanov@nginx.com rc->app->timeout); 664425Smax.romanov@nginx.com } 665425Smax.romanov@nginx.com 666423Smax.romanov@nginx.com ra->app_port = NULL; 667423Smax.romanov@nginx.com ra->msg_info.buf = NULL; 668423Smax.romanov@nginx.com } 669343Smax.romanov@nginx.com 670343Smax.romanov@nginx.com rc->ra = NULL; 671343Smax.romanov@nginx.com ra->rc = NULL; 672343Smax.romanov@nginx.com } 673343Smax.romanov@nginx.com 674343Smax.romanov@nginx.com if (ra->app_port != NULL) { 675343Smax.romanov@nginx.com nxt_router_app_port_release(task, ra->app_port, 0, 1); 676343Smax.romanov@nginx.com 677343Smax.romanov@nginx.com ra->app_port = NULL; 678167Smax.romanov@nginx.com } 679167Smax.romanov@nginx.com 680423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &ra->msg_info, ra->stream); 681423Smax.romanov@nginx.com 682430Sigor@sysoev.ru mp = ra->mem_pool; 683430Sigor@sysoev.ru 684430Sigor@sysoev.ru if (mp != NULL) { 685430Sigor@sysoev.ru nxt_mp_free(mp, ra); 686430Sigor@sysoev.ru nxt_mp_release(mp); 687351Smax.romanov@nginx.com } 688167Smax.romanov@nginx.com } 689167Smax.romanov@nginx.com 690167Smax.romanov@nginx.com 691425Smax.romanov@nginx.com static void 692425Smax.romanov@nginx.com nxt_router_ra_release_handler(nxt_task_t *task, void *obj, void *data) 693425Smax.romanov@nginx.com { 694425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 695425Smax.romanov@nginx.com 696425Smax.romanov@nginx.com ra = obj; 697425Smax.romanov@nginx.com 698425Smax.romanov@nginx.com nxt_assert(ra->work.data == data); 699425Smax.romanov@nginx.com 700425Smax.romanov@nginx.com nxt_atomic_fetch_add(&ra->use_count, -1); 701425Smax.romanov@nginx.com 702425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 703425Smax.romanov@nginx.com } 704425Smax.romanov@nginx.com 705425Smax.romanov@nginx.com 706425Smax.romanov@nginx.com static void 707425Smax.romanov@nginx.com nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i) 708425Smax.romanov@nginx.com { 709425Smax.romanov@nginx.com int c; 710425Smax.romanov@nginx.com nxt_event_engine_t *engine; 711425Smax.romanov@nginx.com 712425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, i); 713425Smax.romanov@nginx.com 714425Smax.romanov@nginx.com if (i < 0 && c == -i) { 715425Smax.romanov@nginx.com engine = ra->work.data; 716425Smax.romanov@nginx.com 717425Smax.romanov@nginx.com if (task->thread->engine == engine) { 718425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 719425Smax.romanov@nginx.com 720425Smax.romanov@nginx.com return; 721425Smax.romanov@nginx.com } 722425Smax.romanov@nginx.com 723425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 724425Smax.romanov@nginx.com 725425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_release_handler; 726425Smax.romanov@nginx.com ra->work.task = &engine->task; 727425Smax.romanov@nginx.com ra->work.next = NULL; 728425Smax.romanov@nginx.com 729425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post release to %p", 730425Smax.romanov@nginx.com ra->stream, engine); 731425Smax.romanov@nginx.com 732425Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 733425Smax.romanov@nginx.com } 734425Smax.romanov@nginx.com } 735425Smax.romanov@nginx.com 736425Smax.romanov@nginx.com 737423Smax.romanov@nginx.com nxt_inline void 738521Szelenkov@nginx.com nxt_router_ra_error(nxt_req_app_link_t *ra, int code, const char *str) 739345Smax.romanov@nginx.com { 740423Smax.romanov@nginx.com ra->app_port = NULL; 741423Smax.romanov@nginx.com ra->err_code = code; 742423Smax.romanov@nginx.com ra->err_str = str; 743345Smax.romanov@nginx.com } 744345Smax.romanov@nginx.com 745345Smax.romanov@nginx.com 746427Smax.romanov@nginx.com nxt_inline void 747427Smax.romanov@nginx.com nxt_router_ra_pending(nxt_task_t *task, nxt_app_t *app, nxt_req_app_link_t *ra) 748427Smax.romanov@nginx.com { 749427Smax.romanov@nginx.com nxt_queue_insert_tail(&ra->app_port->pending_requests, 750427Smax.romanov@nginx.com &ra->link_port_pending); 751427Smax.romanov@nginx.com nxt_queue_insert_tail(&app->pending, &ra->link_app_pending); 752427Smax.romanov@nginx.com 753427Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 754427Smax.romanov@nginx.com 755427Smax.romanov@nginx.com ra->res_time = nxt_thread_monotonic_time(task->thread) + app->res_timeout; 756427Smax.romanov@nginx.com 757427Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD enqueue to pending_requests", ra->stream); 758427Smax.romanov@nginx.com } 759427Smax.romanov@nginx.com 760427Smax.romanov@nginx.com 761425Smax.romanov@nginx.com nxt_inline nxt_bool_t 762425Smax.romanov@nginx.com nxt_queue_chk_remove(nxt_queue_link_t *lnk) 763425Smax.romanov@nginx.com { 764425Smax.romanov@nginx.com if (lnk->next != NULL) { 765425Smax.romanov@nginx.com nxt_queue_remove(lnk); 766425Smax.romanov@nginx.com 767425Smax.romanov@nginx.com lnk->next = NULL; 768425Smax.romanov@nginx.com 769425Smax.romanov@nginx.com return 1; 770425Smax.romanov@nginx.com } 771425Smax.romanov@nginx.com 772425Smax.romanov@nginx.com return 0; 773425Smax.romanov@nginx.com } 774425Smax.romanov@nginx.com 775425Smax.romanov@nginx.com 776343Smax.romanov@nginx.com nxt_inline void 777343Smax.romanov@nginx.com nxt_router_rc_unlink(nxt_task_t *task, nxt_req_conn_link_t *rc) 778343Smax.romanov@nginx.com { 779425Smax.romanov@nginx.com int ra_use_delta; 780343Smax.romanov@nginx.com nxt_req_app_link_t *ra; 781343Smax.romanov@nginx.com 782343Smax.romanov@nginx.com if (rc->app_port != NULL) { 783343Smax.romanov@nginx.com nxt_router_app_port_release(task, rc->app_port, 0, 1); 784343Smax.romanov@nginx.com 785343Smax.romanov@nginx.com rc->app_port = NULL; 786343Smax.romanov@nginx.com } 787343Smax.romanov@nginx.com 788423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &rc->msg_info, rc->stream); 789423Smax.romanov@nginx.com 790343Smax.romanov@nginx.com ra = rc->ra; 791343Smax.romanov@nginx.com 792343Smax.romanov@nginx.com if (ra != NULL) { 793343Smax.romanov@nginx.com rc->ra = NULL; 794