diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2022-08-31 14:35:40 +0200 |
---|---|---|
committer | Carlos Garcia Campos <cgarcia@igalia.com> | 2022-09-02 12:19:00 +0200 |
commit | a99b7ac9801af44359c372083ce0ac519cd71d80 (patch) | |
tree | 34e8a6379747b57a5c1921725367a7bcef5f5302 | |
parent | 59027ddc49b31b60607803f992b83a13764539f2 (diff) | |
download | libsoup-a99b7ac9801af44359c372083ce0ac519cd71d80.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.c | 6 |
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 7e6fc64a..7148e602 100644 --- a/libsoup/http2/soup-client-message-io-http2.c +++ b/libsoup/http2/soup-client-message-io-http2.c @@ -470,6 +470,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 ()); } @@ -488,6 +490,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; @@ -1898,6 +1903,7 @@ soup_client_message_io_http2_new (SoupConnection *conn) 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 ()); |