- Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathngx_http_lua_socket_tcp.h
207 lines (140 loc) · 6.46 KB
/
ngx_http_lua_socket_tcp.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Copyright (C) Yichun Zhang (agentzh)
*/
#ifndef_NGX_HTTP_LUA_SOCKET_TCP_H_INCLUDED_
#define_NGX_HTTP_LUA_SOCKET_TCP_H_INCLUDED_
#include"ngx_http_lua_common.h"
#defineNGX_HTTP_LUA_SOCKET_FT_ERROR 0x0001
#defineNGX_HTTP_LUA_SOCKET_FT_TIMEOUT 0x0002
#defineNGX_HTTP_LUA_SOCKET_FT_CLOSED 0x0004
#defineNGX_HTTP_LUA_SOCKET_FT_RESOLVER 0x0008
#defineNGX_HTTP_LUA_SOCKET_FT_BUFTOOSMALL 0x0010
#defineNGX_HTTP_LUA_SOCKET_FT_NOMEM 0x0020
#defineNGX_HTTP_LUA_SOCKET_FT_PARTIALWRITE 0x0040
#defineNGX_HTTP_LUA_SOCKET_FT_CLIENTABORT 0x0080
#defineNGX_HTTP_LUA_SOCKET_FT_SSL 0x0100
typedefstructngx_http_lua_socket_tcp_upstream_s
ngx_http_lua_socket_tcp_upstream_t;
typedefstructngx_http_lua_socket_udata_queue_s
ngx_http_lua_socket_udata_queue_t;
typedef
int (*ngx_http_lua_socket_tcp_retval_handler)(ngx_http_request_t*r,
ngx_http_lua_socket_tcp_upstream_t*u, lua_State*L);
typedefvoid (*ngx_http_lua_socket_tcp_upstream_handler_pt)
(ngx_http_request_t*r, ngx_http_lua_socket_tcp_upstream_t*u);
typedefstruct {
ngx_event_tevent;
ngx_queue_tqueue;
ngx_str_thost;
ngx_http_cleanup_pt*cleanup;
ngx_http_lua_socket_tcp_upstream_t*u;
in_port_tport;
} ngx_http_lua_socket_tcp_conn_op_ctx_t;
#definengx_http_lua_socket_tcp_free_conn_op_ctx(conn_op_ctx) \
ngx_free(conn_op_ctx->host.data); \
ngx_free(conn_op_ctx)
typedefstruct {
lua_State*lua_vm;
ngx_int_tsize;
ngx_queue_tcache_connect_op;
ngx_queue_twait_connect_op;
/* connections == active connections + pending connect operations,
* while active connections == out-of-pool reused connections
* + in-pool connections */
ngx_int_tconnections;
/* queues of ngx_http_lua_socket_pool_item_t: */
ngx_queue_tcache;
ngx_queue_tfree;
ngx_int_tbacklog;
u_charkey[1];
} ngx_http_lua_socket_pool_t;
structngx_http_lua_socket_tcp_upstream_s {
ngx_http_lua_socket_tcp_retval_handlerread_prepare_retvals;
ngx_http_lua_socket_tcp_retval_handlerwrite_prepare_retvals;
ngx_http_lua_socket_tcp_upstream_handler_ptread_event_handler;
ngx_http_lua_socket_tcp_upstream_handler_ptwrite_event_handler;
ngx_http_lua_socket_udata_queue_t*udata_queue;
ngx_http_lua_socket_pool_t*socket_pool;
ngx_http_lua_loc_conf_t*conf;
ngx_http_cleanup_pt*cleanup;
ngx_http_request_t*request;
ngx_peer_connection_tpeer;
ngx_msec_tread_timeout;
ngx_msec_tsend_timeout;
ngx_msec_tconnect_timeout;
ngx_http_upstream_resolved_t*resolved;
ngx_chain_t*bufs_in; /* input data buffers */
ngx_chain_t*buf_in; /* last input data buffer */
ngx_buf_tbuffer; /* receive buffer */
size_tlength;
size_trest;
ngx_err_tsocket_errno;
ngx_int_t (*input_filter)(void*data, ssize_tbytes);
void*input_filter_ctx;
size_trequest_len;
ngx_chain_t*request_bufs;
ngx_http_lua_co_ctx_t*read_co_ctx;
ngx_http_lua_co_ctx_t*write_co_ctx;
ngx_uint_treused;
#if (NGX_HTTP_SSL)
ngx_str_tssl_name;
ngx_ssl_session_t*ssl_session_ret;
constchar*error_ret;
intopenssl_error_code_ret;
#endif
ngx_chain_t*busy_bufs;
unsignedft_type:16;
unsignedno_close:1;
unsignedconn_waiting:1;
unsignedread_waiting:1;
unsignedwrite_waiting:1;
unsignedeof:1;
unsignedbody_downstream:1;
unsignedraw_downstream:1;
unsignedread_closed:1;
unsignedwrite_closed:1;
unsignedconn_closed:1;
#if (NGX_HTTP_SSL)
unsignedssl_verify:1;
unsignedssl_session_reuse:1;
#endif
};
typedefstructngx_http_lua_dfa_edge_sngx_http_lua_dfa_edge_t;
structngx_http_lua_dfa_edge_s {
u_charchr;
intnew_state;
ngx_http_lua_dfa_edge_t*next;
};
typedefstruct {
ngx_http_lua_socket_tcp_upstream_t*upstream;
ngx_str_tpattern;
intstate;
ngx_http_lua_dfa_edge_t**recovering;
unsignedinclusive:1;
} ngx_http_lua_socket_compiled_pattern_t;
typedefstruct {
ngx_http_lua_socket_pool_t*socket_pool;
ngx_queue_tqueue;
ngx_connection_t*connection;
socklen_tsocklen;
structsockaddr_storagesockaddr;
ngx_uint_treused;
ngx_http_lua_socket_udata_queue_t*udata_queue;
} ngx_http_lua_socket_pool_item_t;
structngx_http_lua_socket_udata_queue_s {
ngx_pool_t*pool;
ngx_queue_tqueue;
ngx_queue_tfree;
intlen;
intcapacity;
};
typedefstruct {
ngx_queue_tqueue;
uint64_tkey;
uint64_tvalue;
} ngx_http_lua_socket_node_t;
voidngx_http_lua_inject_socket_tcp_api(ngx_log_t*log, lua_State*L);
voidngx_http_lua_inject_req_socket_api(lua_State*L);
voidngx_http_lua_cleanup_conn_pools(lua_State*L);
#endif/* _NGX_HTTP_LUA_SOCKET_TCP_H_INCLUDED_ */
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */