4 * It is a user space utility to receive android ion memory buffer fd
5 * over unix domain socket IPC that can be exported by ionapp_export.
6 * This acts like a client for ionapp_export.
8 * Copyright (C) 2017 Pintu Kumar <pintu.ping@gmail.com>
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
26 #include "ipcsocket.h"
32 int sockfd
, shared_fd
;
33 unsigned char *map_buf
;
34 unsigned long map_len
;
35 struct ion_buffer_info info
;
36 struct socket_info skinfo
;
38 /* This is the client part. Here 0 means client or importer */
39 status
= opensocket(&sockfd
, SOCKET_NAME
, 0);
41 fprintf(stderr
, "No exporter exists...\n");
46 skinfo
.sockfd
= sockfd
;
48 ret
= socket_receive_fd(&skinfo
);
50 fprintf(stderr
, "Failed: socket_receive_fd\n");
54 shared_fd
= skinfo
.datafd
;
55 printf("Received buffer fd: %d\n", shared_fd
);
57 fprintf(stderr
, "ERROR: improper buf fd\n");
62 memset(&info
, 0, sizeof(info
));
63 info
.buffd
= shared_fd
;
64 info
.buflen
= ION_BUFFER_LEN
;
66 ret
= ion_import_buffer_fd(&info
);
68 fprintf(stderr
, "Failed: ion_use_buffer_fd\n");
72 map_buf
= info
.buffer
;
73 map_len
= info
.buflen
;
74 read_buffer(map_buf
, map_len
);
76 /* Write probably new data to the same buffer again */
77 map_len
= ION_BUFFER_LEN
;
78 write_buffer(map_buf
, map_len
);
81 ion_close_buffer_fd(&info
);
85 closesocket(sockfd
, SOCKET_NAME
);