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
| #ifndef _epoll_fd_shm_h_
| #define _epoll_fd_shm_h_
|
| #ifndef HIDDENAPI
| #define HIDDENAPI __attribute__((visibility("hidden")))
| #endif
|
| #ifdef __cplusplus
| extern "C" {
| #endif
|
| int unix_domain_server_fd(const char* path, int nonblock);
| int unix_domain_client_fd(const char* path, int nonblock);
|
| struct fd_msg{
| void* data;
| union{
| int len;
| int fd;
| };
| };
|
| typedef int(*cbGetData)(void* args, struct fd_msg* msg);
| typedef cbGetData cbHandleData;
|
| typedef int(*cbQuit)(void* args);
|
| // 效率很高,但是无法保证给所有的客户端发送同一个消息, 2w+/s
| int epoll_loop(int listenfd, cbGetData fget, cbHandleData fhandle, cbQuit fquit, void* args);
| int poll_loop(int listenfd, cbGetData fget, cbHandleData fhandle, cbQuit fquit, void* args);
| int select_loop(int listenfd, cbGetData fget, cbHandleData fhandle, cbQuit fquit, void* args);
| // 认为大部分时间都可写,保证给客户端发送同一个消息, block IO, only send, 1w+/s
| int simple_loop(int listenfd, cbGetData fget, cbQuit fquit, void* args);
|
|
| // 客户端没有并发需求,只需要在 loop 中不停 recvfd 即可
|
|
| // 应该没什么用
| HIDDENAPI void free_fd_msg(struct fd_msg* msg);
|
| #ifdef __cplusplus
| }
| #endif
|
| #endif
|
|