diff options
Diffstat (limited to 'libsoup/soup-server.c')
-rw-r--r-- | libsoup/soup-server.c | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/libsoup/soup-server.c b/libsoup/soup-server.c index 13d6e5e5..dee1a791 100644 --- a/libsoup/soup-server.c +++ b/libsoup/soup-server.c @@ -99,6 +99,7 @@ struct SoupClientContext { GSocketAddress *local_addr; int ref_count; + gboolean stole_connection; }; typedef struct { @@ -1136,8 +1137,12 @@ request_finished (SoupMessage *msg, gboolean io_complete, gpointer user_data) 0, msg, client); soup_client_context_cleanup (client); - if (io_complete && soup_socket_is_connected (sock) && - soup_message_is_keepalive (msg)) { + + if (client->stole_connection) { + soup_client_context_unref (client); + } else if (io_complete && + soup_socket_is_connected (sock) && + soup_message_is_keepalive (msg)) { /* Start a new request */ start_request (server, client); } else { @@ -2176,6 +2181,48 @@ soup_client_context_get_auth_user (SoupClientContext *client) } /** + * soup_client_context_steal_connection: + * @client: a #SoupClientContext + * + * "Steals" the HTTP connection associated with @client from its + * #SoupServer. Note that this happens immediately, regardless of the + * current state of the connection; if the response to the current + * #SoupMessage has not yet finished being sent, then it will be + * discarded; you can steal the connection from a #SoupMessage or + * #SoupServer signal handler if you need to wait for part or all of + * the response to be sent. + * + * Return value: (transfer full): the #GIOStream connected to @client. No + * guarantees are made about what kind of #GIOStream this is. + * + * Since: 2.48 + **/ +GIOStream * +soup_client_context_steal_connection (SoupClientContext *client) +{ + GIOStream *stream; + + g_return_val_if_fail (client != NULL, NULL); + g_return_val_if_fail (client->stole_connection == FALSE, NULL); + + soup_client_context_ref (client); + + client->stole_connection = TRUE; + g_object_set (G_OBJECT (client->sock), + SOUP_SOCKET_CLOSE_ON_DISPOSE, FALSE, + NULL); + stream = g_object_ref (soup_socket_get_iostream (client->sock)); + + if (soup_message_io_in_progress (client->msg)) + soup_message_io_finished (client->msg); + socket_disconnected (client->sock, client); + + soup_client_context_unref (client); + + return stream; +} + +/** * SoupServerCallback: * @server: the #SoupServer * @msg: the message being processed @@ -2420,4 +2467,3 @@ soup_server_unpause_message (SoupServer *server, soup_message_io_unpause (msg); } - |