summaryrefslogtreecommitdiff
path: root/libsoup/soup-message-io.c
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2015-03-02 18:39:27 -0500
committerDan Winship <danw@gnome.org>2015-03-02 21:28:42 -0500
commitaa42dd5588eaf617264cc0c9a0984b8c79f22603 (patch)
treeaee1d870c364745a5e0267cde7eba7f792f717f1 /libsoup/soup-message-io.c
parent36d472e866abfdeedb31effc14dbf896b8060731 (diff)
downloadlibsoup-aa42dd5588eaf617264cc0c9a0984b8c79f22603.tar.gz
soup-message-io: fix up async body close semantics
add13ea0 fixed soup-message-io to do an async close of io->body_ostream, so that in cases where it was necessary to write out the final "0" chunk, and the stream was not immediately writable, it wouldn't block. However, it was emitting :wrote-body and potentially :finished before the close finished in this case, which made it difficult to ensure that the last request on a session was cleaned up correctly in the test programs. Fix this by adding in a new IO_STATE_BODY_FLUSH to do this step before proceeding to IO_STATE_FINISHING. But also, to simplify things, just do the sync close if we're not doing chunked encoding, since it's guaranteed to not block in that case. (Also revert the changes that had been made to continue-test for that commit, since they are no longer needed.)
Diffstat (limited to 'libsoup/soup-message-io.c')
-rw-r--r--libsoup/soup-message-io.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index 021a5ec1..bec3e345 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -36,6 +36,7 @@ typedef enum {
SOUP_MESSAGE_IO_STATE_BODY_START,
SOUP_MESSAGE_IO_STATE_BODY,
SOUP_MESSAGE_IO_STATE_BODY_DATA,
+ SOUP_MESSAGE_IO_STATE_BODY_FLUSH,
SOUP_MESSAGE_IO_STATE_BODY_DONE,
SOUP_MESSAGE_IO_STATE_FINISHING,
SOUP_MESSAGE_IO_STATE_DONE
@@ -486,7 +487,7 @@ io_write (SoupMessage *msg, gboolean blocking,
if (!io->write_length &&
io->write_encoding != SOUP_ENCODING_EOF &&
io->write_encoding != SOUP_ENCODING_CHUNKED) {
- io->write_state = SOUP_MESSAGE_IO_STATE_BODY_DONE;
+ io->write_state = SOUP_MESSAGE_IO_STATE_BODY_FLUSH;
break;
}
@@ -498,7 +499,7 @@ io_write (SoupMessage *msg, gboolean blocking,
return FALSE;
}
if (!io->write_chunk->length) {
- io->write_state = SOUP_MESSAGE_IO_STATE_BODY_DONE;
+ io->write_state = SOUP_MESSAGE_IO_STATE_BODY_FLUSH;
break;
}
}
@@ -528,7 +529,7 @@ io_write (SoupMessage *msg, gboolean blocking,
case SOUP_MESSAGE_IO_STATE_BODY_DATA:
io->written = 0;
if (io->write_chunk->length == 0) {
- io->write_state = SOUP_MESSAGE_IO_STATE_BODY_DONE;
+ io->write_state = SOUP_MESSAGE_IO_STATE_BODY_FLUSH;
break;
}
@@ -544,9 +545,9 @@ io_write (SoupMessage *msg, gboolean blocking,
break;
- case SOUP_MESSAGE_IO_STATE_BODY_DONE:
+ case SOUP_MESSAGE_IO_STATE_BODY_FLUSH:
if (io->body_ostream) {
- if (blocking) {
+ if (blocking || io->write_encoding != SOUP_ENCODING_CHUNKED) {
if (!g_output_stream_close (io->body_ostream, cancellable, error))
return FALSE;
g_clear_object (&io->body_ostream);
@@ -562,11 +563,13 @@ io_write (SoupMessage *msg, gboolean blocking,
}
}
+ io->write_state = SOUP_MESSAGE_IO_STATE_BODY_DONE;
+ break;
+
+
+ case SOUP_MESSAGE_IO_STATE_BODY_DONE:
io->write_state = SOUP_MESSAGE_IO_STATE_FINISHING;
soup_message_wrote_body (msg);
-
- if (io->async_close_wait)
- return TRUE;
break;