[PATCH 2/2] Add SEND_FDS version of Readv

Keith Packard keithp at keithp.com
Sun Nov 3 03:27:15 CET 2013


Now that we've found that libFS uses readv, we can test whether this
readv implementation works correctly.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 Xtranssock.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/Xtranssock.c b/Xtranssock.c
index 23150b2..84e4dcd 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -2273,7 +2273,31 @@ TRANS(SocketReadv) (XtransConnInfo ciptr, struct iovec *buf, int size)
 {
     prmsg (2,"SocketReadv(%d,%p,%d)\n", ciptr->fd, buf, size);
 
+#if XTRANS_SEND_FDS
+    {
+        struct msghdr   msg;
+        struct fd_pass  pass;
+
+        init_msg_recv(&msg, buf, size, &pass, MAX_FDS);
+        size = recvmsg(ciptr->fd, &msg, 0);
+        if (size >= 0 && msg.msg_controllen > sizeof (struct cmsghdr)) {
+            if (pass.cmsghdr.cmsg_level == SOL_SOCKET &&
+                pass.cmsghdr.cmsg_type == SCM_RIGHTS &&
+                !((msg.msg_flags & MSG_TRUNC) ||
+                  (msg.msg_flags & MSG_CTRUNC)))
+            {
+                int nfd = (msg.msg_controllen - sizeof (struct cmsghdr)) / sizeof (int);
+                int *fd = (int *) CMSG_DATA(&pass.cmsghdr);
+                int i;
+                for (i = 0; i < nfd; i++)
+                    appendFd(&ciptr->recv_fds, fd[i], 0);
+            }
+        }
+        return size;
+    }
+#else
     return READV (ciptr, buf, size);
+#endif
 }
 
 
-- 
1.8.4.2



More information about the xorg-devel mailing list