[Spice-devel] [PATCH 11/18] new watch api: switch main channel

Gerd Hoffmann kraxel at redhat.com
Mon Mar 29 08:08:47 PDT 2010


---
 server/reds.c |   40 +++++++++++++++++++++-------------------
 1 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index 5a84a0d..09830c4 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -362,7 +362,6 @@ typedef struct PingItem {
 
 static uint8_t zero_page[ZERO_BUF_SIZE] = {0};
 
-static void reds_main_write(void *data);
 static void reds_push();
 
 static ChannelSecurityOptions *channels_security = NULL;
@@ -748,7 +747,8 @@ static void reds_disconnect()
     }
 
     reds_shatdown_channels();
-    core->set_file_handlers(core, reds->peer->socket, NULL, NULL, NULL);
+    core->watch_remove(reds->peer->watch);
+    reds->peer->watch = NULL;
     reds->peer->cb_free(reds->peer);
     reds->peer = NULL;
     reds->in_handler.shut = TRUE;
@@ -1844,13 +1844,6 @@ static void reds_main_handle_message(void *opaque, SpiceDataHeader *message)
     }
 }
 
-static void reds_main_read(void *data)
-{
-    if (handle_incoming(reds->peer, &reds->in_handler)) {
-        reds_disconnect();
-    }
-}
-
 static int reds_send_data()
 {
     RedsOutgoingData *outgoing = &reds->outgoing;
@@ -1865,8 +1858,8 @@ static int reds_send_data()
         if ((n = reds->peer->cb_writev(reds->peer->ctx, outgoing->vec, outgoing->vec_size)) == -1) {
             switch (errno) {
             case EAGAIN:
-                core->set_file_handlers(core, reds->peer->socket, reds_main_read, reds_main_write,
-                                        NULL);
+                core->watch_update_mask(reds->peer->watch,
+                                        SPICE_WATCH_EVENT_READ | SPICE_WATCH_EVENT_WRITE);
                 return FALSE;
             case EINTR:
                 break;
@@ -1906,14 +1899,21 @@ static void reds_push()
     }
 }
 
-static void reds_main_write(void *data)
+static void reds_main_event(int fd, int event, void *data)
 {
-    RedsOutgoingData *outgoing = &reds->outgoing;
-
-    if (reds_send_data()) {
-        reds_push();
-        if (!outgoing->item) {
-            core->set_file_handlers(core, reds->peer->socket, reds_main_read, NULL, NULL);
+    if (event & SPICE_WATCH_EVENT_READ) {
+        if (handle_incoming(reds->peer, &reds->in_handler)) {
+            reds_disconnect();
+        }
+    }
+    if (event & SPICE_WATCH_EVENT_WRITE) {
+        RedsOutgoingData *outgoing = &reds->outgoing;
+        if (reds_send_data()) {
+            reds_push();
+            if (!outgoing->item) {
+                core->watch_update_mask(reds->peer->watch,
+                                        SPICE_WATCH_EVENT_READ);
+            }
         }
     }
 }
@@ -2072,7 +2072,9 @@ static void reds_handle_main_link(RedLinkInfo *link)
         }
         reds->agent_state.plug_generation++;
     }
-    core->set_file_handlers(core, reds->peer->socket, reds_main_read, NULL, NULL);
+    reds->peer->watch = core->watch_add(reds->peer->socket,
+                                        SPICE_WATCH_EVENT_READ,
+                                        reds_main_event, NULL);
 
     if (!reds->mig_target) {
         SimpleOutItem *item;
-- 
1.6.6.1



More information about the Spice-devel mailing list