#include #include "src2/shmh.h" #include #include #include #include using namespace std; static int idx = 0; static int get_memfd(void* args, struct fd_msg* msg){ int fd = basic_shm_create("shm", 128*1024*1024); if (fd > 0){ // struct stat st; // if (fstat (fd, &st)) // { // return -1; // } // printf("st size %ld\n", st.st_size); msg->fd = fd; unsigned char* addr; if (basic_shm_mmap(fd, &addr) > 0){ sprintf((char*)addr, "get_memfd set msg %d", idx++); basic_shm_unmmap(fd, &addr); } 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, get_memfd, NULL, NULL); // poll_loop(sock, get_memfd, NULL, NULL); // select_loop(sock, get_memfd, NULL, NULL); simple_loop(sock, get_memfd, NULL, NULL); }); t.join(); close(sock); return 0; }