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 { 34133Sigor@sysoev.ru nxt_str_t application; 35115Sigor@sysoev.ru } nxt_router_listener_conf_t; 36115Sigor@sysoev.ru 37115Sigor@sysoev.ru 38774Svbart@nginx.com #if (NXT_TLS) 39774Svbart@nginx.com 40774Svbart@nginx.com typedef struct { 41774Svbart@nginx.com nxt_str_t name; 42774Svbart@nginx.com nxt_socket_conf_t *conf; 43774Svbart@nginx.com 44774Svbart@nginx.com nxt_queue_link_t link; /* for nxt_socket_conf_t.tls */ 45774Svbart@nginx.com } nxt_router_tlssock_t; 46774Svbart@nginx.com 47774Svbart@nginx.com #endif 48774Svbart@nginx.com 49774Svbart@nginx.com 50423Smax.romanov@nginx.com typedef struct nxt_msg_info_s { 51423Smax.romanov@nginx.com nxt_buf_t *buf; 52423Smax.romanov@nginx.com nxt_port_mmap_tracking_t tracking; 53423Smax.romanov@nginx.com nxt_work_handler_t completion_handler; 54423Smax.romanov@nginx.com } nxt_msg_info_t; 55423Smax.romanov@nginx.com 56423Smax.romanov@nginx.com 57167Smax.romanov@nginx.com typedef struct nxt_req_app_link_s nxt_req_app_link_t; 58141Smax.romanov@nginx.com 59141Smax.romanov@nginx.com 60318Smax.romanov@nginx.com typedef struct { 61431Sigor@sysoev.ru uint32_t stream; 62431Sigor@sysoev.ru nxt_app_t *app; 63431Sigor@sysoev.ru nxt_port_t *app_port; 64431Sigor@sysoev.ru nxt_app_parse_ctx_t *ap; 65431Sigor@sysoev.ru nxt_msg_info_t msg_info; 66431Sigor@sysoev.ru nxt_req_app_link_t *ra; 67431Sigor@sysoev.ru 68431Sigor@sysoev.ru nxt_queue_link_t link; /* for nxt_conn_t.requests */ 69318Smax.romanov@nginx.com } nxt_req_conn_link_t; 70318Smax.romanov@nginx.com 71318Smax.romanov@nginx.com 72167Smax.romanov@nginx.com struct nxt_req_app_link_s { 73318Smax.romanov@nginx.com uint32_t stream; 74425Smax.romanov@nginx.com nxt_atomic_t use_count; 75167Smax.romanov@nginx.com nxt_port_t *app_port; 76167Smax.romanov@nginx.com nxt_port_t *reply_port; 77167Smax.romanov@nginx.com nxt_app_parse_ctx_t *ap; 78423Smax.romanov@nginx.com nxt_msg_info_t msg_info; 79167Smax.romanov@nginx.com nxt_req_conn_link_t *rc; 80167Smax.romanov@nginx.com 81427Smax.romanov@nginx.com nxt_nsec_t res_time; 82427Smax.romanov@nginx.com 83425Smax.romanov@nginx.com nxt_queue_link_t link_app_requests; /* for nxt_app_t.requests */ 84425Smax.romanov@nginx.com nxt_queue_link_t link_port_pending; /* for nxt_port_t.pending_requests */ 85427Smax.romanov@nginx.com nxt_queue_link_t link_app_pending; /* for nxt_app_t.pending */ 86167Smax.romanov@nginx.com 87167Smax.romanov@nginx.com nxt_mp_t *mem_pool; 88167Smax.romanov@nginx.com nxt_work_t work; 89345Smax.romanov@nginx.com 90345Smax.romanov@nginx.com int err_code; 91345Smax.romanov@nginx.com const char *err_str; 92167Smax.romanov@nginx.com }; 93167Smax.romanov@nginx.com 94167Smax.romanov@nginx.com 95198Sigor@sysoev.ru typedef struct { 96198Sigor@sysoev.ru nxt_socket_conf_t *socket_conf; 97198Sigor@sysoev.ru nxt_router_temp_conf_t *temp_conf; 98198Sigor@sysoev.ru } nxt_socket_rpc_t; 99198Sigor@sysoev.ru 100198Sigor@sysoev.ru 101507Smax.romanov@nginx.com typedef struct { 102507Smax.romanov@nginx.com nxt_app_t *app; 103507Smax.romanov@nginx.com nxt_router_temp_conf_t *temp_conf; 104507Smax.romanov@nginx.com } nxt_app_rpc_t; 105507Smax.romanov@nginx.com 106507Smax.romanov@nginx.com 107427Smax.romanov@nginx.com struct nxt_port_select_state_s { 108427Smax.romanov@nginx.com nxt_app_t *app; 109427Smax.romanov@nginx.com nxt_req_app_link_t *ra; 110427Smax.romanov@nginx.com 111427Smax.romanov@nginx.com nxt_port_t *failed_port; 112427Smax.romanov@nginx.com int failed_port_use_delta; 113427Smax.romanov@nginx.com 114507Smax.romanov@nginx.com uint8_t start_process; /* 1 bit */ 115427Smax.romanov@nginx.com nxt_req_app_link_t *shared_ra; 116427Smax.romanov@nginx.com nxt_port_t *port; 117427Smax.romanov@nginx.com }; 118427Smax.romanov@nginx.com 119427Smax.romanov@nginx.com typedef struct nxt_port_select_state_s nxt_port_select_state_t; 120427Smax.romanov@nginx.com 121662Smax.romanov@nginx.com static void nxt_router_greet_controller(nxt_task_t *task, 122662Smax.romanov@nginx.com nxt_port_t *controller_port); 123662Smax.romanov@nginx.com 124427Smax.romanov@nginx.com static void nxt_router_port_select(nxt_task_t *task, 125427Smax.romanov@nginx.com nxt_port_select_state_t *state); 126427Smax.romanov@nginx.com 127427Smax.romanov@nginx.com static nxt_int_t nxt_router_port_post_select(nxt_task_t *task, 128427Smax.romanov@nginx.com nxt_port_select_state_t *state); 129427Smax.romanov@nginx.com 130507Smax.romanov@nginx.com static nxt_int_t nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app); 131343Smax.romanov@nginx.com 132425Smax.romanov@nginx.com nxt_inline void 133425Smax.romanov@nginx.com nxt_router_ra_inc_use(nxt_req_app_link_t *ra) 134425Smax.romanov@nginx.com { 135425Smax.romanov@nginx.com nxt_atomic_fetch_add(&ra->use_count, 1); 136425Smax.romanov@nginx.com } 137425Smax.romanov@nginx.com 138425Smax.romanov@nginx.com nxt_inline void 139425Smax.romanov@nginx.com nxt_router_ra_dec_use(nxt_req_app_link_t *ra) 140425Smax.romanov@nginx.com { 141538Svbart@nginx.com #if (NXT_DEBUG) 142425Smax.romanov@nginx.com int c; 143425Smax.romanov@nginx.com 144425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, -1); 145425Smax.romanov@nginx.com 146425Smax.romanov@nginx.com nxt_assert(c > 1); 147538Svbart@nginx.com #else 148538Svbart@nginx.com (void) nxt_atomic_fetch_add(&ra->use_count, -1); 149538Svbart@nginx.com #endif 150425Smax.romanov@nginx.com } 151425Smax.romanov@nginx.com 152425Smax.romanov@nginx.com static void nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i); 153425Smax.romanov@nginx.com 154139Sigor@sysoev.ru static nxt_router_temp_conf_t *nxt_router_temp_conf(nxt_task_t *task); 155198Sigor@sysoev.ru static void nxt_router_conf_apply(nxt_task_t *task, void *obj, void *data); 156198Sigor@sysoev.ru static void nxt_router_conf_ready(nxt_task_t *task, 157139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 158139Sigor@sysoev.ru static void nxt_router_conf_error(nxt_task_t *task, 159139Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 160139Sigor@sysoev.ru static void nxt_router_conf_send(nxt_task_t *task, 161193Smax.romanov@nginx.com nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type); 16253Sigor@sysoev.ru 163115Sigor@sysoev.ru static nxt_int_t nxt_router_conf_create(nxt_task_t *task, 164115Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, u_char *start, u_char *end); 165133Sigor@sysoev.ru static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name); 166133Sigor@sysoev.ru static nxt_app_t *nxt_router_listener_application(nxt_router_temp_conf_t *tmcf, 167133Sigor@sysoev.ru nxt_str_t *name); 168198Sigor@sysoev.ru static void nxt_router_listen_socket_rpc_create(nxt_task_t *task, 169198Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, nxt_socket_conf_t *skcf); 170198Sigor@sysoev.ru static void nxt_router_listen_socket_ready(nxt_task_t *task, 171198Sigor@sysoev.ru nxt_port_recv_msg_t *msg, void *data); 172198Sigor@sysoev.ru static void nxt_router_listen_socket_error(nxt_task_t *task, 173198Sigor@sysoev.ru nxt_port_recv_msg_t *msg, void *data); 174774Svbart@nginx.com #if (NXT_TLS) 175774Svbart@nginx.com static void nxt_router_tls_rpc_create(nxt_task_t *task, 176774Svbart@nginx.com nxt_router_temp_conf_t *tmcf, nxt_router_tlssock_t *tls); 177774Svbart@nginx.com static void nxt_router_tls_rpc_handler(nxt_task_t *task, 178774Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 179774Svbart@nginx.com #endif 180507Smax.romanov@nginx.com static void nxt_router_app_rpc_create(nxt_task_t *task, 181507Smax.romanov@nginx.com nxt_router_temp_conf_t *tmcf, nxt_app_t *app); 182507Smax.romanov@nginx.com static void nxt_router_app_prefork_ready(nxt_task_t *task, 183507Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 184507Smax.romanov@nginx.com static void nxt_router_app_prefork_error(nxt_task_t *task, 185507Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 186359Sigor@sysoev.ru static nxt_socket_conf_t *nxt_router_socket_conf(nxt_task_t *task, 187359Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf, nxt_str_t *name); 188359Sigor@sysoev.ru static nxt_int_t nxt_router_listen_socket_find(nxt_router_temp_conf_t *tmcf, 189359Sigor@sysoev.ru nxt_socket_conf_t *nskcf, nxt_sockaddr_t *sa); 19053Sigor@sysoev.ru 19153Sigor@sysoev.ru static nxt_int_t nxt_router_engines_create(nxt_task_t *task, 19253Sigor@sysoev.ru nxt_router_t *router, nxt_router_temp_conf_t *tmcf, 19353Sigor@sysoev.ru const nxt_event_interface_t *interface); 194115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_create(nxt_router_temp_conf_t *tmcf, 195115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 196115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_update(nxt_router_temp_conf_t *tmcf, 197115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 198115Sigor@sysoev.ru static nxt_int_t nxt_router_engine_conf_delete(nxt_router_temp_conf_t *tmcf, 199115Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 200154Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_create(nxt_router_temp_conf_t *tmcf, 201154Sigor@sysoev.ru nxt_router_engine_conf_t *recf, nxt_queue_t *sockets, 202154Sigor@sysoev.ru nxt_work_handler_t handler); 203313Sigor@sysoev.ru static nxt_int_t nxt_router_engine_quit(nxt_router_temp_conf_t *tmcf, 204313Sigor@sysoev.ru nxt_router_engine_conf_t *recf); 205139Sigor@sysoev.ru static nxt_int_t nxt_router_engine_joints_delete(nxt_router_temp_conf_t *tmcf, 206139Sigor@sysoev.ru nxt_router_engine_conf_t *recf, nxt_queue_t *sockets); 20753Sigor@sysoev.ru 20853Sigor@sysoev.ru static nxt_int_t nxt_router_threads_create(nxt_task_t *task, nxt_runtime_t *rt, 20953Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 21053Sigor@sysoev.ru static nxt_int_t nxt_router_thread_create(nxt_task_t *task, nxt_runtime_t *rt, 21153Sigor@sysoev.ru nxt_event_engine_t *engine); 212343Smax.romanov@nginx.com static void nxt_router_apps_sort(nxt_task_t *task, nxt_router_t *router, 213133Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 21453Sigor@sysoev.ru 215315Sigor@sysoev.ru static void nxt_router_engines_post(nxt_router_t *router, 216315Sigor@sysoev.ru nxt_router_temp_conf_t *tmcf); 217315Sigor@sysoev.ru static void nxt_router_engine_post(nxt_event_engine_t *engine, 218315Sigor@sysoev.ru nxt_work_t *jobs); 21953Sigor@sysoev.ru 22053Sigor@sysoev.ru static void nxt_router_thread_start(void *data); 22153Sigor@sysoev.ru static void nxt_router_listen_socket_create(nxt_task_t *task, void *obj, 22253Sigor@sysoev.ru void *data); 22353Sigor@sysoev.ru static void nxt_router_listen_socket_update(nxt_task_t *task, void *obj, 22453Sigor@sysoev.ru void *data); 22553Sigor@sysoev.ru static void nxt_router_listen_socket_delete(nxt_task_t *task, void *obj, 22653Sigor@sysoev.ru void *data); 227313Sigor@sysoev.ru static void nxt_router_worker_thread_quit(nxt_task_t *task, void *obj, 228313Sigor@sysoev.ru void *data); 22953Sigor@sysoev.ru static void nxt_router_listen_socket_close(nxt_task_t *task, void *obj, 23053Sigor@sysoev.ru void *data); 23153Sigor@sysoev.ru static void nxt_router_thread_exit_handler(nxt_task_t *task, void *obj, 23253Sigor@sysoev.ru void *data); 233359Sigor@sysoev.ru static void nxt_router_listen_socket_release(nxt_task_t *task, 234359Sigor@sysoev.ru nxt_socket_conf_t *skcf); 23553Sigor@sysoev.ru 236630Svbart@nginx.com static void nxt_router_access_log_writer(nxt_task_t *task, 237630Svbart@nginx.com nxt_http_request_t *r, nxt_router_access_log_t *access_log); 238630Svbart@nginx.com static u_char *nxt_router_access_log_date(u_char *buf, nxt_realtime_t *now, 239630Svbart@nginx.com struct tm *tm, size_t size, const char *format); 240630Svbart@nginx.com static void nxt_router_access_log_open(nxt_task_t *task, 241630Svbart@nginx.com nxt_router_temp_conf_t *tmcf); 242630Svbart@nginx.com static void nxt_router_access_log_ready(nxt_task_t *task, 243630Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 244630Svbart@nginx.com static void nxt_router_access_log_error(nxt_task_t *task, 245630Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 246630Svbart@nginx.com static void nxt_router_access_log_release(nxt_task_t *task, 247630Svbart@nginx.com nxt_thread_spinlock_t *lock, nxt_router_access_log_t *access_log); 248651Svbart@nginx.com static void nxt_router_access_log_reopen_completion(nxt_task_t *task, void *obj, 249651Svbart@nginx.com void *data); 250631Svbart@nginx.com static void nxt_router_access_log_reopen_ready(nxt_task_t *task, 251631Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 252631Svbart@nginx.com static void nxt_router_access_log_reopen_error(nxt_task_t *task, 253631Svbart@nginx.com nxt_port_recv_msg_t *msg, void *data); 254630Svbart@nginx.com 255343Smax.romanov@nginx.com static void nxt_router_app_port_ready(nxt_task_t *task, 256343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 257343Smax.romanov@nginx.com static void nxt_router_app_port_error(nxt_task_t *task, 258343Smax.romanov@nginx.com nxt_port_recv_msg_t *msg, void *data); 259343Smax.romanov@nginx.com 260753Smax.romanov@nginx.com static void nxt_router_app_unlink(nxt_task_t *task, nxt_app_t *app); 261343Smax.romanov@nginx.com static void nxt_router_app_port_release(nxt_task_t *task, nxt_port_t *port, 262343Smax.romanov@nginx.com uint32_t request_failed, uint32_t got_response); 263427Smax.romanov@nginx.com static nxt_int_t nxt_router_app_port(nxt_task_t *task, nxt_app_t *app, 264427Smax.romanov@nginx.com nxt_req_app_link_t *ra); 265141Smax.romanov@nginx.com 266425Smax.romanov@nginx.com static void nxt_router_app_prepare_request(nxt_task_t *task, 267343Smax.romanov@nginx.com nxt_req_app_link_t *ra); 268743Smax.romanov@nginx.com static nxt_buf_t *nxt_router_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, 269743Smax.romanov@nginx.com nxt_port_t *port, const nxt_str_t *prefix); 270510Salexander.borisov@nginx.com 271318Smax.romanov@nginx.com static void nxt_router_app_timeout(nxt_task_t *task, void *obj, void *data); 272507Smax.romanov@nginx.com static void nxt_router_adjust_idle_timer(nxt_task_t *task, void *obj, 273507Smax.romanov@nginx.com void *data); 274507Smax.romanov@nginx.com static void nxt_router_app_idle_timeout(nxt_task_t *task, void *obj, 275507Smax.romanov@nginx.com void *data); 276753Smax.romanov@nginx.com static void nxt_router_app_joint_release_handler(nxt_task_t *task, void *obj, 277507Smax.romanov@nginx.com void *data); 278753Smax.romanov@nginx.com static void nxt_router_free_app(nxt_task_t *task, void *obj, void *data); 279431Sigor@sysoev.ru 280431Sigor@sysoev.ru static const nxt_http_request_state_t nxt_http_request_send_state; 281431Sigor@sysoev.ru static void nxt_http_request_send_body(nxt_task_t *task, void *obj, void *data); 282141Smax.romanov@nginx.com 283753Smax.romanov@nginx.com static void nxt_router_app_joint_use(nxt_task_t *task, 284753Smax.romanov@nginx.com nxt_app_joint_t *app_joint, int i); 285753Smax.romanov@nginx.com 286119Smax.romanov@nginx.com static nxt_router_t *nxt_router; 28720Sigor@sysoev.ru 288743Smax.romanov@nginx.com static const nxt_str_t http_prefix = nxt_string("HTTP_"); 289743Smax.romanov@nginx.com static const nxt_str_t empty_prefix = nxt_string(""); 290743Smax.romanov@nginx.com 291743Smax.romanov@nginx.com static const nxt_str_t *nxt_app_msg_prefix[] = { 292*804Svbart@nginx.com &empty_prefix, 293743Smax.romanov@nginx.com &http_prefix, 294743Smax.romanov@nginx.com &http_prefix, 295743Smax.romanov@nginx.com &http_prefix, 296743Smax.romanov@nginx.com &http_prefix, 297216Sigor@sysoev.ru }; 298216Sigor@sysoev.ru 299216Sigor@sysoev.ru 300662Smax.romanov@nginx.com nxt_port_handlers_t nxt_router_process_port_handlers = { 301662Smax.romanov@nginx.com .quit = nxt_worker_process_quit_handler, 302662Smax.romanov@nginx.com .new_port = nxt_router_new_port_handler, 303662Smax.romanov@nginx.com .change_file = nxt_port_change_log_file_handler, 304662Smax.romanov@nginx.com .mmap = nxt_port_mmap_handler, 305662Smax.romanov@nginx.com .data = nxt_router_conf_data_handler, 306662Smax.romanov@nginx.com .remove_pid = nxt_router_remove_pid_handler, 307662Smax.romanov@nginx.com .access_log = nxt_router_access_log_reopen_handler, 308662Smax.romanov@nginx.com .rpc_ready = nxt_port_rpc_handler, 309662Smax.romanov@nginx.com .rpc_error = nxt_port_rpc_handler, 310662Smax.romanov@nginx.com }; 311662Smax.romanov@nginx.com 312662Smax.romanov@nginx.com 31320Sigor@sysoev.ru nxt_int_t 314141Smax.romanov@nginx.com nxt_router_start(nxt_task_t *task, void *data) 31520Sigor@sysoev.ru { 316141Smax.romanov@nginx.com nxt_int_t ret; 317662Smax.romanov@nginx.com nxt_port_t *controller_port; 318141Smax.romanov@nginx.com nxt_router_t *router; 319141Smax.romanov@nginx.com nxt_runtime_t *rt; 320141Smax.romanov@nginx.com 321141Smax.romanov@nginx.com rt = task->thread->runtime; 32253Sigor@sysoev.ru 323771Sigor@sysoev.ru #if (NXT_TLS) 324771Sigor@sysoev.ru rt->tls = nxt_service_get(rt->services, "SSL/TLS", "OpenSSL"); 325771Sigor@sysoev.ru if (nxt_slow_path(rt->tls == NULL)) { 326771Sigor@sysoev.ru return NXT_ERROR; 327771Sigor@sysoev.ru } 328771Sigor@sysoev.ru 329771Sigor@sysoev.ru ret = rt->tls->library_init(task); 330771Sigor@sysoev.ru if (nxt_slow_path(ret != NXT_OK)) { 331771Sigor@sysoev.ru return ret; 332771Sigor@sysoev.ru } 333771Sigor@sysoev.ru #endif 334771Sigor@sysoev.ru 335431Sigor@sysoev.ru ret = nxt_http_init(task, rt); 33688Smax.romanov@nginx.com if (nxt_slow_path(ret != NXT_OK)) { 33788Smax.romanov@nginx.com return ret; 33888Smax.romanov@nginx.com } 33988Smax.romanov@nginx.com 34053Sigor@sysoev.ru router = nxt_zalloc(sizeof(nxt_router_t)); 34153Sigor@sysoev.ru if (nxt_slow_path(router == NULL)) { 34253Sigor@sysoev.ru return NXT_ERROR; 34353Sigor@sysoev.ru } 34453Sigor@sysoev.ru 34553Sigor@sysoev.ru nxt_queue_init(&router->engines); 34653Sigor@sysoev.ru nxt_queue_init(&router->sockets); 347133Sigor@sysoev.ru nxt_queue_init(&router->apps); 34853Sigor@sysoev.ru 349119Smax.romanov@nginx.com nxt_router = router; 350119Smax.romanov@nginx.com 351662Smax.romanov@nginx.com controller_port = rt->port_by_type[NXT_PROCESS_CONTROLLER]; 352662Smax.romanov@nginx.com if (controller_port != NULL) { 353662Smax.romanov@nginx.com nxt_router_greet_controller(task, controller_port); 354662Smax.romanov@nginx.com } 355662Smax.romanov@nginx.com 356115Sigor@sysoev.ru return NXT_OK; 357115Sigor@sysoev.ru } 358115Sigor@sysoev.ru 359115Sigor@sysoev.ru 360343Smax.romanov@nginx.com static void 361662Smax.romanov@nginx.com nxt_router_greet_controller(nxt_task_t *task, nxt_port_t *controller_port) 362662Smax.romanov@nginx.com { 363662Smax.romanov@nginx.com nxt_port_socket_write(task, controller_port, NXT_PORT_MSG_PROCESS_READY, 364662Smax.romanov@nginx.com -1, 0, 0, NULL); 365662Smax.romanov@nginx.com } 366662Smax.romanov@nginx.com 367662Smax.romanov@nginx.com 368662Smax.romanov@nginx.com static void 369507Smax.romanov@nginx.com nxt_router_start_app_process_handler(nxt_task_t *task, nxt_port_t *port, 370507Smax.romanov@nginx.com void *data) 371167Smax.romanov@nginx.com { 372343Smax.romanov@nginx.com size_t size; 373343Smax.romanov@nginx.com uint32_t stream; 374430Sigor@sysoev.ru nxt_mp_t *mp; 375648Svbart@nginx.com nxt_int_t ret; 376343Smax.romanov@nginx.com nxt_app_t *app; 377343Smax.romanov@nginx.com nxt_buf_t *b; 378343Smax.romanov@nginx.com nxt_port_t *main_port; 379343Smax.romanov@nginx.com nxt_runtime_t *rt; 380343Smax.romanov@nginx.com 381343Smax.romanov@nginx.com app = data; 382167Smax.romanov@nginx.com 383167Smax.romanov@nginx.com rt = task->thread->runtime; 384240Sigor@sysoev.ru main_port = rt->port_by_type[NXT_PROCESS_MAIN]; 385167Smax.romanov@nginx.com 386507Smax.romanov@nginx.com nxt_debug(task, "app '%V' %p start process", &app->name, app); 387343Smax.romanov@nginx.com 388343Smax.romanov@nginx.com size = app->name.length + 1 + app->conf.length; 389343Smax.romanov@nginx.com 390343Smax.romanov@nginx.com b = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool, size); 391343Smax.romanov@nginx.com 392343Smax.romanov@nginx.com if (nxt_slow_path(b == NULL)) { 393343Smax.romanov@nginx.com goto failed; 394167Smax.romanov@nginx.com } 395167Smax.romanov@nginx.com 396343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->name); 397343Smax.romanov@nginx.com *b->mem.free++ = '\0'; 398343Smax.romanov@nginx.com nxt_buf_cpystr(b, &app->conf); 399343Smax.romanov@nginx.com 400753Smax.romanov@nginx.com nxt_router_app_joint_use(task, app->joint, 1); 401753Smax.romanov@nginx.com 402343Smax.romanov@nginx.com stream = nxt_port_rpc_register_handler(task, port, 403343Smax.romanov@nginx.com nxt_router_app_port_ready, 404343Smax.romanov@nginx.com nxt_router_app_port_error, 405753Smax.romanov@nginx.com -1, app->joint); 406343Smax.romanov@nginx.com 407343Smax.romanov@nginx.com if (nxt_slow_path(stream == 0)) { 408753Smax.romanov@nginx.com nxt_router_app_joint_use(task, app->joint, -1); 409753Smax.romanov@nginx.com 410343Smax.romanov@nginx.com goto failed; 411343Smax.romanov@nginx.com } 412343Smax.romanov@nginx.com 413648Svbart@nginx.com ret = nxt_port_socket_write(task, main_port, NXT_PORT_MSG_START_WORKER, -1, 414648Svbart@nginx.com stream, port->id, b); 415648Svbart@nginx.com 416648Svbart@nginx.com if (nxt_slow_path(ret != NXT_OK)) { 417648Svbart@nginx.com nxt_port_rpc_cancel(task, port, stream); 418753Smax.romanov@nginx.com 419753Smax.romanov@nginx.com nxt_router_app_joint_use(task, app->joint, -1); 420753Smax.romanov@nginx.com 421648Svbart@nginx.com goto failed; 422648Svbart@nginx.com } 423343Smax.romanov@nginx.com 424753Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 425753Smax.romanov@nginx.com 426343Smax.romanov@nginx.com return; 427343Smax.romanov@nginx.com 428343Smax.romanov@nginx.com failed: 429343Smax.romanov@nginx.com 430648Svbart@nginx.com if (b != NULL) { 431648Svbart@nginx.com mp = b->data; 432648Svbart@nginx.com nxt_mp_free(mp, b); 433648Svbart@nginx.com nxt_mp_release(mp); 434648Svbart@nginx.com } 435648Svbart@nginx.com 436343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 437343Smax.romanov@nginx.com 438507Smax.romanov@nginx.com app->pending_processes--; 439343Smax.romanov@nginx.com 440343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 441343Smax.romanov@nginx.com 442343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 443167Smax.romanov@nginx.com } 444167Smax.romanov@nginx.com 445167Smax.romanov@nginx.com 446753Smax.romanov@nginx.com static void 447753Smax.romanov@nginx.com nxt_router_app_joint_use(nxt_task_t *task, nxt_app_joint_t *app_joint, int i) 448753Smax.romanov@nginx.com { 449753Smax.romanov@nginx.com app_joint->use_count += i; 450753Smax.romanov@nginx.com 451753Smax.romanov@nginx.com if (app_joint->use_count == 0) { 452753Smax.romanov@nginx.com nxt_assert(app_joint->app == NULL); 453753Smax.romanov@nginx.com 454753Smax.romanov@nginx.com nxt_free(app_joint); 455753Smax.romanov@nginx.com } 456753Smax.romanov@nginx.com } 457753Smax.romanov@nginx.com 458753Smax.romanov@nginx.com 459343Smax.romanov@nginx.com static nxt_int_t 460507Smax.romanov@nginx.com nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app) 461141Smax.romanov@nginx.com { 462343Smax.romanov@nginx.com nxt_int_t res; 463343Smax.romanov@nginx.com nxt_port_t *router_port; 464343Smax.romanov@nginx.com nxt_runtime_t *rt; 465343Smax.romanov@nginx.com 466343Smax.romanov@nginx.com rt = task->thread->runtime; 467343Smax.romanov@nginx.com router_port = rt->port_by_type[NXT_PROCESS_ROUTER]; 468343Smax.romanov@nginx.com 469343Smax.romanov@nginx.com nxt_router_app_use(task, app, 1); 470343Smax.romanov@nginx.com 471507Smax.romanov@nginx.com res = nxt_port_post(task, router_port, nxt_router_start_app_process_handler, 472343Smax.romanov@nginx.com app); 473343Smax.romanov@nginx.com 474343Smax.romanov@nginx.com if (res == NXT_OK) { 475343Smax.romanov@nginx.com return res; 476318Smax.romanov@nginx.com } 477318Smax.romanov@nginx.com 478343Smax.romanov@nginx.com nxt_thread_mutex_lock(&app->mutex); 479343Smax.romanov@nginx.com 480507Smax.romanov@nginx.com app->pending_processes--; 481343Smax.romanov@nginx.com 482343Smax.romanov@nginx.com nxt_thread_mutex_unlock(&app->mutex); 483343Smax.romanov@nginx.com 484343Smax.romanov@nginx.com nxt_router_app_use(task, app, -1); 485343Smax.romanov@nginx.com 486343Smax.romanov@nginx.com return NXT_ERROR; 487318Smax.romanov@nginx.com } 488318Smax.romanov@nginx.com 489318Smax.romanov@nginx.com 490351Smax.romanov@nginx.com nxt_inline void 491351Smax.romanov@nginx.com nxt_router_ra_init(nxt_task_t *task, nxt_req_app_link_t *ra, 492351Smax.romanov@nginx.com nxt_req_conn_link_t *rc) 493167Smax.romanov@nginx.com { 494318Smax.romanov@nginx.com nxt_event_engine_t *engine; 495351Smax.romanov@nginx.com 496318Smax.romanov@nginx.com engine = task->thread->engine; 497167Smax.romanov@nginx.com 498167Smax.romanov@nginx.com nxt_memzero(ra, sizeof(nxt_req_app_link_t)); 499167Smax.romanov@nginx.com 500318Smax.romanov@nginx.com ra->stream = rc->stream; 501425Smax.romanov@nginx.com ra->use_count = 1; 502167Smax.romanov@nginx.com ra->rc = rc; 503318Smax.romanov@nginx.com rc->ra = ra; 504318Smax.romanov@nginx.com ra->reply_port = engine->port; 505351Smax.romanov@nginx.com ra->ap = rc->ap; 506167Smax.romanov@nginx.com 507167Smax.romanov@nginx.com ra->work.handler = NULL; 508318Smax.romanov@nginx.com ra->work.task = &engine->task; 509167Smax.romanov@nginx.com ra->work.obj = ra; 510318Smax.romanov@nginx.com ra->work.data = engine; 511351Smax.romanov@nginx.com } 512351Smax.romanov@nginx.com 513351Smax.romanov@nginx.com 514351Smax.romanov@nginx.com nxt_inline nxt_req_app_link_t * 515351Smax.romanov@nginx.com nxt_router_ra_create(nxt_task_t *task, nxt_req_app_link_t *ra_src) 516351Smax.romanov@nginx.com { 517351Smax.romanov@nginx.com nxt_mp_t *mp; 518351Smax.romanov@nginx.com nxt_req_app_link_t *ra; 519351Smax.romanov@nginx.com 520425Smax.romanov@nginx.com if (ra_src->mem_pool != NULL) { 521425Smax.romanov@nginx.com return ra_src; 522425Smax.romanov@nginx.com } 523425Smax.romanov@nginx.com 524351Smax.romanov@nginx.com mp = ra_src->ap->mem_pool; 525351Smax.romanov@nginx.com 526430Sigor@sysoev.ru ra = nxt_mp_alloc(mp, sizeof(nxt_req_app_link_t)); 527351Smax.romanov@nginx.com 528351Smax.romanov@nginx.com if (nxt_slow_path(ra == NULL)) { 529351Smax.romanov@nginx.com 530351Smax.romanov@nginx.com ra_src->rc->ra = NULL; 531351Smax.romanov@nginx.com ra_src->rc = NULL; 532351Smax.romanov@nginx.com 533351Smax.romanov@nginx.com return NULL; 534351Smax.romanov@nginx.com } 535351Smax.romanov@nginx.com 536430Sigor@sysoev.ru nxt_mp_retain(mp); 537430Sigor@sysoev.ru 538351Smax.romanov@nginx.com nxt_router_ra_init(task, ra, ra_src->rc); 539351Smax.romanov@nginx.com 540351Smax.romanov@nginx.com ra->mem_pool = mp; 541167Smax.romanov@nginx.com 542167Smax.romanov@nginx.com return ra; 543167Smax.romanov@nginx.com } 544167Smax.romanov@nginx.com 545167Smax.romanov@nginx.com 546423Smax.romanov@nginx.com nxt_inline nxt_bool_t 547423Smax.romanov@nginx.com nxt_router_msg_cancel(nxt_task_t *task, nxt_msg_info_t *msg_info, 548423Smax.romanov@nginx.com uint32_t stream) 549423Smax.romanov@nginx.com { 550423Smax.romanov@nginx.com nxt_buf_t *b, *next; 551423Smax.romanov@nginx.com nxt_bool_t cancelled; 552423Smax.romanov@nginx.com 553423Smax.romanov@nginx.com if (msg_info->buf == NULL) { 554423Smax.romanov@nginx.com return 0; 555423Smax.romanov@nginx.com } 556423Smax.romanov@nginx.com 557423Smax.romanov@nginx.com cancelled = nxt_port_mmap_tracking_cancel(task, &msg_info->tracking, 558423Smax.romanov@nginx.com stream); 559423Smax.romanov@nginx.com 560423Smax.romanov@nginx.com if (cancelled) { 561423Smax.romanov@nginx.com nxt_debug(task, "stream #%uD: cancelled by router", stream); 562423Smax.romanov@nginx.com } 563423Smax.romanov@nginx.com 564423Smax.romanov@nginx.com for (b = msg_info->buf; b != NULL; b = next) { 565423Smax.romanov@nginx.com next = b->next; 566423Smax.romanov@nginx.com 567423Smax.romanov@nginx.com b->completion_handler = msg_info->completion_handler; 568423Smax.romanov@nginx.com 569423Smax.romanov@nginx.com if (b->is_port_mmap_sent) { 570423Smax.romanov@nginx.com b->is_port_mmap_sent = cancelled == 0; 571423Smax.romanov@nginx.com b->completion_handler(task, b, b->parent); 572423Smax.romanov@nginx.com } 573423Smax.romanov@nginx.com } 574423Smax.romanov@nginx.com 575423Smax.romanov@nginx.com msg_info->buf = NULL; 576423Smax.romanov@nginx.com 577423Smax.romanov@nginx.com return cancelled; 578423Smax.romanov@nginx.com } 579423Smax.romanov@nginx.com 580423Smax.romanov@nginx.com 581167Smax.romanov@nginx.com static void 582425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra); 583425Smax.romanov@nginx.com 584425Smax.romanov@nginx.com 585425Smax.romanov@nginx.com static void 586425Smax.romanov@nginx.com nxt_router_ra_update_peer_handler(nxt_task_t *task, void *obj, void *data) 587167Smax.romanov@nginx.com { 588425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 589425Smax.romanov@nginx.com 590425Smax.romanov@nginx.com ra = obj; 591425Smax.romanov@nginx.com 592425Smax.romanov@nginx.com nxt_router_ra_update_peer(task, ra); 593425Smax.romanov@nginx.com 594425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 595425Smax.romanov@nginx.com } 596425Smax.romanov@nginx.com 597425Smax.romanov@nginx.com 598425Smax.romanov@nginx.com static void 599425Smax.romanov@nginx.com nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra) 600425Smax.romanov@nginx.com { 601343Smax.romanov@nginx.com nxt_event_engine_t *engine; 602343Smax.romanov@nginx.com nxt_req_conn_link_t *rc; 603318Smax.romanov@nginx.com 604425Smax.romanov@nginx.com engine = ra->work.data; 605318Smax.romanov@nginx.com 606343Smax.romanov@nginx.com if (task->thread->engine != engine) { 607425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 608425Smax.romanov@nginx.com 609425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_update_peer_handler; 610318Smax.romanov@nginx.com ra->work.task = &engine->task; 611318Smax.romanov@nginx.com ra->work.next = NULL; 612318Smax.romanov@nginx.com 613425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post update peer to %p", 614318Smax.romanov@nginx.com ra->stream, engine); 615318Smax.romanov@nginx.com 616318Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 617318Smax.romanov@nginx.com 618318Smax.romanov@nginx.com return; 619318Smax.romanov@nginx.com } 620318Smax.romanov@nginx.com 621425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD update peer", ra->stream); 622425Smax.romanov@nginx.com 623425Smax.romanov@nginx.com rc = ra->rc; 624425Smax.romanov@nginx.com 625425Smax.romanov@nginx.com if (rc != NULL && ra->app_port != NULL) { 626425Smax.romanov@nginx.com nxt_port_rpc_ex_set_peer(task, engine->port, rc, ra->app_port->pid); 627425Smax.romanov@nginx.com } 628425Smax.romanov@nginx.com 629425Smax.romanov@nginx.com nxt_router_ra_use(task, ra, -1); 630425Smax.romanov@nginx.com } 631425Smax.romanov@nginx.com 632425Smax.romanov@nginx.com 633425Smax.romanov@nginx.com static void 634425Smax.romanov@nginx.com nxt_router_ra_release(nxt_task_t *task, nxt_req_app_link_t *ra) 635425Smax.romanov@nginx.com { 636431Sigor@sysoev.ru nxt_mp_t *mp; 637431Sigor@sysoev.ru nxt_req_conn_link_t *rc; 638425Smax.romanov@nginx.com 639425Smax.romanov@nginx.com nxt_assert(task->thread->engine == ra->work.data); 640425Smax.romanov@nginx.com nxt_assert(ra->use_count == 0); 641425Smax.romanov@nginx.com 642343Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD release", ra->stream); 643343Smax.romanov@nginx.com 644343Smax.romanov@nginx.com rc = ra->rc; 645343Smax.romanov@nginx.com 646343Smax.romanov@nginx.com if (rc != NULL) { 647423Smax.romanov@nginx.com if (nxt_slow_path(ra->err_code != 0)) { 648431Sigor@sysoev.ru nxt_http_request_error(task, rc->ap->request, ra->err_code); 649423Smax.romanov@nginx.com 650423Smax.romanov@nginx.com } else { 651423Smax.romanov@nginx.com rc->app_port = ra->app_port; 652423Smax.romanov@nginx.com rc->msg_info = ra->msg_info; 653423Smax.romanov@nginx.com 654425Smax.romanov@nginx.com if (rc->app->timeout != 0) { 655431Sigor@sysoev.ru rc->ap->timer.handler = nxt_router_app_timeout; 656615Smax.romanov@nginx.com rc->ap->timer_data = rc; 657431Sigor@sysoev.ru nxt_timer_add(task->thread->engine, &rc->ap->timer, 658425Smax.romanov@nginx.com rc->app->timeout); 659425Smax.romanov@nginx.com } 660425Smax.romanov@nginx.com 661423Smax.romanov@nginx.com ra->app_port = NULL; 662423Smax.romanov@nginx.com ra->msg_info.buf = NULL; 663423Smax.romanov@nginx.com } 664343Smax.romanov@nginx.com 665343Smax.romanov@nginx.com rc->ra = NULL; 666343Smax.romanov@nginx.com ra->rc = NULL; 667343Smax.romanov@nginx.com } 668343Smax.romanov@nginx.com 669343Smax.romanov@nginx.com if (ra->app_port != NULL) { 670343Smax.romanov@nginx.com nxt_router_app_port_release(task, ra->app_port, 0, 1); 671343Smax.romanov@nginx.com 672343Smax.romanov@nginx.com ra->app_port = NULL; 673167Smax.romanov@nginx.com } 674167Smax.romanov@nginx.com 675423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &ra->msg_info, ra->stream); 676423Smax.romanov@nginx.com 677430Sigor@sysoev.ru mp = ra->mem_pool; 678430Sigor@sysoev.ru 679430Sigor@sysoev.ru if (mp != NULL) { 680430Sigor@sysoev.ru nxt_mp_free(mp, ra); 681430Sigor@sysoev.ru nxt_mp_release(mp); 682351Smax.romanov@nginx.com } 683167Smax.romanov@nginx.com } 684167Smax.romanov@nginx.com 685167Smax.romanov@nginx.com 686425Smax.romanov@nginx.com static void 687425Smax.romanov@nginx.com nxt_router_ra_release_handler(nxt_task_t *task, void *obj, void *data) 688425Smax.romanov@nginx.com { 689425Smax.romanov@nginx.com nxt_req_app_link_t *ra; 690425Smax.romanov@nginx.com 691425Smax.romanov@nginx.com ra = obj; 692425Smax.romanov@nginx.com 693425Smax.romanov@nginx.com nxt_assert(ra->work.data == data); 694425Smax.romanov@nginx.com 695425Smax.romanov@nginx.com nxt_atomic_fetch_add(&ra->use_count, -1); 696425Smax.romanov@nginx.com 697425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 698425Smax.romanov@nginx.com } 699425Smax.romanov@nginx.com 700425Smax.romanov@nginx.com 701425Smax.romanov@nginx.com static void 702425Smax.romanov@nginx.com nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i) 703425Smax.romanov@nginx.com { 704425Smax.romanov@nginx.com int c; 705425Smax.romanov@nginx.com nxt_event_engine_t *engine; 706425Smax.romanov@nginx.com 707425Smax.romanov@nginx.com c = nxt_atomic_fetch_add(&ra->use_count, i); 708425Smax.romanov@nginx.com 709425Smax.romanov@nginx.com if (i < 0 && c == -i) { 710425Smax.romanov@nginx.com engine = ra->work.data; 711425Smax.romanov@nginx.com 712425Smax.romanov@nginx.com if (task->thread->engine == engine) { 713425Smax.romanov@nginx.com nxt_router_ra_release(task, ra); 714425Smax.romanov@nginx.com 715425Smax.romanov@nginx.com return; 716425Smax.romanov@nginx.com } 717425Smax.romanov@nginx.com 718425Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 719425Smax.romanov@nginx.com 720425Smax.romanov@nginx.com ra->work.handler = nxt_router_ra_release_handler; 721425Smax.romanov@nginx.com ra->work.task = &engine->task; 722425Smax.romanov@nginx.com ra->work.next = NULL; 723425Smax.romanov@nginx.com 724425Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD post release to %p", 725425Smax.romanov@nginx.com ra->stream, engine); 726425Smax.romanov@nginx.com 727425Smax.romanov@nginx.com nxt_event_engine_post(engine, &ra->work); 728425Smax.romanov@nginx.com } 729425Smax.romanov@nginx.com } 730425Smax.romanov@nginx.com 731425Smax.romanov@nginx.com 732423Smax.romanov@nginx.com nxt_inline void 733521Szelenkov@nginx.com nxt_router_ra_error(nxt_req_app_link_t *ra, int code, const char *str) 734345Smax.romanov@nginx.com { 735423Smax.romanov@nginx.com ra->app_port = NULL; 736423Smax.romanov@nginx.com ra->err_code = code; 737423Smax.romanov@nginx.com ra->err_str = str; 738345Smax.romanov@nginx.com } 739345Smax.romanov@nginx.com 740345Smax.romanov@nginx.com 741427Smax.romanov@nginx.com nxt_inline void 742427Smax.romanov@nginx.com nxt_router_ra_pending(nxt_task_t *task, nxt_app_t *app, nxt_req_app_link_t *ra) 743427Smax.romanov@nginx.com { 744427Smax.romanov@nginx.com nxt_queue_insert_tail(&ra->app_port->pending_requests, 745427Smax.romanov@nginx.com &ra->link_port_pending); 746427Smax.romanov@nginx.com nxt_queue_insert_tail(&app->pending, &ra->link_app_pending); 747427Smax.romanov@nginx.com 748427Smax.romanov@nginx.com nxt_router_ra_inc_use(ra); 749427Smax.romanov@nginx.com 750427Smax.romanov@nginx.com ra->res_time = nxt_thread_monotonic_time(task->thread) + app->res_timeout; 751427Smax.romanov@nginx.com 752427Smax.romanov@nginx.com nxt_debug(task, "ra stream #%uD enqueue to pending_requests", ra->stream); 753427Smax.romanov@nginx.com } 754427Smax.romanov@nginx.com 755427Smax.romanov@nginx.com 756425Smax.romanov@nginx.com nxt_inline nxt_bool_t 757425Smax.romanov@nginx.com nxt_queue_chk_remove(nxt_queue_link_t *lnk) 758425Smax.romanov@nginx.com { 759425Smax.romanov@nginx.com if (lnk->next != NULL) { 760425Smax.romanov@nginx.com nxt_queue_remove(lnk); 761425Smax.romanov@nginx.com 762425Smax.romanov@nginx.com lnk->next = NULL; 763425Smax.romanov@nginx.com 764425Smax.romanov@nginx.com return 1; 765425Smax.romanov@nginx.com } 766425Smax.romanov@nginx.com 767425Smax.romanov@nginx.com return 0; 768425Smax.romanov@nginx.com } 769425Smax.romanov@nginx.com 770425Smax.romanov@nginx.com 771343Smax.romanov@nginx.com nxt_inline void 772343Smax.romanov@nginx.com nxt_router_rc_unlink(nxt_task_t *task, nxt_req_conn_link_t *rc) 773343Smax.romanov@nginx.com { 774425Smax.romanov@nginx.com int ra_use_delta; 775343Smax.romanov@nginx.com nxt_req_app_link_t *ra; 776343Smax.romanov@nginx.com 777343Smax.romanov@nginx.com if (rc->app_port != NULL) { 778343Smax.romanov@nginx.com nxt_router_app_port_release(task, rc->app_port, 0, 1); 779343Smax.romanov@nginx.com 780343Smax.romanov@nginx.com rc->app_port = NULL; 781343Smax.romanov@nginx.com } 782343Smax.romanov@nginx.com 783423Smax.romanov@nginx.com nxt_router_msg_cancel(task, &rc->msg_info, rc->stream); 784423Smax.romanov@nginx.com 785343Smax.romanov@nginx.com ra = rc->ra; 786343Smax.romanov@nginx.com 787343Smax.romanov@nginx.com if (ra != NULL) { 788343Smax.romanov@nginx.com rc->ra = NULL; 789343Smax.romanov@nginx.com ra->rc = NULL; 790343Smax.romanov@nginx.com 791425Smax.romanov@nginx.com ra_use_delta = 0; 792