1 2 /* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) Valentin V. Bartenev 5 * Copyright (C) NGINX, Inc. 6 */ 7 8 #ifndef _NXT_RUNTIME_H_INCLUDED_ 9 #define _NXT_RUNTIME_H_INCLUDED_ 10 11 12 typedef void (*nxt_runtime_cont_t)(nxt_task_t *task); 13 14 15 struct nxt_runtime_s { 16 nxt_mp_t *mem_pool; 17 18 nxt_array_t *inherited_sockets; /* of nxt_listen_socket_t */ 19 nxt_array_t *listen_sockets; /* of nxt_listen_socket_t */ 20 21 nxt_array_t *services; /* of nxt_service_t */ 22 nxt_array_t *languages; /* of nxt_app_lang_module_t */ 23 void *data; 24 25 nxt_runtime_cont_t start; 26 27 nxt_str_t hostname; 28 29 nxt_file_name_t *pid_file; 30 31 nxt_array_t *thread_pools; /* of nxt_thread_pool_t */ 32 nxt_runtime_cont_t continuation; 33 34 nxt_process_t *mprocess; 35 size_t nprocesses; 36 nxt_thread_mutex_t processes_mutex; 37 nxt_lvlhsh_t processes; /* of nxt_process_t */ 38 39 nxt_port_t *port_by_type[NXT_PROCESS_MAX]; 40 nxt_lvlhsh_t ports; /* of nxt_port_t */ 41 42 nxt_list_t *log_files; /* of nxt_file_t */ 43 44 uint32_t last_engine_id; 45 46 uint32_t types; /* bitset of nxt_process_type_t */ 47 48 nxt_timer_t timer; 49 50 uint8_t daemon; 51 uint8_t batch; 52 uint8_t main_process; 53 const char *engine; 54 uint32_t engine_connections; 55 uint32_t auxiliary_threads; 56 nxt_user_cred_t user_cred; 57 const char *group; 58 const char *pid; 59 const char *log; 60 const char *modules; 61 const char *state; 62 const char *conf; 63 const char *conf_tmp; 64 const char *control; 65 66 nxt_queue_t engines; /* of nxt_event_engine_t */ 67 68 nxt_sockaddr_t *controller_listen; 69 nxt_listen_socket_t *controller_socket; 70 nxt_str_t upstream; 71 }; 72 73 74 75 typedef nxt_int_t (*nxt_module_init_t)(nxt_thread_t *thr, nxt_runtime_t *rt); 76 77 78 nxt_int_t nxt_runtime_create(nxt_task_t *task); 79 void nxt_runtime_quit(nxt_task_t *task); 80 81 void nxt_runtime_event_engine_free(nxt_runtime_t *rt); 82 83 nxt_int_t nxt_runtime_thread_pool_create(nxt_thread_t *thr, nxt_runtime_t *rt, 84 nxt_uint_t max_threads, nxt_nsec_t timeout); 85 86 87 nxt_inline nxt_bool_t 88 nxt_runtime_is_type(nxt_runtime_t *rt, nxt_process_type_t type) 89 { 90 return (rt->types & (1U << type)) != 0; 91 } 92 93 94 nxt_inline nxt_bool_t 95 nxt_runtime_is_main(nxt_runtime_t *rt) 96 { 97 return nxt_runtime_is_type(rt, NXT_PROCESS_MAIN); 98 } 99 100 101 nxt_process_t *nxt_runtime_process_new(nxt_runtime_t *rt); 102 103 nxt_process_t *nxt_runtime_process_get(nxt_runtime_t *rt, nxt_pid_t pid); 104 105 void nxt_runtime_process_add(nxt_task_t *task, nxt_process_t *process); 106 107 nxt_process_t *nxt_runtime_process_find(nxt_runtime_t *rt, nxt_pid_t pid); 108 109 void nxt_process_use(nxt_task_t *task, nxt_process_t *process, int i); 110 111 nxt_process_t *nxt_runtime_process_first(nxt_runtime_t *rt, 112 nxt_lvlhsh_each_t *lhe); 113 114 #define nxt_runtime_process_next(rt, lhe) \ 115 nxt_lvlhsh_each(&rt->processes, lhe) 116 117 118 void nxt_runtime_port_add(nxt_task_t *task, nxt_port_t *port); 119 120 void nxt_runtime_port_remove(nxt_task_t *task, nxt_port_t *port); 121 122 nxt_port_t *nxt_runtime_port_find(nxt_runtime_t *rt, nxt_pid_t pid, 123 nxt_port_id_t port_id); 124 125 nxt_port_t *nxt_runtime_port_first(nxt_runtime_t *rt, 126 nxt_lvlhsh_each_t *lhe); 127 128 #define nxt_runtime_port_next(rt, lhe) \ 129 nxt_port_hash_next(&rt->ports, lhe) 130 131 132 /* STUB */ 133 nxt_int_t nxt_runtime_controller_socket(nxt_task_t *task, nxt_runtime_t *rt); 134 135 nxt_str_t *nxt_current_directory(nxt_mp_t *mp); 136 137 nxt_listen_socket_t *nxt_runtime_listen_socket_add(nxt_runtime_t *rt, 138 nxt_sockaddr_t *sa); 139 nxt_int_t nxt_runtime_listen_sockets_create(nxt_task_t *task, 140 nxt_runtime_t *rt); 141 nxt_int_t nxt_runtime_listen_sockets_enable(nxt_task_t *task, 142 nxt_runtime_t *rt); 143 nxt_file_t *nxt_runtime_log_file_add(nxt_runtime_t *rt, nxt_str_t *name); 144 145 /* STUB */ 146 void nxt_cdecl nxt_log_time_handler(nxt_uint_t level, nxt_log_t *log, 147 const char *fmt, ...); 148 149 void nxt_stream_connection_init(nxt_task_t *task, void *obj, void *data); 150 151 void nxt_app_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 152 void nxt_app_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 153 154 155 #define nxt_runtime_process_each(rt, process) \ 156 do { \ 157 nxt_lvlhsh_each_t _lhe; \ 158 nxt_process_t *_nxt; \ 159 \ 160 for (process = nxt_runtime_process_first(rt, &_lhe); \ 161 process != NULL; \ 162 process = _nxt) { \ 163 \ 164 _nxt = nxt_runtime_process_next(rt, &_lhe); \ 165 166 #define nxt_runtime_process_loop \ 167 } \ 168 } while(0) 169 170 171 #define nxt_runtime_port_each(rt, port) \ 172 do { \ 173 nxt_lvlhsh_each_t _lhe; \ 174 \ 175 for (port = nxt_runtime_port_first(rt, &_lhe); \ 176 port != NULL; \ 177 port = nxt_runtime_port_next(rt, &_lhe)) { \ 178 179 #define nxt_runtime_port_loop \ 180 } \ 181 } while(0) 182 183 184 extern nxt_module_init_t nxt_init_modules[]; 185 extern nxt_uint_t nxt_init_modules_n; 186 187 188 #endif /* _NXT_RUNTIME_H_INCLIDED_ */ 189