summaryrefslogtreecommitdiffstats
path: root/src/gallium/winsys/virgl
diff options
context:
space:
mode:
authorGurchetan Singh <[email protected]>2018-12-11 17:01:34 -0800
committerGurchetan Singh <[email protected]>2019-04-18 15:38:52 -0700
commit9881733e328e3b9cb15bdfa9105fd33001cd7182 (patch)
treef2e4d78a94c95525ddbacf2b90415e06278814b3 /src/gallium/winsys/virgl
parent0dd661777a489d1134707ebc770af9e21e44e0dc (diff)
virgl/vtest: add utilities for receiving fds
v2: recieve --> receive (airlied@) Signed-off-by: Gurchetan Singh <[email protected]> Reviewed-By: Gert Wollny <[email protected]> Reviewed-By: Piotr Rak <[email protected]>
Diffstat (limited to 'src/gallium/winsys/virgl')
-rw-r--r--src/gallium/winsys/virgl/vtest/virgl_vtest_socket.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/gallium/winsys/virgl/vtest/virgl_vtest_socket.c b/src/gallium/winsys/virgl/vtest/virgl_vtest_socket.c
index 410cfa2cc04..5baeaf4c952 100644
--- a/src/gallium/winsys/virgl/vtest/virgl_vtest_socket.c
+++ b/src/gallium/winsys/virgl/vtest/virgl_vtest_socket.c
@@ -72,6 +72,49 @@ static int virgl_block_read(int fd, void *buf, int size)
return size;
}
+static int virgl_vtest_receive_fd(int socket_fd)
+{
+ struct cmsghdr *cmsgh;
+ struct msghdr msgh = { 0 };
+ char buf[CMSG_SPACE(sizeof(int))], c;
+ struct iovec iovec;
+
+ iovec.iov_base = &c;
+ iovec.iov_len = sizeof(char);
+
+ msgh.msg_name = NULL;
+ msgh.msg_namelen = 0;
+ msgh.msg_iov = &iovec;
+ msgh.msg_iovlen = 1;
+ msgh.msg_control = buf;
+ msgh.msg_controllen = sizeof(buf);
+ msgh.msg_flags = 0;
+
+ int size = recvmsg(socket_fd, &msgh, 0);
+ if (size < 0) {
+ fprintf(stderr, "Failed with %s\n", strerror(errno));
+ return -1;
+ }
+
+ cmsgh = CMSG_FIRSTHDR(&msgh);
+ if (!cmsgh) {
+ fprintf(stderr, "No headers available\n");
+ return -1;
+ }
+
+ if (cmsgh->cmsg_level != SOL_SOCKET) {
+ fprintf(stderr, "invalid cmsg_level %d\n", cmsgh->cmsg_level);
+ return -1;
+ }
+
+ if (cmsgh->cmsg_type != SCM_RIGHTS) {
+ fprintf(stderr, "invalid cmsg_type %d\n", cmsgh->cmsg_type);
+ return -1;
+ }
+
+ return *((int *) CMSG_DATA(cmsgh));
+}
+
static int virgl_vtest_send_init(struct virgl_vtest_winsys *vws)
{
uint32_t buf[VTEST_HDR_SIZE];