forked from zhouchangxun/ngx_healthcheck_module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h.in
130 lines (96 loc) · 4.63 KB
/
common.h.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* module internal common header */
#include <nginx.h>
#include <ngx_core.h>
typedef struct ngx_upstream_check_peer_s ngx_upstream_check_peer_t;
typedef struct ngx_upstream_check_srv_conf_s ngx_upstream_check_srv_conf_t;
typedef ngx_int_t (*ngx_upstream_check_packet_init_pt)
(ngx_upstream_check_peer_t *peer);
typedef ngx_int_t (*ngx_upstream_check_packet_parse_pt)
(ngx_upstream_check_peer_t *peer);
typedef void (*ngx_upstream_check_packet_clean_pt)
(ngx_upstream_check_peer_t *peer);
typedef struct {
ngx_uint_t type;
ngx_str_t name;
ngx_str_t default_send;
/* HTTP */
ngx_uint_t default_status_alive;
ngx_event_handler_pt send_handler;
ngx_event_handler_pt recv_handler;
ngx_upstream_check_packet_init_pt init;
ngx_upstream_check_packet_parse_pt parse;
ngx_upstream_check_packet_clean_pt reinit;
unsigned need_pool;
unsigned need_keepalive;
} ngx_check_conf_t;
struct ngx_upstream_check_srv_conf_s {
ngx_uint_t port;
ngx_uint_t fall_count;
ngx_uint_t rise_count;
ngx_msec_t check_interval;
ngx_msec_t check_timeout;
ngx_uint_t check_keepalive_requests;
ngx_check_conf_t *check_type_conf;
ngx_str_t send;
union {
ngx_uint_t return_code;
ngx_uint_t status_alive;
} code;
ngx_array_t *fastcgi_params; //only for http module.
ngx_uint_t default_down;
};
typedef struct {
ngx_shmtx_t mutex;
#if (nginx_version >= 1002000)
ngx_shmtx_sh_t lock;
#else
ngx_atomic_t lock;
#endif
ngx_pid_t owner;
ngx_msec_t access_time;
ngx_uint_t fall_count;
ngx_uint_t rise_count;
ngx_uint_t busyness;
ngx_uint_t access_count;
struct sockaddr *sockaddr;
socklen_t socklen;
ngx_atomic_t down; //current status.
ngx_str_t *upstream_name;
u_char padding[64];
} ngx_upstream_check_peer_shm_t;
typedef struct {
ngx_uint_t generation;// current process generation(==reload_num +1)
ngx_uint_t checksum;// we can know if peer config file changed by calculate it.
ngx_uint_t number;
/* ngx_upstream_check_status_peer_t */
ngx_upstream_check_peer_shm_t peers[1]; //hack: peer[0]
} ngx_upstream_check_peers_shm_t;
/* followed with (peers_num-1)*ngx_upstream_check_peer_shm_t dynamicly,*/
/* so we can ref by peers_shm->peers[0],[1],... */
struct ngx_upstream_check_peer_s {
ngx_flag_t state;
ngx_pool_t *pool;
ngx_uint_t index;
ngx_uint_t max_busy;
ngx_str_t *upstream_name;
ngx_addr_t *check_peer_addr;
ngx_addr_t *peer_addr;
ngx_event_t check_ev;
ngx_event_t check_timeout_ev;
ngx_peer_connection_t pc;
void *check_data;
ngx_event_handler_pt send_handler;
ngx_event_handler_pt recv_handler;
ngx_upstream_check_packet_init_pt init; //zhoucx: function ptr
ngx_upstream_check_packet_parse_pt parse;
ngx_upstream_check_packet_clean_pt reinit;
ngx_upstream_check_peer_shm_t *shm;
ngx_upstream_check_srv_conf_t *conf;
};
typedef struct {
ngx_str_t check_shm_name;
ngx_uint_t checksum;
/* peers include ngx_upstream_check_peer_t item*/
ngx_array_t peers;
ngx_upstream_check_peers_shm_t *peers_shm;
} ngx_upstream_check_peers_t;