| | |
| | | #include <errno.h> |
| | | #include "ipc_msg.h" |
| | | |
| | | int basic_create_ipc_client(char * unix_domain_path, memfd_data_st * ptr_memfd_data) |
| | | |
| | | int basic_create_ipc_client(char * unix_domain_path, char * send_buf, int send_len, void ** pptr_recv_buf, int *ptr_recv_len) |
| | | { |
| | | int fd; |
| | | int connect_fd; |
| | | struct sockaddr_un srv_addr; |
| | | char snd_buf[MAX_LEN] = {0}; |
| | | char rcv_buf[MAX_LEN] = {0}; |
| | | int ret; |
| | | int i; |
| | | char *fd_path; |
| | | int rcv_num = 0; |
| | | char buf[MAX_LEN] = {0}; |
| | | int recv_len = 0; |
| | | |
| | | if((NULL == pptr_recv_buf)||(NULL == ptr_recv_len)) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | if (strlen(unix_domain_path) > sizeof(srv_addr.sun_path)) |
| | | { |
| | | perror("too long filename!\n"); |
| | | return -1; |
| | | } |
| | | |
| | | connect_fd = socket(AF_UNIX, SOCK_STREAM, 0); |
| | | |
| | | if(connect_fd < 0) |
| | | { |
| | | perror("client create socket failed"); |
| | | return 1; |
| | | return -1; |
| | | } |
| | | srv_addr.sun_family = AF_UNIX; |
| | | |
| | |
| | | { |
| | | perror("connect to server failed!"); |
| | | close(connect_fd); |
| | | unlink(UNIX_DOMAIN); |
| | | return 1; |
| | | //unlink(unix_domain_path); |
| | | return -1; |
| | | } |
| | | |
| | | printf("connect to server path:%s success!", srv_addr.sun_path); |
| | |
| | | //int rcv_num = read(connect_fd, rcv_buf, sizeof(rcv_buf)); |
| | | //memcpy(&memfd_data, rcv_buf, sizeof(memfd_data_st)); |
| | | |
| | | memset(snd_buf, 0, 256); |
| | | strcpy(snd_buf, HELLO_MSG); |
| | | printf("sizeof(snd_buf): %ld\n", sizeof(snd_buf)); |
| | | |
| | | printf("send data to server... ...\n"); |
| | | write(connect_fd, snd_buf, sizeof(snd_buf)); |
| | | write(connect_fd, send_buf, send_len); |
| | | printf("send end!\n"); |
| | | |
| | | memset(rcv_buf, 0, sizeof(rcv_buf)); |
| | | rcv_num = read(connect_fd, rcv_buf, sizeof(rcv_buf)); |
| | | if(rcv_num == 0) |
| | | recv_len = read(connect_fd, buf, sizeof(buf)); |
| | | if(recv_len == 0) |
| | | { |
| | | close(connect_fd); |
| | | return 0; |
| | | return -1; |
| | | } |
| | | memcpy(ptr_memfd_data, rcv_buf, rcv_num); |
| | | |
| | | memcpy(*pptr_recv_buf, buf, recv_len); |
| | | *ptr_recv_len = recv_len; |
| | | close(connect_fd); |
| | | |
| | | return 0; |
| | | } |