[libsoup/wip/http2] fixup! Add initial HTTP2 backend
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/wip/http2] fixup! Add initial HTTP2 backend
- Date: Wed, 12 May 2021 18:30:58 +0000 (UTC)
commit d490a5ab392a4234f5180e1e0904a9c1d8645212
Author: Patrick Griffis <pgriffis igalia com>
Date: Wed May 12 13:30:38 2021 -0500
fixup! Add initial HTTP2 backend
libsoup/http2/soup-memory-input-stream.c | 43 ++++++++++++++++++++++++--------
tests/memory-stream-test.c | 26 ++++++++++++-------
2 files changed, 49 insertions(+), 20 deletions(-)
---
diff --git a/libsoup/http2/soup-memory-input-stream.c b/libsoup/http2/soup-memory-input-stream.c
index 9d659d1b..997e0af0 100644
--- a/libsoup/http2/soup-memory-input-stream.c
+++ b/libsoup/http2/soup-memory-input-stream.c
@@ -158,7 +158,7 @@ soup_memory_input_stream_read_real (GInputStream *stream,
memcpy ((guint8 *)buffer + (count - rest), chunk_data + start, size);
rest -= size;
- // Remove fully read chunk from list, note that we are always near the start of the list
+ /* Remove fully read chunk from list, note that we are always near the start of the list */
if (start + size == len) {
priv->start_offset += len;
priv->chunks = g_slist_delete_link (priv->chunks, l);
@@ -171,8 +171,8 @@ soup_memory_input_stream_read_real (GInputStream *stream,
priv->pos += count;
- // We need to block until the read is completed.
- // So emit a signal saying we need more data.
+ /* We need to block until the read is completed.
+ * So emit a signal saying we need more data. */
if (count == 0 && blocking && !priv->completed) {
GError *read_error = NULL;
g_signal_emit (memory_stream, signals[NEED_MORE_DATA], 0,
@@ -216,17 +216,22 @@ soup_memory_input_stream_read_nonblocking (GPollableInputStream *stream,
gsize read = soup_memory_input_stream_read_real (G_INPUT_STREAM (stream), FALSE, buffer, count,
NULL, &inner_error);
if (read == 0 && !priv->completed && !inner_error) {
- g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK, "Operation would block");
-
- // Try requesting more reads from the io backend
- GError *inner_error = NULL;
+ /* Try requesting more reads from the io backend */
+ GError *read_error = NULL;
g_signal_emit (memory_stream, signals[NEED_MORE_DATA], 0,
- NULL, FALSE, &inner_error);
+ NULL, FALSE, &read_error);
- // TODO: Do we care?
- g_clear_error (&inner_error);
+ if (read_error) {
+ g_propagate_error (error, read_error);
+ return -1;
+ }
- return -1;
+ /* Immediately return any data read */
+ read = soup_memory_input_stream_read_real (G_INPUT_STREAM (stream), FALSE, buffer, count,
NULL, &inner_error);
+ if (read == 0) {
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK, "Operation would
block");
+ return -1;
+ }
}
if (inner_error)
@@ -257,6 +262,21 @@ soup_memory_input_stream_skip (GInputStream *stream,
count = MIN (count, priv->len - priv->pos);
priv->pos += count;
+ /* Remove all skipped chunks */
+ gsize offset = priv->start_offset;
+ for (GSList *l = priv->chunks; l; l = l->next) {
+ GBytes *chunk = (GBytes *)l->data;
+ gsize chunk_len = g_bytes_get_size (chunk);
+
+ if (offset + chunk_len <= priv->pos) {
+ priv->chunks = g_slist_delete_link (priv->chunks, l);
+ g_bytes_unref (chunk);
+ offset += chunk_len;
+ }
+ break;
+ }
+ priv->start_offset = offset;
+
return count;
}
@@ -496,6 +516,7 @@ soup_memory_input_stream_finalize (GObject *object)
SoupMemoryInputStream *stream = SOUP_MEMORY_INPUT_STREAM (object);
SoupMemoryInputStreamPrivate *priv = soup_memory_input_stream_get_instance_private (stream);
+ g_message ("FREE WITH %u len", g_slist_length (priv->chunks));
g_slist_free_full (priv->chunks, (GDestroyNotify)g_bytes_unref);
g_clear_object (&priv->parent_stream);
diff --git a/tests/memory-stream-test.c b/tests/memory-stream-test.c
index 33d39bee..de0e4053 100644
--- a/tests/memory-stream-test.c
+++ b/tests/memory-stream-test.c
@@ -29,22 +29,30 @@ do_large_data_test (void)
GInputStream *stream = soup_memory_input_stream_new (NULL);
SoupMemoryInputStream *mem_stream = SOUP_MEMORY_INPUT_STREAM (stream);
gsize data_needed = TEST_SIZE;
- char *memory_chunk = g_new (char, CHUNK_SIZE);
- char *trash_buffer = g_new (char, CHUNK_SIZE);
+ guint8 *memory_chunk = g_new (guint8, CHUNK_SIZE);
+ guint8 *trash_buffer = g_new (guint8, CHUNK_SIZE);
- // We can add unlimited data and as long as its read the data will
- // be freed, so this should work fine even though its reading GB of data
+ /* We can add unlimited data and as long as its read the data will
+ * be freed, so this should work fine even though its reading GB of data */
while (data_needed > 0) {
- // Copy chunk
+ /* Copy chunk */
soup_memory_input_stream_add_data (mem_stream, memory_chunk, CHUNK_SIZE);
- // This should free the copy
+ /* This should free the copy */
gssize read = g_input_stream_read (stream, trash_buffer, CHUNK_SIZE, NULL, NULL);
g_assert_cmpint (read, ==, CHUNK_SIZE);
+ data_needed -= CHUNK_SIZE;
+ }
+
+ data_needed = TEST_SIZE;
+ while (data_needed > 0) {
+ soup_memory_input_stream_add_data (mem_stream, memory_chunk, CHUNK_SIZE);
+ /* Skipping also frees the copy */
+ gssize skipped = g_input_stream_skip (stream, CHUNK_SIZE, NULL, NULL);
+ g_assert_cmpint (skipped, ==, CHUNK_SIZE);
data_needed -= CHUNK_SIZE;
-
}
g_free (trash_buffer);
@@ -62,9 +70,9 @@ do_multiple_chunk_test (void)
};
for (guint i = 0; i < G_N_ELEMENTS (chunks); ++i)
- soup_memory_input_stream_add_data (mem_stream, chunks[i], 4);
+ soup_memory_input_stream_add_data (mem_stream, (guint8*)chunks[i], 4);
- // Do partial reads of chunks to ensure it always comes out as expected
+ /* Do partial reads of chunks to ensure it always comes out as expected */
for (guint i = 0; i < G_N_ELEMENTS (chunks); ++i) {
char buffer[5] = { 0 };
gssize read = g_input_stream_read (stream, buffer, 2, NULL, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]