[libsoup/carlosgc/server-http2: 10/13] server: deprecate soup_server_message_pause/unpause methods




commit 928716f5063db0e971a6f96c6754e82144b95185
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Wed Jul 27 10:26:04 2022 +0200

    server: deprecate soup_server_message_pause/unpause methods
    
    They don't use the server at all, they just call
    soup_server_message_pause/unpause, so we can make them public instead.

 examples/simple-proxy.c                      | 18 +++++++++---------
 libsoup/server/soup-server-message-private.h |  2 --
 libsoup/server/soup-server-message.c         | 26 ++++++++++++++++++++++++++
 libsoup/server/soup-server-message.h         |  6 ++++++
 libsoup/server/soup-server.c                 | 16 ++++++++--------
 libsoup/server/soup-server.h                 |  4 ++--
 tests/context-test.c                         |  6 ++----
 tests/misc-test.c                            |  7 ++-----
 tests/server-test.c                          | 12 +++++-------
 tests/timeout-test.c                         |  7 ++-----
 10 files changed, 62 insertions(+), 42 deletions(-)
---
diff --git a/examples/simple-proxy.c b/examples/simple-proxy.c
index a78147ef..f196d68f 100644
--- a/examples/simple-proxy.c
+++ b/examples/simple-proxy.c
@@ -190,7 +190,7 @@ tunnel_connected_cb (GObject      *object,
                                                  SOUP_MEMORY_COPY,
                                                  error->message, strlen (error->message));
                g_error_free (error);
-               soup_server_unpause_message (tunnel->self, tunnel->msg);
+               soup_server_message_unpause (tunnel->msg);
                tunnel_close (tunnel);
                return;
        }
@@ -199,7 +199,7 @@ tunnel_connected_cb (GObject      *object,
        tunnel->server.ostream = g_io_stream_get_output_stream (tunnel->server.iostream);
 
        soup_server_message_set_status (tunnel->msg, SOUP_STATUS_OK, NULL);
-       soup_server_unpause_message (tunnel->self, tunnel->msg);
+       soup_server_message_unpause (tunnel->msg);
        g_signal_connect (tunnel->msg, "finished",
                          G_CALLBACK (start_tunnel), tunnel);
 }
@@ -211,7 +211,7 @@ try_tunnel (SoupServer *server, SoupServerMessage *msg)
        GUri *dest_uri;
        GSocketClient *sclient;
 
-       soup_server_pause_message (server, msg);
+       soup_server_message_pause (msg);
 
        tunnel = g_new0 (Tunnel, 1);
        tunnel->self = g_object_ref (server);
@@ -241,7 +241,7 @@ send_headers (SoupMessage *from, SoupServerMessage *to)
        soup_message_headers_foreach (soup_message_get_response_headers (from), copy_header,
                                      soup_server_message_get_response_headers (to));
        soup_message_headers_remove (soup_server_message_get_response_headers (to), "Content-Length");
-       soup_server_unpause_message (server, to);
+       soup_server_message_unpause (to);
 }
 
 static void
@@ -262,7 +262,7 @@ stream_read (GObject *source, GAsyncResult *result, gpointer user_data)
         if (error) {
                 g_print ("[%p]  failed to read body: %s\n\n", server_msg, error->message);
                 soup_server_message_set_status (server_msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, NULL);
-                soup_server_unpause_message (server, server_msg);
+                soup_server_message_unpause (server_msg);
                 g_error_free (error);
                 return;
         }
@@ -274,7 +274,7 @@ stream_read (GObject *source, GAsyncResult *result, gpointer user_data)
                 g_signal_handlers_disconnect_by_func (server_msg, client_msg_failed, client_cancellable);
 
                 soup_message_body_complete (soup_server_message_get_response_body (server_msg));
-                soup_server_unpause_message (server, server_msg);
+                soup_server_message_unpause (server_msg);
                 g_object_unref (server_msg);
                 return;
         }
@@ -284,7 +284,7 @@ stream_read (GObject *source, GAsyncResult *result, gpointer user_data)
 
         SoupMessageBody *body = soup_server_message_get_response_body (server_msg);
         soup_message_body_append_bytes (body, bytes);
-        soup_server_unpause_message (server, server_msg);
+        soup_server_message_unpause (server_msg);
 
         g_bytes_unref (bytes);
 
@@ -303,7 +303,7 @@ client_message_sent (GObject *source, GAsyncResult *result, gpointer user_data)
         if (error) {
                 g_print ("[%p]  failed to read body: %s\n\n", server_msg, error->message);
                 soup_server_message_set_status (server_msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, NULL);
-                soup_server_unpause_message (server, server_msg);
+                soup_server_message_unpause (server_msg);
                 g_error_free (error);
                 return;
         }
@@ -365,7 +365,7 @@ server_callback (SoupServer *server, SoupServerMessage *msg,
 
         // Keep the server message alive until the client one is finished
        g_object_ref (msg);
-       soup_server_pause_message (server, msg);
+       soup_server_message_pause (msg);
 }
 
 static gboolean
diff --git a/libsoup/server/soup-server-message-private.h b/libsoup/server/soup-server-message-private.h
index bb3b0fc4..739019ed 100644
--- a/libsoup/server/soup-server-message-private.h
+++ b/libsoup/server/soup-server-message-private.h
@@ -20,8 +20,6 @@ void               soup_server_message_set_auth            (SoupServerMessage
                                                             SoupAuthDomain           *domain,
                                                             char                     *user);
 gboolean           soup_server_message_is_keepalive        (SoupServerMessage        *msg);
-void               soup_server_message_pause               (SoupServerMessage        *msg);
-void               soup_server_message_unpause             (SoupServerMessage        *msg);
 gboolean           soup_server_message_is_io_paused        (SoupServerMessage        *msg);
 void               soup_server_message_finish              (SoupServerMessage        *msg);
 void               soup_server_message_cleanup_response    (SoupServerMessage        *msg);
diff --git a/libsoup/server/soup-server-message.c b/libsoup/server/soup-server-message.c
index 5df59853..9ef34be0 100644
--- a/libsoup/server/soup-server-message.c
+++ b/libsoup/server/soup-server-message.c
@@ -565,17 +565,43 @@ soup_server_message_get_io_data (SoupServerMessage *msg)
         return msg->io_data;
 }
 
+/**
+ * soup_server_message_pause:
+ * @msg: a SoupServerMessage
+ *
+ * Pauses I/O on @msg.
+ *
+ * This can be used when you need to return from the server handler without
+ * having the full response ready yet. Use [method@ServerMessage.unpause] to
+ * resume I/O.
+ *
+ * Since: 3.2
+ */
 void
 soup_server_message_pause (SoupServerMessage *msg)
 {
+        g_return_if_fail (SOUP_IS_SERVER_MESSAGE (msg));
         g_return_if_fail (msg->io_data != NULL);
 
         soup_server_message_io_pause (msg->io_data, msg);
 }
 
+/**
+ * soup_server_message_unpause:
+ * @msg: a SoupServerMessage
+ *
+ * Resumes I/O on @msg.
+ *
+ * Use this to resume after calling [method@ServerMessage.pause], or after
+ * adding a new chunk to a chunked response. I/O won't actually resume until you
+ * return to the main loop.
+ *
+ * Since: 3.2
+ */
 void
 soup_server_message_unpause (SoupServerMessage *msg)
 {
+        g_return_if_fail (SOUP_IS_SERVER_MESSAGE (msg));
         g_return_if_fail (msg->io_data != NULL);
 
         soup_server_message_io_unpause (msg->io_data, msg);
diff --git a/libsoup/server/soup-server-message.h b/libsoup/server/soup-server-message.h
index de5fdc90..df77928b 100644
--- a/libsoup/server/soup-server-message.h
+++ b/libsoup/server/soup-server-message.h
@@ -80,6 +80,12 @@ GIOStream          *soup_server_message_steal_connection      (SoupServerMessage
 SOUP_AVAILABLE_IN_ALL
 gboolean            soup_server_message_is_options_ping       (SoupServerMessage *msg);
 
+SOUP_AVAILABLE_IN_3_2
+void                 soup_server_message_pause                (SoupServerMessage *msg);
+
+SOUP_AVAILABLE_IN_3_2
+void                 soup_server_message_unpause              (SoupServerMessage *msg);
+
 SOUP_AVAILABLE_IN_3_2
 GTlsCertificate     *soup_server_message_get_tls_peer_certificate          (SoupServerMessage *msg);
 
diff --git a/libsoup/server/soup-server.c b/libsoup/server/soup-server.c
index 6f42769d..0b2abb1b 100644
--- a/libsoup/server/soup-server.c
+++ b/libsoup/server/soup-server.c
@@ -84,7 +84,7 @@
  * %SOUP_STATUS_BAD_REQUEST accordingly.
  *
  * If the message still has no status code at this point (and has not
- * been paused with [method@Server.pause_message]), then it will be
+ * been paused with [method@ServerMessage.pause]), then it will be
  * given a status of %SOUP_STATUS_INTERNAL_SERVER_ERROR (because at
  * least one handler ran, but returned without assigning a status).
  *
@@ -1633,16 +1633,16 @@ get_or_create_handler (SoupServer *server, const char *exact_path)
  *
  * If the callback cannot fully fill in the response before returning
  * (eg, if it needs to wait for information from a database, or
- * another network server), it should call [method@Server.pause_message]
+ * another network server), it should call [method@ServerMessage.pause]
  * to tell @server to not send the response right away. When the
- * response is ready, call [method@Server.unpause_message] to cause it
+ * response is ready, call [method@ServerMessage.unpause] to cause it
  * to be sent.
  *
  * To send the response body a bit at a time using "chunked" encoding, first
  * call [method@MessageHeaders.set_encoding] to set %SOUP_ENCODING_CHUNKED on
  * the response-headers. Then call [method@MessageBody.append] (or
  * [method@MessageBody.append_bytes])) to append each chunk as it becomes ready,
- * and [method@Server.unpause_message] to make sure it's running. (The server
+ * and [method@ServerMessage.unpause] to make sure it's running. (The server
  * will automatically pause the message if it is using chunked encoding but no
  * more chunks are available.) When you are done, call
  * [method@MessageBody.complete] to indicate that no more chunks are coming.
@@ -1885,15 +1885,15 @@ soup_server_remove_auth_domain (SoupServer *server, SoupAuthDomain *auth_domain)
  * #SoupServer and are currently doing I/O, such as those passed into a
  * [callback@ServerCallback] or emitted in a [signal@Server::request-read]
  * signal.
+ *
+ * Deprecated: 3.2: Use soup_server_message_pause() instead.
  **/
 void
 soup_server_pause_message (SoupServer        *server,
                           SoupServerMessage *msg)
 {
        g_return_if_fail (SOUP_IS_SERVER (server));
-       g_return_if_fail (SOUP_IS_SERVER_MESSAGE (msg));
 
-        /* FIXME: make this public and deprecate soup_server_pause_message */
        soup_server_message_pause (msg);
 }
 
@@ -1913,15 +1913,15 @@ soup_server_pause_message (SoupServer        *server,
  * #SoupServer and are currently doing I/O, such as those passed into a
  * [callback@ServerCallback] or emitted in a [signal@Server::request-read]
  * signal.
+ *
+ * Deprecated: 3.2: Use soup_server_message_unpause() instead.
  **/
 void
 soup_server_unpause_message (SoupServer        *server,
                             SoupServerMessage *msg)
 {
        g_return_if_fail (SOUP_IS_SERVER (server));
-       g_return_if_fail (SOUP_IS_SERVER_MESSAGE (msg));
 
-        /* FIXME: make this public and deprecate soup_server_unpause_message */
        soup_server_message_unpause (msg);
 }
 
diff --git a/libsoup/server/soup-server.h b/libsoup/server/soup-server.h
index d98ef512..c7f52407 100644
--- a/libsoup/server/soup-server.h
+++ b/libsoup/server/soup-server.h
@@ -150,10 +150,10 @@ void            soup_server_remove_auth_domain (SoupServer         *server,
                                                SoupAuthDomain     *auth_domain);
 
 /* I/O */
-SOUP_AVAILABLE_IN_ALL
+SOUP_DEPRECATED_IN_3_2_FOR(soup_server_message_pause)
 void            soup_server_pause_message   (SoupServer        *server,
                                             SoupServerMessage *msg);
-SOUP_AVAILABLE_IN_ALL
+SOUP_DEPRECATED_IN_3_2_FOR(soup_server_message_unpause)
 void            soup_server_unpause_message (SoupServer        *server,
                                             SoupServerMessage *msg);
 
diff --git a/tests/context-test.c b/tests/context-test.c
index c99f2451..14903d53 100644
--- a/tests/context-test.c
+++ b/tests/context-test.c
@@ -9,7 +9,6 @@
 static char *base_uri;
 
 typedef struct {
-       SoupServer *server;
        SoupServerMessage *msg;
        GSource *timeout;
 } SlowData;
@@ -35,7 +34,7 @@ add_body_chunk (gpointer data)
        soup_message_body_append (response_body,
                                  SOUP_MEMORY_STATIC, "OK\r\n", 4);
        soup_message_body_complete (response_body);
-       soup_server_unpause_message (sd->server, sd->msg);
+       soup_server_message_unpause (sd->msg);
        g_object_unref (sd->msg);
 
        return FALSE;
@@ -67,10 +66,9 @@ server_callback (SoupServer        *server,
        soup_message_headers_set_encoding (response_headers,
                                           SOUP_ENCODING_CHUNKED);
        g_object_ref (msg);
-       soup_server_pause_message (server, msg);
+       soup_server_message_pause (msg);
 
        sd = g_new (SlowData, 1);
-       sd->server = server;
        sd->msg = msg;
        sd->timeout = soup_add_timeout (
                g_main_context_get_thread_default (),
diff --git a/tests/misc-test.c b/tests/misc-test.c
index f0a33e96..9bb5e8da 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -21,9 +21,7 @@ auth_callback (SoupAuthDomain *auth_domain, SoupMessage *msg,
 static gboolean
 timeout_finish_message (gpointer msg)
 {
-       SoupServer *server = g_object_get_data (G_OBJECT (msg), "server");
-
-       soup_server_unpause_message (server, msg);
+       soup_server_message_unpause (msg);
        return FALSE;
 }
 
@@ -49,8 +47,7 @@ server_callback (SoupServer        *server,
 
        if (!strcmp (path, "/slow")) {
                 GSource *timeout;
-               soup_server_pause_message (server, msg);
-               g_object_set_data (G_OBJECT (msg), "server", server);
+               soup_server_message_pause (msg);
                timeout = soup_add_timeout (g_main_context_get_thread_default (),
                                             1000, timeout_finish_message, msg);
                 g_source_unref (timeout);
diff --git a/tests/server-test.c b/tests/server-test.c
index 8f81c256..19384d51 100644
--- a/tests/server-test.c
+++ b/tests/server-test.c
@@ -770,7 +770,6 @@ do_iostream_accept_test (void)
 }
 
 typedef struct {
-       SoupServer *server;
        SoupServerMessage *smsg;
        gboolean handler_called;
        gboolean paused;
@@ -781,7 +780,7 @@ idle_unpause_message (gpointer user_data)
 {
        UnhandledServerData *usd = user_data;
 
-       soup_server_unpause_message (usd->server, usd->smsg);
+       soup_server_message_unpause (usd->smsg);
        return FALSE;
 }
 
@@ -798,9 +797,8 @@ unhandled_server_callback (SoupServer        *server,
 
        if (soup_message_headers_get_one (soup_server_message_get_request_headers (msg), 
"X-Test-Server-Pause")) {
                usd->paused = TRUE;
-               usd->server = server;
                usd->smsg = msg;
-               soup_server_pause_message (server, msg);
+               soup_server_message_pause (msg);
                g_idle_add (idle_unpause_message, usd);
        }
 }
@@ -1237,7 +1235,7 @@ tunnel_connected_cb (GObject      *object,
                                                  SOUP_MEMORY_COPY,
                                                  error->message, strlen (error->message));
                g_error_free (error);
-               soup_server_unpause_message (tunnel->self, tunnel->msg);
+               soup_server_message_unpause (tunnel->msg);
                tunnel_close (tunnel);
                return;
        }
@@ -1246,7 +1244,7 @@ tunnel_connected_cb (GObject      *object,
        tunnel->server.ostream = g_io_stream_get_output_stream (tunnel->server.iostream);
 
        soup_server_message_set_status (tunnel->msg, SOUP_STATUS_OK, NULL);
-       soup_server_unpause_message (tunnel->self, tunnel->msg);
+       soup_server_message_unpause (tunnel->msg);
        g_signal_connect (tunnel->msg, "wrote-body",
                          G_CALLBACK (start_tunnel), tunnel);
 }
@@ -1267,7 +1265,7 @@ proxy_server_callback (SoupServer        *server,
                return;
        }
 
-       soup_server_pause_message (server, msg);
+       soup_server_message_pause (msg);
 
        tunnel = g_new0 (Tunnel, 1);
        tunnel->self = g_object_ref (server);
diff --git a/tests/timeout-test.c b/tests/timeout-test.c
index 6783e341..7a32e766 100644
--- a/tests/timeout-test.c
+++ b/tests/timeout-test.c
@@ -179,9 +179,7 @@ do_sync_timeout_tests (gconstpointer data)
 static gboolean
 timeout_finish_message (gpointer msg)
 {
-       SoupServer *server = g_object_get_data (G_OBJECT (msg), "server");
-
-       soup_server_unpause_message (server, msg);
+       soup_server_message_unpause (msg);
        return FALSE;
 }
 
@@ -199,8 +197,7 @@ server_handler (SoupServer        *server,
 
        if (!strcmp (path, "/slow")) {
                 GSource *timeout;
-               soup_server_pause_message (server, msg);
-               g_object_set_data (G_OBJECT (msg), "server", server);
+               soup_server_message_pause (msg);
                timeout = soup_add_timeout (g_main_context_get_thread_default (),
                                             4000, timeout_finish_message, msg);
                 g_source_unref (timeout);


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