1 // SPDX-License-Identifier: GPL-2.0-only
5 * It is a user space utility to receive android ion memory buffer fd
6 * over unix domain socket IPC that can be exported by ionapp_export.
7 * This acts like a client for ionapp_export.
9 * Copyright (C) 2017 Pintu Kumar <pintu.ping@gmail.com>
17 #include "ipcsocket.h"
23 int sockfd
, shared_fd
;
24 unsigned char *map_buf
;
25 unsigned long map_len
;
26 struct ion_buffer_info info
;
27 struct socket_info skinfo
;
29 /* This is the client part. Here 0 means client or importer */
30 status
= opensocket(&sockfd
, SOCKET_NAME
, 0);
32 fprintf(stderr
, "No exporter exists...\n");
37 skinfo
.sockfd
= sockfd
;
39 ret
= socket_receive_fd(&skinfo
);
41 fprintf(stderr
, "Failed: socket_receive_fd\n");
45 shared_fd
= skinfo
.datafd
;
46 printf("Received buffer fd: %d\n", shared_fd
);
48 fprintf(stderr
, "ERROR: improper buf fd\n");
53 memset(&info
, 0, sizeof(info
));
54 info
.buffd
= shared_fd
;
55 info
.buflen
= ION_BUFFER_LEN
;
57 ret
= ion_import_buffer_fd(&info
);
59 fprintf(stderr
, "Failed: ion_use_buffer_fd\n");
63 map_buf
= info
.buffer
;
64 map_len
= info
.buflen
;
65 read_buffer(map_buf
, map_len
);
67 /* Write probably new data to the same buffer again */
68 map_len
= ION_BUFFER_LEN
;
69 write_buffer(map_buf
, map_len
);
72 ion_close_buffer_fd(&info
);
76 closesocket(sockfd
, SOCKET_NAME
);