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
| #include <stdio.h>
|
| #include "src2/shmh.h"
| #include <sys/types.h>
| #include <sys/stat.h>
|
| #include <thread>
| #include <unistd.h>
| using namespace std;
|
| static int handle_memfd(void* args, struct fd_msg* msg){
| int fd = msg->fd;
| if (fd > 0){
| // struct stat st;
| // if (fstat (fd, &st))
| // {
| // return -1;
| // }
| // printf("st size %ld\n", st.st_size);
|
| unsigned char* addr;
| int len = basic_shm_mmap(fd, &addr);
| if (len <= 0) {
| printf("======>> basic_shm_mmap failed\n");
| return -1;
| }
| printf("======>> mmap len %d msg %s\n", len, addr);
| basic_shm_unmmap(fd, &addr);
| basic_shm_close(fd);
| return fd;
| }
| return 0;
| }
|
| int main(int argc, char const *argv[])
| {
| int sock = unix_domain_server_fd("/tmp/memfd_shm.sock", 1);
| if (sock < 0){
| printf("unix_domain_server_fd failed\n");
| return 0;
| }
|
| thread t([&sock]{
| epoll_loop(sock, NULL, handle_memfd, NULL, NULL);
| // poll_loop(sock, NULL, handle_memfd, NULL, NULL);
| // select_loop(sock, NULL, handle_memfd, NULL, NULL);
| });
|
| t.join();
| close(sock);
|
| return 0;
| }
|
|