[libsoup/wip/http2] fixup! Add initial HTTP2 backend



commit c218bf642f89c78d5be3afee60c53849e20a1457
Author: Patrick Griffis <pgriffis igalia com>
Date:   Mon May 10 12:42:25 2021 -0500

    fixup! Add initial HTTP2 backend

 libsoup/http2/soup-client-message-io-http2.c | 71 +++++-----------------------
 1 file changed, 13 insertions(+), 58 deletions(-)
---
diff --git a/libsoup/http2/soup-client-message-io-http2.c b/libsoup/http2/soup-client-message-io-http2.c
index 875d2c40..7eb524a8 100644
--- a/libsoup/http2/soup-client-message-io-http2.c
+++ b/libsoup/http2/soup-client-message-io-http2.c
@@ -68,7 +68,7 @@ typedef struct {
 
         GMainContext *async_context;
 
-        GPtrArray *messages;
+        GHashTable *messages;
         GHashTable *message_errors;
 
         nghttp2_session *session;
@@ -115,24 +115,6 @@ typedef struct {
 static void soup_message_io_http2_finished (SoupClientMessageIO *, SoupMessage *);
 static gboolean io_read_or_write (SoupMessageIOHTTP2 *, gboolean, GCancellable *, GError **);
 
-#if 0
-static SoupHTTP2MessageData *
-get_message_by_stream_id (SoupMessageIOHTTP2 *io, guint32 stream_id)
-{
-        const guint len = io->messages->len;
-
-        for (uint i = 0; i < len; ++i) {
-                SoupHTTP2MessageData *data = io->messages->pdata[i];
-                if (data->stream_id == stream_id)
-                        return data;
-        }
-
-        if (stream_id != 0)
-                g_warning ("Recieved frame for unknown stream id %u!", stream_id);
-        return NULL;
-}
-#endif
-
 static const char *
 frame_type_to_string (nghttp2_frame_type type)
 {
@@ -301,10 +283,11 @@ on_begin_frame_callback (nghttp2_session *session, const nghttp2_frame_hd *hd, v
 static void
 handle_goaway (SoupMessageIOHTTP2 *io, guint32 error_code, guint32 last_stream_id)
 {
-        const guint len = io->messages->len;
+        GHashTableIter iter;
+        SoupHTTP2MessageData *data;
 
-        for (uint i = 0; i < len; ++i) {
-                SoupHTTP2MessageData *data = io->messages->pdata[i];
+        g_hash_table_iter_init (&iter, io->messages);
+        while (g_hash_table_iter_next (&iter, NULL, (gpointer*)&data)) {
                 /* If there is no error it is a graceful shutdown and
                  * existing messages can be handled otherwise it is a fatal error */
                 if ((error_code == 0 && data->stream_id > last_stream_id) ||
@@ -672,14 +655,6 @@ on_data_source_read_callback (nghttp2_session *session, int32_t stream_id, uint8
 
 /* HTTP2 IO functions */
 
-static gboolean
-data_compare (gconstpointer a, gconstpointer b)
-{
-        SoupHTTP2MessageData *data1 = (SoupHTTP2MessageData *)a, *data2 = (SoupHTTP2MessageData *)b;
-
-        return data1->msg == data2->msg;
-}
-
 static SoupHTTP2MessageData *
 add_message_to_io_data (SoupMessageIOHTTP2 *io,
                         SoupMessageQueueItem *item,
@@ -697,9 +672,8 @@ add_message_to_io_data (SoupMessageIOHTTP2 *io,
         data->stream_id = 0; // Will be overwritten
         data->io = io;
 
-        if (g_ptr_array_find_with_equal_func (io->messages, data, data_compare, NULL))
+        if (!g_hash_table_insert (io->messages, item->msg, data))
                 g_warn_if_reached ();
-        g_ptr_array_add (io->messages, data);
 
         return data;
 }
@@ -826,16 +800,11 @@ soup_message_io_http2_send_item (SoupClientMessageIO *iface,
 static SoupHTTP2MessageData *
 get_data_for_message (SoupMessageIOHTTP2 *io, SoupMessage *msg)
 {
-        const guint len = io->messages->len;
+        SoupHTTP2MessageData *data = g_hash_table_lookup (io->messages, msg);
 
-        for (uint i = 0; i < len; ++i) {
-                SoupHTTP2MessageData *data = io->messages->pdata[i];
-                if (data->msg == msg)
-                        return data;
-        }
+        g_warn_if_fail (data != NULL);
 
-        g_warn_if_reached ();
-        return NULL;
+        return data;
 }
 
 static void
@@ -846,7 +815,6 @@ soup_message_io_http2_finished (SoupClientMessageIO *iface,
         SoupHTTP2MessageData *data;
        SoupMessageIOCompletionFn completion_cb;
        gpointer completion_data;
-       SoupMessageIOCompletion completion;
 
         data = get_data_for_message (io, msg);
 
@@ -861,19 +829,16 @@ soup_message_io_http2_finished (SoupClientMessageIO *iface,
        completion_cb = data->completion_cb;
        completion_data = data->completion_data;
 
-       // TODO
-       completion = SOUP_MESSAGE_IO_COMPLETE;
-
        g_object_ref (msg);
 
         nghttp2_session_set_stream_user_data (io->session, data->stream_id, NULL);
-        if (!g_ptr_array_remove_fast (io->messages, data))
+        if (!g_hash_table_remove (io->messages, msg))
                 g_warn_if_reached ();
 
         soup_connection_message_io_finished (soup_message_get_connection (msg), msg);
 
        if (completion_cb)
-               completion_cb (G_OBJECT (msg), completion, completion_data);
+               completion_cb (G_OBJECT (msg), SOUP_MESSAGE_IO_COMPLETE, completion_data);
 
        g_object_unref (msg);
 }
@@ -1002,16 +967,6 @@ soup_message_io_http2_skip_body (SoupClientMessageIO *iface,
         soup_message_got_body (data->msg);
 }
 
-#if 0
-static int
-idle_finish (gpointer user_data)
-{
-        SoupMessage *msg = user_data;
-        soup_message_io_http2_finished (msg); // TODO: Smarter
-        return G_SOURCE_REMOVE;
-}
-#endif
-
 static void
 client_stream_eof (SoupClientInputStream *stream, gpointer user_data)
 {
@@ -1307,7 +1262,7 @@ soup_message_io_http2_destroy (SoupClientMessageIO *iface)
         g_clear_object (&io->stream);
         g_clear_pointer (&io->async_context, g_main_context_unref);
         g_clear_pointer (&io->session, nghttp2_session_del);
-        g_clear_pointer (&io->messages, g_ptr_array_unref);
+        g_clear_pointer (&io->messages, g_hash_table_unref);
         g_clear_pointer (&io->message_errors, g_hash_table_unref);
 
         g_free (io);
@@ -1351,7 +1306,7 @@ soup_client_message_io_http2_init (SoupMessageIOHTTP2 *io)
         nghttp2_session_client_new (&io->session, callbacks, io);
         nghttp2_session_callbacks_del (callbacks);
 
-        io->messages = g_ptr_array_new_full (1, (GDestroyNotify)soup_http2_message_data_free);
+        io->messages = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, 
(GDestroyNotify)soup_http2_message_data_free);
         /* Errors are stored separate as they have a longer lifetime than MessageData */
         io->message_errors = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, 
(GDestroyNotify)g_error_free);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]