[PATCH 1/2] connection: add wl_connection_copy_fds function

Marek Chalupa mchqwerty at gmail.com
Sun Jul 20 07:42:46 PDT 2014


this function pipes filedescriptors from one connection to another
(from input buffer to output buffer). Handy in dump tool.
---
 src/connection.c      | 24 ++++++++++++++++++++++++
 src/wayland-private.h |  1 +
 2 files changed, 25 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index f292853..ba886d1 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -406,6 +406,30 @@ wl_connection_put_fd(struct wl_connection *connection, int32_t fd)
 	return wl_buffer_put(&connection->fds_out, &fd, sizeof fd);
 }
 
+/*
+ * pipe fds from one connection to another, it will remove the fds from
+ * the first connection
+ */
+int
+wl_connection_copy_fds(struct wl_connection *conn1, struct wl_connection *conn2)
+{
+	uint32_t size = wl_buffer_size(&conn1->fds_in);
+
+	if (size == 0)
+		return 0;
+
+	if (size + wl_buffer_size(&conn2->fds_out)
+		>= MAX_FDS_OUT * sizeof(int32_t)) {
+		conn2->want_flush = 1;
+		if (wl_connection_flush(conn2) < 0)
+			return -1;
+	}
+
+	conn1->fds_in.tail += size;
+
+	return wl_buffer_put(&conn2->fds_out, &conn1->fds_in.data, size);
+}
+
 const char *
 get_next_argument(const char *signature, struct argument_details *details)
 {
diff --git a/src/wayland-private.h b/src/wayland-private.h
index 67e8783..adb8e2e 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -96,6 +96,7 @@ int wl_connection_read(struct wl_connection *connection);
 int wl_connection_write(struct wl_connection *connection, const void *data, size_t count);
 int wl_connection_queue(struct wl_connection *connection,
 			const void *data, size_t count);
+int wl_connection_copy_fds(struct wl_connection *conn1, struct wl_connection *conn2);
 
 struct wl_closure {
 	int count;
-- 
2.0.1



More information about the wayland-devel mailing list