[libsoup/wip/server-steal: 1/3] soup-message-io: slight tweak to callback/error handling



commit 25daaf5f10932d9f0bbf8ef2d812ef95a4428ab0
Author: Dan Winship <danw gnome org>
Date:   Sun Jan 19 09:44:35 2014 -0500

    soup-message-io: slight tweak to callback/error handling
    
    Let the callback know whether I/O completed on the message, and move
    the server-side "disconnect on I/O error" code from soup-message-io to
    soup-server.

 libsoup/soup-message-io.c      |   11 +++++------
 libsoup/soup-message-private.h |    1 +
 libsoup/soup-server.c          |    8 +++++---
 libsoup/soup-session.c         |    4 ++--
 4 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index be5cb2d..600cd85 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -143,11 +143,6 @@ soup_message_io_stop (SoupMessage *msg)
                g_source_unref (io->unpause_source);
                io->unpause_source = NULL;
        }
-
-       if (io->mode == SOUP_MESSAGE_IO_SERVER) {
-               if (io->write_state < SOUP_MESSAGE_IO_STATE_FINISHING)
-                       g_io_stream_close (io->iostream, NULL, NULL);
-       }
 }
 
 void
@@ -157,6 +152,7 @@ soup_message_io_finished (SoupMessage *msg)
        SoupMessageIOData *io = priv->io_data;
        SoupMessageCompletionFn completion_cb;
        gpointer completion_data;
+       gboolean complete;
 
        if (!io)
                return;
@@ -164,10 +160,13 @@ soup_message_io_finished (SoupMessage *msg)
        completion_cb = io->completion_cb;
        completion_data = io->completion_data;
 
+       complete = (io->read_state >= SOUP_MESSAGE_IO_STATE_FINISHING &&
+                   io->write_state >= SOUP_MESSAGE_IO_STATE_FINISHING);
+
        g_object_ref (msg);
        soup_message_io_cleanup (msg);
        if (completion_cb)
-               completion_cb (msg, completion_data);
+               completion_cb (msg, complete, completion_data);
        g_object_unref (msg);
 }
 
diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h
index 35cc988..0796ba0 100644
--- a/libsoup/soup-message-private.h
+++ b/libsoup/soup-message-private.h
@@ -60,6 +60,7 @@ typedef guint    (*SoupMessageParseHeadersFn)(SoupMessage      *msg,
                                              gpointer          user_data,
                                              GError          **error);
 typedef void     (*SoupMessageCompletionFn)  (SoupMessage      *msg,
+                                             gboolean          io_complete,
                                              gpointer          user_data);
 
 
diff --git a/libsoup/soup-server.c b/libsoup/soup-server.c
index 07d801d..18aefba 100644
--- a/libsoup/soup-server.c
+++ b/libsoup/soup-server.c
@@ -870,20 +870,22 @@ soup_client_context_unref (SoupClientContext *client)
 }
 
 static void
-request_finished (SoupMessage *msg, gpointer user_data)
+request_finished (SoupMessage *msg, gboolean io_complete, gpointer user_data)
 {
        SoupClientContext *client = user_data;
        SoupServer *server = client->server;
        SoupSocket *sock = client->sock;
 
        soup_message_finished (msg);
+
        g_signal_emit (server,
-                      msg->status_code == SOUP_STATUS_IO_ERROR ?
+                      (!io_complete || msg->status_code == SOUP_STATUS_IO_ERROR) ?
                       signals[REQUEST_ABORTED] : signals[REQUEST_FINISHED],
                       0, msg, client);
 
        soup_client_context_cleanup (client);
-       if (soup_socket_is_connected (sock) && soup_message_is_keepalive (msg)) {
+       if (io_complete && soup_socket_is_connected (sock) &&
+           soup_message_is_keepalive (msg)) {
                /* Start a new request */
                start_request (server, client);
        } else {
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index b3081f1..7181a4b 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -1497,7 +1497,7 @@ soup_session_set_item_status (SoupSession          *session,
 
 
 static void
-message_completed (SoupMessage *msg, gpointer user_data)
+message_completed (SoupMessage *msg, gboolean io_complete, gpointer user_data)
 {
        SoupMessageQueueItem *item = user_data;
 
@@ -1603,7 +1603,7 @@ tunnel_handshake_complete (GObject      *object,
 }
 
 static void
-tunnel_message_completed (SoupMessage *msg, gpointer user_data)
+tunnel_message_completed (SoupMessage *msg, gboolean io_complete, gpointer user_data)
 {
        SoupMessageQueueItem *tunnel_item = user_data;
        SoupMessageQueueItem *item = tunnel_item->related;


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