Re: Quick question regarding recent SOUP_ENCODING_EOF code



I am using the recently added SOUP_ENCODING_EOF. I am finding that
calling soup_message_body_complete () is not enough to cause libsoup to
stop sending the "wrote_chunk" signal and instead send the "finished"
signal. I have to actually call soup_message_finished ().

Everything works as long as I call soup_message_finished (), but this is
not what is done in streaming-test.c. Is this expected?

You definitely shouldn't call soup_message_finished() yourself.

My guess would be that the message is getting paused, probably because
you're letting a wrote_chunk signal go by without adding another chunk.
If the I/O layer runs out of chunks, it will automatically call
soup_session_pause_message(), and you have to then unpause it yourself
after adding another chunk. The sample code always adds another chunk
before the I/O layer can run out, so it doesn't ever have to call
soup_session_unpause_message(), but if your code is written slightly
differently, it might have to.

Everything works when I use chunked encoding. Only when I use the new EOF encoding do I have this problem. The only difference between the two cases is:

if (soup_message_get_http_version (message) == SOUP_HTTP_1_0) {
soup_message_headers_set_encoding (message->response_headers, SOUP_ENCODING_EOF);
} else {
soup_message_headers_set_encoding (message->response_headers, SOUP_ENCODING_CHUNKED);
}

I've tested this with curl (HTTP 1.0 mode) and one other client.

On the other hand, everything works fine when curl uses HTTP 1.1 and my server uses chunked encoding instead of EOF encoding.

I do use soup_server_unpause_message () in my write_next_chunk () callback. The following works fine when using chunked encoding (writes "wrote 0 bytes, sending message complete" once and stops getting called) but not when using EOF encoding (called over and over, printing "wrote 0 bytes, sending message complete" repeatedly)

static void
write_next_chunk (SoupMessage *message, ChunkData *cd)
{
        gssize read_size;
        GError *error = NULL;
        gchar *chunk = g_malloc (DMAP_SHARE_CHUNK_SIZE);

        read_size = g_input_stream_read (cd->stream,
                                         chunk,
                                         DMAP_SHARE_CHUNK_SIZE,
                                         NULL,
                                         &error);
        if (read_size > 0) {
                soup_message_body_append (message->response_body,
                                          SOUP_MEMORY_TAKE,
                                          chunk,
                                          read_size);
                g_warning ("wrote %d bytes", read_size);
        } else {
                if (error != NULL) {
g_warning ("error reading from input stream: %s",
                                   error->message);
                        g_error_free (error);
                }
                g_free (chunk);
                g_warning ("wrote 0 bytes, sending message complete");
                soup_message_body_complete (message->response_body);
/* FIXME: why is this required for SOUP_ENCODING_EOF? */
                /* soup_message_finished (message); */
        }
        soup_server_unpause_message (cd->server, message);
}


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