xref: /unit/src/nxt_router.h (revision 216:07257705cd64)
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #ifndef _NXT_ROUTER_H_INCLUDED_
8 #define _NXT_ROUTER_H_INCLUDED_
9 
10 
11 #include <nxt_main.h>
12 #include <nxt_runtime.h>
13 #include <nxt_master_process.h>
14 #include <nxt_application.h>
15 
16 
17 typedef struct {
18     nxt_thread_spinlock_t  lock;
19     nxt_queue_t            engines;
20 
21     nxt_queue_t            sockets;    /* of nxt_socket_conf_t */
22     nxt_queue_t            apps;       /* of nxt_app_t */
23 } nxt_router_t;
24 
25 
26 typedef struct {
27     uint32_t               count;
28     uint32_t               threads;
29     nxt_router_t           *router;
30     nxt_mp_t               *mem_pool;
31 } nxt_router_conf_t;
32 
33 
34 typedef struct {
35     nxt_event_engine_t     *engine;
36     nxt_work_t             *jobs;
37 } nxt_router_engine_conf_t;
38 
39 
40 typedef struct {
41     nxt_queue_t            creating;   /* of nxt_socket_conf_t */
42     nxt_queue_t            pending;    /* of nxt_socket_conf_t */
43     nxt_queue_t            updating;   /* of nxt_socket_conf_t */
44     nxt_queue_t            keeping;    /* of nxt_socket_conf_t */
45     nxt_queue_t            deleting;   /* of nxt_socket_conf_t */
46 
47     nxt_queue_t            apps;       /* of nxt_app_t */
48     nxt_queue_t            previous;   /* of nxt_app_t */
49 
50     uint32_t               new_threads;
51     uint32_t               stream;
52     uint32_t               count;
53 
54     nxt_event_engine_t     *engine;
55     nxt_port_t             *port;
56     nxt_array_t            *engines;
57     nxt_router_conf_t      *conf;
58     nxt_mp_t               *mem_pool;
59 } nxt_router_temp_conf_t;
60 
61 
62 typedef struct {
63     nxt_task_t              task;
64     nxt_work_t              work;
65     nxt_router_temp_conf_t  *tmcf;
66 } nxt_joint_job_t;
67 
68 
69 
70 typedef nxt_int_t (*nxt_app_prepare_msg_t)(nxt_task_t *task,
71     nxt_app_request_t *r, nxt_app_wmsg_t *wmsg);
72 
73 
74 struct nxt_app_s {
75     nxt_thread_mutex_t     mutex;    /* Protects ports queue. */
76     nxt_queue_t            ports;    /* of nxt_port_t.app_link */
77 
78     nxt_queue_t            requests; /* of nxt_req_conn_link_t */
79     nxt_str_t              name;
80 
81     uint32_t               pending_workers;
82     uint32_t               workers;
83     uint32_t               max_workers;
84 
85     nxt_app_type_t         type:8;
86     uint8_t                live;   /* 1 bit */
87 
88     nxt_queue_link_t       link;
89 
90     nxt_str_t              conf;
91     nxt_app_prepare_msg_t  prepare_msg;
92 };
93 
94 
95 typedef struct {
96     uint32_t               count;
97     nxt_socket_t           fd;
98 } nxt_router_socket_t;
99 
100 
101 typedef struct {
102     uint32_t               count;
103     nxt_queue_link_t       link;
104     nxt_router_socket_t    *socket;
105     nxt_router_conf_t      *router_conf;
106     nxt_sockaddr_t         *sockaddr;
107 
108     nxt_app_t              *application;
109 
110     nxt_listen_socket_t    listen;
111 
112     size_t                 header_buffer_size;
113     size_t                 large_header_buffer_size;
114     size_t                 large_header_buffers;
115     size_t                 body_buffer_size;
116     size_t                 max_body_size;
117     nxt_msec_t             header_read_timeout;
118     nxt_msec_t             body_read_timeout;
119 } nxt_socket_conf_t;
120 
121 
122 typedef struct {
123     uint32_t               count;
124     nxt_queue_link_t       link;
125     nxt_event_engine_t     *engine;
126     nxt_socket_conf_t      *socket_conf;
127 
128     /* Modules configuraitons. */
129 } nxt_socket_conf_joint_t;
130 
131 
132 void nxt_router_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
133 void nxt_router_conf_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
134 void nxt_router_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
135 
136 nxt_bool_t nxt_router_app_remove_port(nxt_port_t *port);
137 
138 #endif  /* _NXT_ROUTER_H_INCLUDED_ */
139