[libsoup/carlosgc/requeue-private: 4/6] session: make soup_session_steal_connection static




commit 99e633f74e82b557326c17169a7d654712519001
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Wed Sep 30 11:40:58 2020 +0200

    session: make soup_session_steal_connection static
    
    And remove the stealing tests since it's internal api already covered by
    websockets tests.

 libsoup/soup-session-private.h |   3 -
 libsoup/soup-session.c         |   5 +-
 tests/misc-test.c              | 184 -----------------------------------------
 3 files changed, 2 insertions(+), 190 deletions(-)
---
diff --git a/libsoup/soup-session-private.h b/libsoup/soup-session-private.h
index 023cd6cb..3272301b 100644
--- a/libsoup/soup-session-private.h
+++ b/libsoup/soup-session-private.h
@@ -15,9 +15,6 @@ G_BEGIN_DECLS
 SoupMessageQueue     *soup_session_get_queue            (SoupSession          *session);
 
 
-GIOStream *           soup_session_steal_connection     (SoupSession          *session,
-                                                         SoupMessage          *msg);
-
 
 G_END_DECLS
 
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index d801f6f8..1ae7aba2 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -3995,9 +3995,8 @@ steal_connection (SoupSession          *session,
  *   connection). No guarantees are made about what kind of #GIOStream
  *   is returned.
  *
- * Since: 2.50
- **/
-GIOStream *
+ */
+static GIOStream *
 soup_session_steal_connection (SoupSession *session,
                               SoupMessage *msg)
 {
diff --git a/tests/misc-test.c b/tests/misc-test.c
index 9a51c353..759c2abf 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -954,188 +954,6 @@ do_pause_cancel_test (void)
                g_source_remove (timeout_id);
 }
 
-static gboolean
-run_echo_server (gpointer user_data)
-{
-       GIOStream *stream = user_data;
-       GInputStream *istream;
-       GDataInputStream *distream;
-       GOutputStream *ostream;
-       char *str, *caps;
-       gssize n;
-       GError *error = NULL;
-
-       istream = g_io_stream_get_input_stream (stream);
-       distream = G_DATA_INPUT_STREAM (g_data_input_stream_new (istream));
-       ostream = g_io_stream_get_output_stream (stream);
-
-       /* Echo until the client disconnects */
-       while (TRUE) {
-               str = g_data_input_stream_read_line (distream, NULL, NULL, &error);
-               g_assert_no_error (error);
-               if (!str)
-                       break;
-
-               caps = g_ascii_strup (str, -1);
-               n = g_output_stream_write (ostream, caps, strlen (caps), NULL, &error);
-               g_assert_no_error (error);
-               g_assert_cmpint (n, ==, strlen (caps)); 
-               n = g_output_stream_write (ostream, "\n", 1, NULL, &error);
-               g_assert_no_error (error);
-               g_assert_cmpint (n, ==, 1);
-               g_free (caps);
-               g_free (str);
-       }
-
-       g_object_unref (distream);
-
-       g_io_stream_close (stream, NULL, &error);
-       g_assert_no_error (error);
-       g_object_unref (stream);
-
-       return FALSE;
-}
-
-static void
-steal_after_upgrade (SoupMessage *msg, gpointer user_data)
-{
-       SoupClientContext *context = user_data;
-       GIOStream *stream;
-       GSource *source;
-
-       /* This should not ever be seen. */
-       soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
-
-       stream = soup_client_context_steal_connection (context);
-
-       source = g_idle_source_new ();
-       g_source_set_callback (source, run_echo_server, stream, NULL);
-       g_source_attach (source, g_main_context_get_thread_default ());
-       g_source_unref (source);
-}
-
-static void
-upgrade_server_callback (SoupServer *server, SoupMessage *msg,
-                        const char *path, GHashTable *query,
-                        SoupClientContext *context, gpointer data)
-{
-       if (msg->method != SOUP_METHOD_GET) {
-               soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
-               return;
-       }
-
-       soup_message_set_status (msg, SOUP_STATUS_SWITCHING_PROTOCOLS);
-       soup_message_headers_append (msg->request_headers, "Upgrade", "ECHO");
-       soup_message_headers_append (msg->request_headers, "Connection", "upgrade");
-
-       g_signal_connect (msg, "wrote-informational",
-                         G_CALLBACK (steal_after_upgrade), context);
-}
-
-static void
-callback_not_reached (SoupMessage *msg,
-                     gpointer     user_data)
-{
-       g_assert_not_reached ();
-}
-
-static void
-switching_protocols (SoupMessage *msg, gpointer user_data)
-{
-       GIOStream **out_iostream = user_data;
-       SoupSession *session = g_object_get_data (G_OBJECT (msg), "SoupSession");
-
-       *out_iostream = soup_session_steal_connection (session, msg);
-}
-
-static void
-do_stealing_test (gconstpointer data)
-{
-       gboolean sync = GPOINTER_TO_INT (data);
-       SoupServer *server;
-       SoupURI *uri;
-       SoupSession *session;
-       SoupMessage *msg;
-       GIOStream *iostream;
-       GInputStream *istream;
-       GDataInputStream *distream;
-       GOutputStream *ostream;
-       int i;
-       gssize n;
-       char *str, *caps;
-       GError *error = NULL;
-       static const char *strings[] = { "one", "two", "three", "four", "five" };
-
-       server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
-       uri = soup_test_server_get_uri (server, SOUP_URI_SCHEME_HTTP, "127.0.0.1");
-       soup_server_add_handler (server, NULL, upgrade_server_callback, NULL, NULL);
-
-       session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
-       msg = soup_message_new_from_uri ("GET", uri);
-       soup_message_headers_append (msg->request_headers, "Upgrade", "echo");
-       soup_message_headers_append (msg->request_headers, "Connection", "upgrade");
-       g_object_set_data (G_OBJECT (msg), "SoupSession", session);
-
-       soup_message_add_status_code_handler (msg, "got-informational",
-                                             SOUP_STATUS_SWITCHING_PROTOCOLS,
-                                             G_CALLBACK (switching_protocols), &iostream);
-
-       iostream = NULL;
-
-       if (sync) {
-               soup_test_session_send_message (session, msg);
-               soup_test_assert_message_status (msg, SOUP_STATUS_SWITCHING_PROTOCOLS);
-       } else {
-               g_signal_connect (msg, "finished",
-                                 G_CALLBACK (callback_not_reached), NULL);
-               soup_session_send_async (session, msg, NULL, NULL, NULL);
-               while (iostream == NULL)
-                       g_main_context_iteration (NULL, TRUE);
-       }
-
-       g_assert (iostream != NULL);
-
-       g_object_unref (msg);
-       soup_test_session_abort_unref (session);
-       soup_uri_free (uri);
-
-       /* Now iostream connects to a (capitalizing) echo server */
-
-       istream = g_io_stream_get_input_stream (iostream);
-       distream = G_DATA_INPUT_STREAM (g_data_input_stream_new (istream));
-       ostream = g_io_stream_get_output_stream (iostream);
-
-       for (i = 0; i < G_N_ELEMENTS (strings); i++) {
-               n = g_output_stream_write (ostream, strings[i], strlen (strings[i]),
-                                          NULL, &error);
-               g_assert_no_error (error);
-               g_assert_cmpint (n, ==, strlen (strings[i]));
-               n = g_output_stream_write (ostream, "\n", 1, NULL, &error);
-               g_assert_no_error (error);
-               g_assert_cmpint (n, ==, 1);
-       }
-
-       for (i = 0; i < G_N_ELEMENTS (strings); i++) {
-               str = g_data_input_stream_read_line (distream, NULL, NULL, &error);
-               g_assert_no_error (error);
-               caps = g_ascii_strup (strings[i], -1);
-               g_assert_cmpstr (caps, ==, str);
-               g_free (caps);
-               g_free (str);
-       }
-
-       g_object_unref (distream);
-
-       g_io_stream_close (iostream, NULL, &error);
-       g_assert_no_error (error);
-       g_object_unref (iostream);
-
-       /* We can't do this until the end because it's in another thread, and
-        * soup_test_server_quit_unref() will wait for that thread to exit.
-        */ 
-       soup_test_server_quit_unref (server);
-}
-
 int
 main (int argc, char **argv)
 {
@@ -1177,8 +995,6 @@ main (int argc, char **argv)
        g_test_add_func ("/misc/aliases", do_aliases_test);
        g_test_add_func ("/misc/pause-abort", do_pause_abort_test);
        g_test_add_func ("/misc/pause-cancel", do_pause_cancel_test);
-       g_test_add_data_func ("/misc/stealing/async", GINT_TO_POINTER (FALSE), do_stealing_test);
-       g_test_add_data_func ("/misc/stealing/sync", GINT_TO_POINTER (TRUE), do_stealing_test);
 
        ret = g_test_run ();
 


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