| | |
| | | #include <stdio.h> |
| | | #include <string.h> |
| | | #include <stdlib.h> |
| | | #include "memfd.h" |
| | | #include "ipc_msg.h" |
| | | |
| | |
| | | { |
| | | int fd = 0; |
| | | int ret; |
| | | int i; |
| | | char *fd_path; |
| | | int recv_len = 0; |
| | | memfd_data_st memfd_data = {0}; |
| | | int rcv_num = 0; |
| | | char snd_buf[MAX_LEN] = {0}; |
| | | char * unix_domain_path = NULL; |
| | | |
| | | ret = basic_create_ipc_client(UNIX_DOMAIN, &memfd_data); |
| | | char *recv_buf = (char *)malloc(MAX_LEN); |
| | | |
| | | /*client get memfd from server*/ |
| | | memset(snd_buf, 0, sizeof(snd_buf)); |
| | | strncpy(snd_buf, GET_MEMFD_MSG, strlen(GET_MEMFD_MSG) + 1); |
| | | printf("snd_buf: %s\n", snd_buf); |
| | | memset(recv_buf, 0, MAX_LEN); |
| | | |
| | | unix_domain_path = UNIX_DOMAIN; |
| | | ret = basic_create_ipc_client(unix_domain_path, snd_buf, strlen(snd_buf), (void **)&recv_buf, &recv_len); |
| | | if(ret < 0) |
| | | { |
| | | return ret; |
| | | } |
| | | |
| | | memcpy(&memfd_data, recv_buf, sizeof(memfd_data)); |
| | | |
| | | printf("receive message from server,pid:%d, memfd:%d\n", memfd_data.pid, memfd_data.memfd); |
| | | if ((memfd_data.pid != 0) && (memfd_data.memfd != 0)) |
| | | { |
| | | char fd_path[256] = {0}; |
| | | snprintf(fd_path, sizeof(fd_path), "/proc/%d/fd/%d", memfd_data.pid, memfd_data.memfd); |
| | | fprintf(stderr,"fd_path:%s\n", fd_path); |
| | | fd = basic_shm_open(memfd_data.memfd, memfd_data.pid, 1); |
| | | ret = memfd_read(fd); |
| | | } |
| | | |
| | | basic_shm_close(fd); |
| | | |
| | | /*client get memfd and custom data from server*/ |
| | | #if 1 |
| | | |
| | | memset(snd_buf, 0, sizeof(snd_buf)); |
| | | strncpy(snd_buf, GET_CUSTOM_MSG, strlen(GET_CUSTOM_MSG) + 1); |
| | | printf("\nsnd_buf: %s\n", snd_buf); |
| | | memset(recv_buf, 0, MAX_LEN); |
| | | |
| | | unix_domain_path = UNIX_DOMAIN; |
| | | ret = basic_create_ipc_client(unix_domain_path, snd_buf, strlen(snd_buf), (void **)&recv_buf, &recv_len); |
| | | if(ret < 0) |
| | | { |
| | | return ret; |
| | | } |
| | | |
| | | memcpy(&memfd_data, recv_buf, sizeof(memfd_data)); |
| | | if(memfd_data.len > 0) |
| | | { |
| | | memfd_data.data = malloc(memfd_data.len); |
| | | memcpy(memfd_data.data, recv_buf+sizeof(memfd_data), memfd_data.len); |
| | | } |
| | | |
| | | printf("receive message from server,pid:%d, memfd:%d\n", memfd_data.pid, memfd_data.memfd); |
| | |
| | | char fd_path[256] = {0}; |
| | | snprintf(fd_path, sizeof(fd_path), "/proc/%d/fd/%d", memfd_data.pid, memfd_data.memfd); |
| | | fprintf(stderr,"fd_path:%s\n", fd_path); |
| | | fd = basic_shm_open(memfd_data.memfd, memfd_data.pid , 1); |
| | | fd = basic_shm_open(memfd_data.memfd, memfd_data.pid, 1); |
| | | ret = memfd_read(fd); |
| | | } |
| | | |
| | | basic_shm_close(fd); |
| | | fprintf(stderr,"custom data:%s\n", (char *)memfd_data.data); |
| | | if(memfd_data.len > 0) |
| | | { |
| | | free(memfd_data.data); |
| | | } |
| | | #endif |
| | | |
| | | #if 1 |
| | | /*client get usedata from server*/ |
| | | memset(snd_buf, 0, sizeof(snd_buf)); |
| | | strncpy(snd_buf, GET_DATA_MSG, strlen(GET_DATA_MSG) + 1); |
| | | printf("\nsnd_buf: %s\n", snd_buf); |
| | | memset(recv_buf, 0, MAX_LEN); |
| | | recv_len = 0; |
| | | |
| | | //unix_domain_path="/tmp/unix_domain_usedata"; |
| | | ret = basic_create_ipc_client(unix_domain_path, snd_buf, strlen(snd_buf), (void **)&recv_buf, &recv_len); |
| | | if(ret < 0) |
| | | { |
| | | return ret; |
| | | } |
| | | printf("receive message from server msg:%s\n", recv_buf); |
| | | /*deal the recv_buf*/ |
| | | #endif |
| | | |
| | | free(recv_buf); |
| | | return 0; |
| | | |
| | | } |