summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2022-08-31 14:35:40 +0200
committerCarlos Garcia Campos <cgarcia@igalia.com>2022-08-31 14:35:40 +0200
commit20643a063ba7e55c62d7324cd7448e6bb3f18ad8 (patch)
tree2c424ea32d83c5f8f0c63ad94d5af98e0a697bc5
parenta31e1744191b88d0da4dcdc4d95cc78f37c2609a (diff)
downloadlibsoup-20643a063ba7e55c62d7324cd7448e6bb3f18ad8.tar.gz
http2: always try to write before every read
It can happen that an error handled by nghttp2 generates a reset stream frame that needs to be sent, so we need to try to write even if we haven't made any explict call that requires writing. Also give more priority to write source than read source. Fixes #298
-rw-r--r--libsoup/http2/soup-client-message-io-http2.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/libsoup/http2/soup-client-message-io-http2.c b/libsoup/http2/soup-client-message-io-http2.c
index 6f7dd747..86d3f3ae 100644
--- a/libsoup/http2/soup-client-message-io-http2.c
+++ b/libsoup/http2/soup-client-message-io-http2.c
@@ -373,6 +373,8 @@ io_try_write (SoupClientMessageIOHTTP2 *io,
g_clear_error (&error);
io->write_source = g_pollable_output_stream_create_source (G_POLLABLE_OUTPUT_STREAM (io->ostream), NULL);
g_source_set_name (io->write_source, "Soup HTTP/2 write source");
+ /* Give write more priority than read */
+ g_source_set_priority (io->write_source, G_PRIORITY_DEFAULT - 1);
g_source_set_callback (io->write_source, (GSourceFunc)io_write_ready, io, NULL);
g_source_attach (io->write_source, g_main_context_get_thread_default ());
}
@@ -391,6 +393,9 @@ io_read (SoupClientMessageIOHTTP2 *io,
gssize read;
int ret;
+ /* Always try to write before read, in case there's a pending reset stream after an error. */
+ io_try_write (io, blocking);
+
if ((read = g_pollable_stream_read (io->istream, buffer, sizeof (buffer),
blocking, cancellable, error)) < 0)
return FALSE;
@@ -1723,6 +1728,7 @@ soup_client_message_io_http2_set_owner (SoupClientMessageIOHTTP2 *io,
io->read_source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (io->istream), NULL);
g_source_set_name (io->read_source, "Soup HTTP/2 read source");
+ g_source_set_priority (io->read_source, G_PRIORITY_DEFAULT);
g_source_set_callback (io->read_source, (GSourceFunc)io_read_ready, io, NULL);
g_source_attach (io->read_source, g_main_context_get_thread_default ());
}