From 74d7000943e1037303294332b415b0b4b5e8291c Mon Sep 17 00:00:00 2001
From: Zebediah Figura <z.figura12@gmail.com>
Date: Fri, 8 Jun 2018 18:55:49 -0500
Subject: [PATCH 14/83] server: Add a request to get the eventfd file
 descriptor associated with a waitable handle.

---
 server/esync.c      | 28 ++++++++++++++++++++++++++++
 server/protocol.def |  6 ++++++
 2 files changed, 34 insertions(+)

diff --git a/server/esync.c b/server/esync.c
index f3a139da4..351da1a7c 100644
--- a/server/esync.c
+++ b/server/esync.c
@@ -136,3 +136,31 @@ DECL_HANDLER(create_esync)
 
     if (root) release_object( root );
 }
+
+/* Retrieve a file descriptor for an esync object which will be signaled by the
+ * server. The client should only read from (i.e. wait on) this object. */
+DECL_HANDLER(get_esync_fd)
+{
+    struct object *obj;
+    int fd;
+
+    if (!(obj = get_handle_obj( current->process, req->handle, SYNCHRONIZE, NULL )))
+        return;
+
+    if (obj->ops->get_esync_fd)
+    {
+        fd = obj->ops->get_esync_fd( obj );
+        send_client_fd( current->process, fd, req->handle );
+    }
+    else
+    {
+        if (debug_level)
+        {
+            fprintf( stderr, "%04x: esync: can't wait on object: ", current->id );
+            obj->ops->dump( obj, 0 );
+        }
+        set_error( STATUS_NOT_IMPLEMENTED );
+    }
+
+    release_object( obj );
+}
diff --git a/server/protocol.def b/server/protocol.def
index a56f098ab..5f2d77bc7 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -4051,3 +4051,9 @@ struct handle_info
 @REPLY
     obj_handle_t handle;        /* handle to the object */
 @END
+
+/* Retrieve the esync fd for an object. */
+@REQ(get_esync_fd)
+    obj_handle_t handle;        /* handle to the object */
+@REPLY
+@END
-- 
2.20.1

