forked from laocai/tcp-nginx-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngx_tcp_cmdso.h
127 lines (98 loc) · 3.39 KB
/
ngx_tcp_cmdso.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
#ifndef _NGX_TCP_CMDSO_H_
#define _NGX_TCP_CMDSO_H_
#include <ngx_tcp_export.h>
///* g_cycle_ctx is declared here must be defined in dynamic shared object,
// * must be initialized in cmdso_load from the param cycle_ctx.
// */
//extern ngx_tcp_cycle_ctx_t *g_cycle_ctx;
typedef long (*cmdpkg_handler_pt)(ngx_tcp_ctx_t *ctx,
const u_char *pkg,
int pkg_len);
/* pkg = head + body. Filter result must be the same as this format. */
typedef long (*cmdpkg_filter_pt)(ngx_tcp_ctx_t *ctx,
u_char **pkg,
int *pkg_len);
typedef long
(*cmdpkg_handler_add_pt)(void *cycle_param,
uint32_t cmd_min, uint32_t cmd_max,
cmdpkg_handler_pt h);
enum
{
FILTER_CALL_NO_ORDER = 0,
// If these are more than one first call filters, only one will be valid
FILTER_CALL_FIRST = 1,
// If these are more than one last call filters, only one will be valid
FILTER_CALL_LAST = 2
};
typedef long
(*cmdpkg_filter_add_pt)(void *cycle_param, cmdpkg_filter_pt h, int call_order);
#define CMDSO_LOAD "cmdso_load"
#define CMDSO_UNLOAD "cmdso_unload"
#define CMDSO_SESS_INIT "cmdso_sess_init"
#define CMDSO_SESS_FINIT "cmdso_sess_finit"
typedef long
(*cmdso_load_pt)(void *cycle_param, cmdpkg_handler_add_pt add_h,
cmdpkg_filter_add_pt add_recvpkg_filter_h,
cmdpkg_filter_add_pt add_sendpkg_filter_h,
int slot, ngx_tcp_cycle_ctx_t *cycle_ctx);
typedef long (*cmdso_unload_pt)(void *cycle_param);
typedef long (*cmdso_sess_init_pt)(ngx_tcp_ctx_t *ctx);
typedef long (*cmdso_sess_finit_pt)(ngx_tcp_ctx_t *ctx);
typedef struct {
void *handle;
cmdso_load_pt cmdso_load;
cmdso_unload_pt cmdso_unload;
cmdso_sess_init_pt cmdso_sess_init;
cmdso_sess_finit_pt cmdso_sess_finit;
} ngx_tcp_cmdso_t;
#pragma pack(push, 1)
typedef struct {
/* size == pkg_head + pkg_body */
uint32_t size;
uint32_t cmd;
/* padding */
uint32_t spare0;
uint32_t spare1;
uint32_t spare2;
uint32_t spare3;
uint32_t spare4;
uint32_t spare5;
} ngx_tcp_cmd_pkghead_t;
typedef struct {
pid_t dest_pid;
int32_t dest_fd;
uint32_t data_size;
u_char data[0];
} ngx_tcp_cmd_pkgtran_t;
#define CMD_SESSION_PKG_HEAD_LEN sizeof(ngx_tcp_cmd_pkghead_t)
#pragma pack(pop)
static inline void
ngx_tcp_cmd_pkghead_hton(ngx_tcp_cmd_pkghead_t *pkghead)
{
pkghead->size = htonl(pkghead->size);
pkghead->cmd = htonl(pkghead->cmd);
}
static inline void
ngx_tcp_cmd_pkghead_ntoh(ngx_tcp_cmd_pkghead_t *pkghead)
{
pkghead->size = ntohl(pkghead->size);
pkghead->cmd = ntohl(pkghead->cmd);
}
#define NGX_TCP_CMD_KEEPALIVE 1
#define NGX_TCP_CMD_TRAN 2
#define NGX_TCP_CMD_MAX_PKG_SIZE (1024 * 1024 * 4)
# ifdef __cplusplus
extern "C" {
# endif
/* The dynamic shared object must implement this function for loading. */
long cmdso_load(void *cycle_param, cmdpkg_handler_add_pt add_h,
cmdpkg_filter_add_pt add_recvpkg_filter_h,
cmdpkg_filter_add_pt add_sendpkg_filter_h,
int slot, ngx_tcp_cycle_ctx_t *cycle_ctx);
long cmdso_unload(void *cycle_param);
long cmdso_sess_init(ngx_tcp_ctx_t *ctx);
long cmdso_sess_finit(ngx_tcp_ctx_t *ctx);
# ifdef __cplusplus
}
# endif
#endif