[Spice-devel] [PATCH v2 3/6] introduce DISPATCHER_{NONE, ACK, ASYNC}

Alon Levy alevy at redhat.com
Mon Nov 7 03:44:43 PST 2011


---
 server/dispatcher.c |   12 +++++++-----
 server/dispatcher.h |   13 +++++++++++--
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/server/dispatcher.c b/server/dispatcher.c
index e2973a4..b54580e 100644
--- a/server/dispatcher.c
+++ b/server/dispatcher.c
@@ -105,10 +105,12 @@ static int dispatcher_handle_single_read(Dispatcher *dispatcher)
     } else {
         red_printf("error: no handler for message type %d\n", type);
     }
-    if (msg->ack && write_safe(dispatcher->recv_fd,
-                               &ack, sizeof(ack)) == -1) {
-        red_printf("error writing ack for message %d\n", type);
-        /* TODO: close socketpair? */
+    if (msg->ack == DISPATCHER_ACK) {
+        if (write_safe(dispatcher->recv_fd,
+                       &ack, sizeof(ack)) == -1) {
+            red_printf("error writing ack for message %d\n", type);
+            /* TODO: close socketpair? */
+        }
     }
     return 1;
 }
@@ -144,7 +146,7 @@ void dispatcher_send_message(Dispatcher *dispatcher, uint32_t message_type,
                    message_type);
         goto unlock;
     }
-    if (msg->ack) {
+    if (msg->ack == DISPATCHER_ACK) {
         if (read_safe(send_fd, &ack, sizeof(ack), 1) == -1) {
         }
         if (ack != ACK) {
diff --git a/server/dispatcher.h b/server/dispatcher.h
index 04e6b46..95b6bfc 100644
--- a/server/dispatcher.h
+++ b/server/dispatcher.h
@@ -45,13 +45,22 @@ void dispatcher_send_message(Dispatcher *dispatcher, uint32_t message_type,
 void dispatcher_init(Dispatcher *dispatcher, size_t max_message_type,
                      void *opaque);
 
+enum {
+    DISPATCHER_NONE = 0,
+    DISPATCHER_ACK,
+    DISPATCHER_ASYNC
+};
+
 /*
  * dispatcher_register_handler
- * @dispatcher:           dispatcher
+ * @dispatcher:     dispatcher
  * @messsage_type:  message type
  * @handler:        message handler
  * @size:           message size. Each type has a fixed associated size.
- * @ack:            send an ack. This is per message type - you can't send the
+ * @ack:            One of DISPATCHER_NONE, DISPATCHER_ACK, DISPATCHER_ASYNC.
+ *                  DISPATCHER_NONE - only send the message
+ *                  DISPATCHER_ACK - send an ack after the message
+ *                  DISPATCHER_ASYNC - call send an ack. This is per message type - you can't send the
  *                  same message type with and without. Register two different
  *                  messages if that is what you want.
  */
-- 
1.7.7.1



More information about the Spice-devel mailing list