forked from laocai/tcp-nginx-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ngx_tcp_cmdso.h
132 lines (103 loc) · 3.65 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
127
128
129
130
131
#ifndef _NGX_TCP_CMDSO_H_
#define _NGX_TCP_CMDSO_H_
#include <sys/types.h>
#include <stdint.h>
#include <netinet/in.h>
/* */
typedef intptr_t ngx_tcp_int_t;
typedef uintptr_t ngx_tcp_uint_t;
typedef intptr_t ngx_tcp_flag_t;
typedef int ngx_tcp_err_t;
#define NGX_TCP_LOG_STDERR 0
#define NGX_TCP_LOG_EMERG 1
#define NGX_TCP_LOG_ALERT 2
#define NGX_TCP_LOG_CRIT 3
#define NGX_TCP_LOG_ERR 4
#define NGX_TCP_LOG_WARN 5
#define NGX_TCP_LOG_NOTICE 6
#define NGX_TCP_LOG_INFO 7
#define NGX_TCP_LOG_DEBUG 8
typedef struct ngx_tcp_ctx_s ngx_tcp_ctx_t;
typedef long (*ngx_tcp_send_data_pt)(ngx_tcp_ctx_t *ctx,
const u_char *data,
int len);
typedef void (*ngx_tcp_log_error_pt)(ngx_tcp_uint_t level, void *log,
ngx_tcp_err_t err,
const char *fmt, ...);
typedef void *(*ngx_tcp_alloc_pt)(void *pool, size_t size);
typedef ngx_tcp_int_t (*ngx_tcp_pfree_pt)(void *pool, void *p);
typedef ngx_tcp_int_t (*ngx_tcp_conf_get_str_pt)(const char *section,
const char *k, char **v);
struct ngx_tcp_ctx_s {
/* cmdso_sessioin array. the slot is init in cmdso_load func */
void **cmdso_sessioin;
void *ngx_tcp_session;
ngx_tcp_send_data_pt send_data;
ngx_tcp_conf_get_str_pt conf_get_str;
void *log;
ngx_tcp_log_error_pt log_error;
void *pool;
ngx_tcp_alloc_pt palloc;
ngx_tcp_alloc_pt pcalloc;
ngx_tcp_pfree_pt pfree;
};
typedef long (*cmd_pkg_handler_pt)(ngx_tcp_ctx_t *ctx,
const u_char *pkg,
int pkg_len);
typedef long
(*cmd_pkg_handler_add_pt)(void *cycle_param,
uint32_t cmd_min, uint32_t cmd_max,
cmd_pkg_handler_pt h);
#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, cmd_pkg_handler_add_pt add_h, int slot);
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)
#endif