[Spice-devel] [PATCH 12/18] new watch api: switch ssl accept

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


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

diff --git a/server/reds.c b/server/reds.c
index 09830c4..b9d2dea 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -489,7 +489,12 @@ static int reds_ssl_free(RedsStreamContext *peer)
 static void __reds_release_link(RedLinkInfo *link)
 {
     ASSERT(link->peer);
-    core->set_file_handlers(core, link->peer->socket, NULL, NULL, NULL);
+    if (link->peer->watch) {
+        core->watch_remove(link->peer->watch);
+        link->peer->watch = NULL;
+    } else {
+        core->set_file_handlers(core, link->peer->socket, NULL, NULL, NULL);
+    }
     free(link->link_mess);
     BN_free(link->tiTicketing.bn);
     if (link->tiTicketing.rsa) {
@@ -2727,20 +2732,27 @@ static void reds_handle_new_link(RedLinkInfo *link)
     async_read_handler(0, 0, &link->asyc_read);
 }
 
-static void reds_handle_ssl_accept(void *data)
+static void reds_handle_ssl_accept(int fd, int event, void *data)
 {
     RedLinkInfo *link = (RedLinkInfo *)data;
     int return_code;
 
     if ((return_code = SSL_accept(link->peer->ssl)) != 1) {
         int ssl_error = SSL_get_error(link->peer->ssl, return_code);
-
         if (ssl_error != SSL_ERROR_WANT_READ && ssl_error != SSL_ERROR_WANT_WRITE) {
             red_printf("SSL_accept failed, error=%d", ssl_error);
             reds_release_link(link);
+        } else {
+            if (ssl_error == SSL_ERROR_WANT_READ) {
+                core->watch_update_mask(link->peer->watch, SPICE_WATCH_EVENT_READ);
+            } else {
+                core->watch_update_mask(link->peer->watch, SPICE_WATCH_EVENT_WRITE);
+            }
         }
         return;
     }
+    core->watch_remove(link->peer->watch);
+    link->peer->watch = NULL;
     reds_handle_new_link(link);
 }
 
@@ -2847,8 +2859,10 @@ static void reds_accept_ssl_connection(int fd, int event, void *data)
     ssl_error = SSL_get_error(link->peer->ssl, return_code);
     if (return_code == -1 && (ssl_error == SSL_ERROR_WANT_READ ||
                               ssl_error == SSL_ERROR_WANT_WRITE)) {
-        core->set_file_handlers(core, link->peer->socket, reds_handle_ssl_accept,
-                                reds_handle_ssl_accept, link);
+        int eventmask = ssl_error == SSL_ERROR_WANT_READ ?
+            SPICE_WATCH_EVENT_READ : SPICE_WATCH_EVENT_WRITE;
+        link->peer->watch = core->watch_add(link->peer->socket, eventmask,
+                                            reds_handle_ssl_accept, link);
         return;
     }
 
-- 
1.6.6.1



More information about the Spice-devel mailing list