zhangmeng
2020-08-06 c3d4d0f6ad26e7291d581d24fd64ae55e8f0c1fe
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#ifndef _c_libshm_queue_so_func_h_
#define _c_libshm_queue_so_func_h_
 
 
#ifdef __cplusplus
extern "C"{
#endif
 
/**
 * 初始化共享内存
 * @size 共享内存大小
 *
 */
typedef void(*tfn_shm_init)(int);
/**
 * 销毁共享内存
 * 整个进程退出时需要执行这个方法,该方法首先会检查是否还有其他进程在使用该共享内存,如果还有其他进程在使用就只是detach,如果没有其他进程在使用则销毁整块内存。
 */
typedef void(*tfn_shm_destroy)();
/**
 * 获取key
 */
typedef int(*tfn_shm_alloc_key) ();
 
//移除不包含在keys中的队列
typedef void (*tfn_shm_rm_dead_queue)(void *keys, int length);
 
/**
 * 创建队列
 * @ shmqueue
 * @ key 标识共享队列的唯一标识, key是一个指针里面存储了key的值, 如果key的值为-1系统会自动分配一个key值并把该key的值赋给key指针。如果key的值不会空会检查是否有重复绑定的情况, 有重复就报错没有就创建队列并绑定key.
 * @ queue_size 队列大小
 */
typedef void*(*tfn_queue_create) (int*, int);
/**
 * 绑定key到队列,但是并不会创建队列。如果没有对应指定key的队列提示错误并返回空值
 */
typedef void*(*tfn_queue_attach) (int);
/**
 * 销毁
*/
typedef void(*tfn_queue_drop) (void*);
/**
 * 队列元素的个数
 */
typedef int(*tfn_queue_size) (void*);
/**
 * 是否已满
 * * @return 1是, 0否
 */
typedef int(*tfn_queue_full) (void*);
/**
 * 是否为空
 * @return 1是, 0否
 */
typedef int(*tfn_queue_empty) (void*);
/**
 * 入队, 队列满时等待.
 * @return 1 入队成功, 0 入队失败
 */
typedef int(*tfn_queue_push) (void*, void*, int);
/**
 * 入队, 队列满时立即返回.
 * @return 1 入队成功, 0 入队失败
 */
typedef tfn_queue_push tfn_queue_push_nowait;
/**
 * 入队, 指定时间内入队不成功就返回
 * @sec 秒
 * @nsec 纳秒
 * @return 1 入队成功, 0 入队失败
 */
typedef int(*tfn_queue_push_timeout) (void*, void*, int, int, int);
/**
 * 出队, 队列空时等待
 * @return 1 出队成功, 0出队失败
 */
typedef int(*tfn_queue_pop) (void*, void**, int *);
/**
 * 出队, 队列空时立即返回
 * @return 1 出队成功, 0出队失败
 */
typedef tfn_queue_pop tfn_queue_pop_nowait;
/**
 * 出队, 指定时间内出队不成功就返回
 * @sec秒
 * @nsec纳秒
 * @return 1 出队成功, 0出队失败
 */
typedef int(*tfn_queue_pop_timeout) (void*, void**, int *, int, int);
/**
 * 释放出队分配的内存
 */
typedef void (*tfn_queue_free_poped)(void *ptr);
 
////////////////////////////
// socket mode
////////////////////////////
enum socket_mod_t
{
    PULL_PUSH = 1,
    REQ_REP = 2,
    PAIR = 3,
    PUB_SUB = 4,
    SURVEY = 5,
    BUS = 6
 
};
 
/**
 * 创建socket
 * @return socket地址
*/
typedef void*(*tfn_socket_open) (int);
/**
 * 关闭socket
*/
typedef int(*tfn_socket_close) (void*);
/**
 * 绑定端口到socket, 如果不绑定则系统自动分配一个
 * @return 0 成功, 其他值 失败的错误码
*/
typedef int(*tfn_socket_bind) (void*, int);
/**
 * 服务端开启连接监听
 * @return 0 成功, 其他值 失败的错误码
 */
typedef int(*tfn_socket_listen) (void*);
/**
 * 客户端发起连接请求
 */
typedef int(*tfn_socket_connect) (void*, int);
/**
 * 发送信息
 * @return 0 成功, 其他值 失败的错误码
 */
typedef int(*tfn_socket_send) (void*, const void*, const int);
/**
 * 接收信息
 * @return 0 成功, 其他值 失败的错误码
*/
typedef int(*tfn_socket_recv) (void*, void**, int*);
 
/**
 * 释放接收信息的buf
 */
typedef void(*tfn_socket_buf_free) (void*);
 
/**
 * 获取soket端口号
 */
typedef int(*tfn_socket_port) (void*);
 
//////////////////////////////////////////////
// dgram socket
/**
 * 创建socket
 * @return socket地址
*/
typedef void*(*tfn_dgram_socket_open) ();
/**
 * 关闭socket
 * @return 0 成功, 其他值 失败的错误码
*/
typedef int(*tfn_dgram_socket_close) (void*);
/**
 * 绑定端口到socket, 如果不绑定则系统自动分配一个
 * @return 0 成功, 其他值 失败的错误码
*/
typedef int(*tfn_dgram_socket_bind) (void*, int);
typedef tfn_dgram_socket_bind tfn_dgram_socket_force_bind;
/**
 * 发送信息
 * @port 发送给谁
 * @return 0 成功, 其他值 失败的错误码
 */
typedef int(*tfn_dgram_socket_sendto) (void*, const void*, const int, const int);
// 发送信息超时返回。 @sec 秒 , @nsec 纳秒
typedef int(*tfn_dgram_socket_sendto_timeout) (void*, const void*, const int, const int, int, int);
// 发送信息立刻返回。
typedef tfn_dgram_socket_sendto tfn_dgram_socket_sendto_nowait;
/**
 * 接收信息
 * @port 从谁哪里收到的信息
 * @return 0 成功, 其他值 失败的错误码
*/
typedef int(*tfn_dgram_socket_recvfrom) (void*, void**, int*, int*);
typedef int(*tfn_dgram_socket_recvfrom_timeout) (void*, void**, int*, int*, int, int);
typedef tfn_dgram_socket_recvfrom tfn_dgram_socket_recvfrom_nowait;
/**
 * 发送请求信息并等待接收应答
 * @port 发送给谁
 * @return 0 成功, 其他值 失败的错误码
*/
typedef int(*tfn_dgram_socket_sendandrecv) (void*, const void*, const int, const int, void**, int*);
typedef int(*tfn_dgram_socket_sendandrecv_timeout) (void*, const void*, const int, const int, void**, int*, int, int);
typedef tfn_dgram_socket_sendandrecv tfn_dgram_socket_sendandrecv_nowait;
/**
 * 启动bus
 *
 * @return 0 成功, 其他值 失败的错误码
*/
typedef int(*tfn_dgram_socket_start_bus) (void*);
/**
 * 订阅指定主题
 * @topic 主题
 * @size 主题长度
 * @port 总线端口
 */
typedef int(*tfn_dgram_socket_sub) (void*, void*, int, int);
typedef int(*tfn_dgram_socket_sub_timeout) (void*, void*, int, int, int, int);
typedef tfn_dgram_socket_sub tfn_dgram_socket_sub_nowait;
/**
 * 取消订阅指定主题
 * @topic 主题
 * @size 主题长度
 * @port 总线端口
 */
typedef tfn_dgram_socket_sub tfn_dgram_socket_desub;
typedef tfn_dgram_socket_sub_timeout tfn_dgram_socket_desub_timeout;
typedef tfn_dgram_socket_sub_nowait tfn_dgram_socket_desub_nowait;
/**
 * 发布主题
 * @topic 主题
 * @content 主题内容
 * @port 总线端口
 */
typedef int(*tfn_dgram_socket_pub) (void*, void*, int, void*, int, int);
typedef int(*tfn_dgram_socket_pub_timeout) (void*, void*, int, void*, int, int, int, int);
typedef tfn_dgram_socket_pub tfn_dgram_socket_pub_nowait;
/**
 * 获取soket端口号
 */
typedef int(*tfn_dgram_socket_port) (void*);
/**
 * 释放存储接收信息的buf
 */
typedef void(*tfn_dgram_socket_free) (void*);
 
/**
 * 删除key对应的共享队列,并在bus里删除该key的订阅
 */
 
typedef int(*tfn_dgram_remove_key) (int);
/**
 * 批量删除key对应的共享队列,并在bus里删除该key的订阅
 */
typedef int(*tfn_dgram_remove_keys) (int*, int);
 
 
#ifdef __cplusplus
}
#endif
 
#endif