wangzhengquan
2020-07-25 48ae739d196e8a1ad681e5a54ad992302119bd83
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
#ifndef __DGRAM_MOD_SOCKET_H__
#define __DGRAM_MOD_SOCKET_H__
 
 
#ifdef __cplusplus
extern "C" {
#endif
 
 
/**
 * 创建socket
 * @return socket地址
*/
void *dgram_mod_open_socket();
 
/**
 * 关闭socket
 * @return 0 成功, 其他值 失败的错误码
*/
int dgram_mod_close_socket(void * _socket);
 
/**
 * 绑定端口到socket, 如果不绑定则系统自动分配一个
 * @return 0 成功, 其他值 失败的错误码
*/
int dgram_mod_bind(void * _socket, int port);
 
/**
 * 发送信息
 * @port 发送给谁
 * @return 0 成功, 其他值 失败的错误码
 */
int dgram_mod_sendto(void *_socket, const void *buf, const int size, const int port);
 
 
/**
 * 接收信息
 * @port 从谁哪里收到的信息
 * @return 0 成功, 其他值 失败的错误码
*/
int dgram_mod_recvfrom(void *_socket, void **buf, int *size, int *port);
 
/**
 * 发送请求信息并等待接收应答
 * @port 发送给谁
 * @return 0 成功, 其他值 失败的错误码
*/
int dgram_mod_sendandrecv(void * _socket, const void *send_buf, const int send_size, const int port, void **recv_buf, int *recv_size) ;
 
/**
 * 获取soket端口号
 */
int dgram_mod_get_port(void * _socket) ;
 
 
/**
 * 释放存储接收信息的buf
 */
void dgram_mod_free(void *buf) ;
 
/**
 * 启动bus
 * 
 * @return 0 成功, 其他值 失败的错误码
*/
int start_bus(void * _socket);
 
/**
 * 订阅指定主题
 * @topic 主题
 * @size 主题长度
 * @port 总线端口
 */
int sub(void * _socket, void *topic, int size, int port);
 
/**
 * 发布主题
 * @topic 主题
 * @content 主题内容
 * @port 总线端口
 */
int pub(void * _socket, void *topic, int topic_size, void *content, int content_size, int port);
 
 
#ifdef __cplusplus
}
#endif
 
#endif