/
ngx_http_drizzle_upstream.h
148 lines (101 loc) · 4.49 KB
/
ngx_http_drizzle_upstream.h
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef NGX_HTTP_DRIZZLE_UPSTREAM_H
#define NGX_HTTP_DRIZZLE_UPSTREAM_H
#include <ngx_core.h>
#include <ngx_http.h>
#include <nginx.h>
#include "ngx_http_drizzle_module.h"
typedef enum {
drizzle_keepalive_overflow_ignore = 0,
drizzle_keepalive_overflow_reject
} ngx_http_drizzle_keepalive_overflow_t;
typedef enum {
ngx_http_drizzle_protocol = 0,
ngx_http_mysql_protocol
} ngx_http_upstream_drizzle_protocol_t;
typedef struct {
#if defined(nginx_version) && nginx_version >= 8022
ngx_addr_t *addrs;
#else
ngx_peer_addr_t *addrs;
#endif
ngx_uint_t naddrs;
in_port_t port;
ngx_str_t user;
ngx_str_t password;
ngx_str_t dbname;
ngx_str_t set_names_query;
ngx_http_upstream_drizzle_protocol_t protocol;
} ngx_http_upstream_drizzle_server_t;
typedef struct {
struct sockaddr *sockaddr;
socklen_t socklen;
ngx_str_t name;
in_port_t port;
ngx_str_t user;
ngx_str_t password;
ngx_str_t dbname;
ngx_str_t *set_names_query;
u_char *host;
ngx_http_upstream_drizzle_protocol_t protocol;
} ngx_http_upstream_drizzle_peer_t;
typedef struct {
unsigned single;
ngx_uint_t number;
ngx_str_t *name;
ngx_http_upstream_drizzle_peer_t peer[1];
} ngx_http_upstream_drizzle_peers_t;
typedef struct {
ngx_http_upstream_drizzle_peers_t *peers;
/* TODO: we might need "tried" from round robin peer data */
ngx_uint_t current;
/* of ngx_http_upstream_drizzle_server_t */
ngx_array_t *servers;
drizzle_st drizzle;
ngx_pool_t *pool;
/* keepalive related fields */
unsigned single;
ngx_queue_t free;
ngx_queue_t cache;
ngx_uint_t active_conns;
ngx_uint_t max_cached;
ngx_http_drizzle_keepalive_overflow_t overflow;
} ngx_http_upstream_drizzle_srv_conf_t;
typedef struct {
ngx_http_drizzle_loc_conf_t *loc_conf;
ngx_http_upstream_drizzle_srv_conf_t *srv_conf;
ngx_http_upstream_t *upstream;
ngx_http_request_t *request;
ngx_str_t dbname;
ngx_str_t query;
ngx_http_drizzle_state_t state;
drizzle_con_st *drizzle_con;
drizzle_result_st drizzle_res;
drizzle_column_st drizzle_col;
uint64_t drizzle_row;
ngx_str_t name;
ngx_chain_t **last_out;
ngx_buf_t *out_buf;
ngx_buf_t cached;
ngx_buf_t postponed;
size_t avail_out;
ngx_str_t charset;
ngx_str_t *set_names_query;
struct sockaddr sockaddr;
/* how many times this connection has been successfully used */
ngx_uint_t used;
unsigned failed:1;
unsigned seen_stream_end:1;
unsigned has_set_names:1;
unsigned enable_charset:1;
} ngx_http_upstream_drizzle_peer_data_t;
char * ngx_http_upstream_drizzle_server(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
void * ngx_http_upstream_drizzle_create_srv_conf(ngx_conf_t *cf);
ngx_flag_t ngx_http_upstream_drizzle_is_my_peer(
const ngx_peer_connection_t *peer);
void ngx_http_upstream_drizzle_free_connection(ngx_log_t *log,
ngx_connection_t *c, drizzle_con_st *dc,
ngx_http_upstream_drizzle_srv_conf_t *dscf);
ngx_http_upstream_srv_conf_t * ngx_http_upstream_drizzle_add(
ngx_http_request_t *r, ngx_url_t *url);
#endif /* NGX_HTTP_DRIZZLE_UPSTREAM_H */