[Spice-devel] [PATCH 3/7] Remove RedLinkInfo::async_read

Christophe Fergeau cfergeau at redhat.com
Mon Mar 17 06:20:37 PDT 2014


9feed69 moved the async reader code to RedsStream so that it can be used
for the SASL authentication code. In particular, it introduced a
RedsStream::async_read member which is used by the SASL authentication code
for its async operations.

However, what was not done is to remove the now redundant
RedLinkInfo::async_read field. This causes failures when using SASL
authentication as the async read error callback is getting set
on the RedLinkInfo::async_read structure, but then the SASL code is trying
to use the RedeStream::async_read structure for its async IOs, which do not
have the needed error callback set.

This commit makes use of the newly introduced reds_stream_async_read()
helper in order to make use of RedsStream::async_read.
---
 server/reds.c | 44 +++++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 25 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index 2ef4aad..c1c0efc 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -123,7 +123,6 @@ static RedsState *reds = NULL;
 
 typedef struct RedLinkInfo {
     RedsStream *stream;
-    AsyncRead async_read;
     SpiceLinkHeader link_header;
     SpiceLinkMess *link_mess;
     int mess_pos;
@@ -1873,12 +1872,9 @@ end:
 
 static void reds_get_spice_ticket(RedLinkInfo *link)
 {
-    AsyncRead *obj = &link->async_read;
-
-    obj->now = (uint8_t *)&link->tiTicketing.encrypted_ticket.encrypted_data;
-    obj->end = obj->now + link->tiTicketing.rsa_size;
-    obj->done = reds_handle_ticket;
-    async_read_handler(0, 0, &link->async_read);
+    reds_stream_async_read(link->stream,
+                           (uint8_t *)&link->tiTicketing.encrypted_ticket.encrypted_data,
+                           link->tiTicketing.rsa_size, reds_handle_ticket, link);
 }
 
 #if HAVE_SASL
@@ -2041,7 +2037,6 @@ static void reds_handle_read_link_done(void *opaque)
 {
     RedLinkInfo *link = (RedLinkInfo *)opaque;
     SpiceLinkMess *link_mess = link->link_mess;
-    AsyncRead *obj = &link->async_read;
     uint32_t num_caps = link_mess->num_common_caps + link_mess->num_channel_caps;
     uint32_t *caps = (uint32_t *)((uint8_t *)link_mess + link_mess->caps_offset);
     int auth_selection;
@@ -2083,10 +2078,11 @@ static void reds_handle_read_link_done(void *opaque)
         spice_warning("Peer doesn't support AUTH selection");
         reds_get_spice_ticket(link);
     } else {
-        obj->now = (uint8_t *)&link->auth_mechanism;
-        obj->end = obj->now + sizeof(SpiceLinkAuthMechanism);
-        obj->done = reds_handle_auth_mechanism;
-        async_read_handler(0, 0, &link->async_read);
+        reds_stream_async_read(link->stream,
+                               (uint8_t *)&link->auth_mechanism,
+                               sizeof(SpiceLinkAuthMechanism),
+                               reds_handle_auth_mechanism,
+                               link);
     }
 }
 
@@ -2108,7 +2104,6 @@ static void reds_handle_read_header_done(void *opaque)
 {
     RedLinkInfo *link = (RedLinkInfo *)opaque;
     SpiceLinkHeader *header = &link->link_header;
-    AsyncRead *obj = &link->async_read;
 
     if (header->magic != SPICE_MAGIC) {
         reds_send_link_error(link, SPICE_LINK_ERR_INVALID_MAGIC);
@@ -2137,22 +2132,21 @@ static void reds_handle_read_header_done(void *opaque)
 
     link->link_mess = spice_malloc(header->size);
 
-    obj->now = (uint8_t *)link->link_mess;
-    obj->end = obj->now + header->size;
-    obj->done = reds_handle_read_link_done;
-    async_read_handler(0, 0, &link->async_read);
+    reds_stream_async_read(link->stream,
+                           (uint8_t *)link->link_mess,
+                           header->size,
+                           reds_handle_read_link_done,
+                           link);
 }
 
 static void reds_handle_new_link(RedLinkInfo *link)
 {
-    AsyncRead *obj = &link->async_read;
-    obj->opaque = link;
-    obj->stream = link->stream;
-    obj->now = (uint8_t *)&link->link_header;
-    obj->end = (uint8_t *)((SpiceLinkHeader *)&link->link_header + 1);
-    obj->done = reds_handle_read_header_done;
-    obj->error = reds_handle_link_error;
-    async_read_handler(0, 0, &link->async_read);
+    reds_stream_set_async_error_handler(link->stream, reds_handle_link_error);
+    reds_stream_async_read(link->stream,
+                           (uint8_t *)&link->link_header,
+                           sizeof(SpiceLinkHeader),
+                           reds_handle_read_header_done,
+                           link);
 }
 
 static void reds_handle_ssl_accept(int fd, int event, void *data)
-- 
1.8.5.3



More information about the Spice-devel mailing list