void soup_message_io_client (SoupMessageQueueItem *item, GIOStream *iostream, GMainContext *async_context, SoupMessageGetHeadersFn get_headers_cb, SoupMessageParseHeadersFn parse_headers_cb, gpointer header_data, SoupMessageCompletionFn completion_cb, gpointer completion_data) { SoupMessageIOData *io; io = new_iostate (item->msg, iostream, async_context, SOUP_MESSAGE_IO_CLIENT, get_headers_cb, parse_headers_cb, header_data, completion_cb, completion_data); io->item = item; soup_message_queue_item_ref (item); io->cancellable = item->cancellable; io->read_body = item->msg->response_body; io->write_body = item->msg->request_body; io->write_state = SOUP_MESSAGE_IO_STATE_HEADERS; if (!item->new_api) { gboolean blocking = SOUP_IS_SESSION_SYNC (item->session) || (!SOUP_IS_SESSION_ASYNC (item->session) && !item->async); io_run (item->msg, blocking); } }
void soup_message_send_request (SoupMessageQueueItem *item, SoupMessageCompletionFn completion_cb, gpointer user_data) { GMainContext *async_context; GIOStream *iostream; if (SOUP_IS_SESSION_ASYNC (item->session)) { async_context = soup_session_get_async_context (item->session); if (!async_context) async_context = g_main_context_default (); } else async_context = NULL; iostream = soup_socket_get_iostream (soup_connection_get_socket (item->conn)); soup_message_io_client (item, iostream, async_context, get_request_headers, parse_response_headers, item, completion_cb, user_data); }
static void do_cancel_while_reading_test_for_session (SoupSession *session) { SoupMessage *msg; GThread *thread = NULL; SoupURI *uri; gboolean done = FALSE; uri = soup_uri_new_with_base (base_uri, "/slow"); msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); g_object_set_data (G_OBJECT (msg), "session", session); g_object_ref (msg); g_object_ref (session); if (SOUP_IS_SESSION_ASYNC (session)) g_timeout_add (100, cancel_message_timeout, msg); else thread = g_thread_new ("cancel_message_thread", cancel_message_thread, msg); /* We intentionally don't use soup_session_send_message() here, * because it holds an extra ref on the SoupMessageQueueItem * relative to soup_session_queue_message(). */ g_object_ref (msg); soup_session_queue_message (session, msg, set_done, &done); while (!done) g_main_context_iteration (NULL, TRUE); if (msg->status_code != SOUP_STATUS_CANCELLED) { debug_printf (1, " FAILED: %d %s (expected Cancelled)\n", msg->status_code, msg->reason_phrase); errors++; } g_object_unref (msg); if (thread) g_thread_join (thread); }
static void do_cancel_while_reading_req_test_for_session (SoupSession *session) { SoupRequest *req; SoupURI *uri; GCancellable *cancellable; GError *error = NULL; uri = soup_uri_new_with_base (base_uri, "/slow"); req = soup_session_request_uri (session, uri, NULL); soup_uri_free (uri); cancellable = g_cancellable_new (); if (SOUP_IS_SESSION_ASYNC (soup_request_get_session (req))) { g_timeout_add (100, cancel_request_timeout, cancellable); soup_test_request_send (req, cancellable, &error); } else { GThread *thread; thread = g_thread_new ("cancel_request_thread", cancel_request_thread, g_object_ref (cancellable)); soup_test_request_send (req, cancellable, &error); g_thread_unref (thread); } if (!error) { debug_printf (1, " Request succeeded?\n"); errors++; } else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { debug_printf (1, " Unexpected error: %s\n", error->message); errors++; } g_clear_error (&error); g_object_unref (req); g_object_unref (cancellable); }