queue_message


Description:

public virtual void queue_message (owned Message msg, SessionCallback? callback)

Queues the message msg for asynchronously sending the request and receiving a response in the current thread-default MainContext.

If msg has been processed before, any resources related to the time it was last sent are freed.

Upon message completion, the callback specified in callback will be invoked. If after returning from this callback the message has not been requeued, msg will be unreffed.

(The behavior above applies to a plain Session; if you are using SessionAsync or SessionSync, then the MainContext that is used depends on the settings of async_context and use_thread_context, and for SessionSync, the message will actually be sent and processed in another thread, with only the final callback occurring in the indicated MainContext.)

Contrast this method with send_async, which also asynchronously sends a message, but returns before reading the response body, and allows you to read the response via a InputStream.

Example: Basic soup request, async:

public static int main (string[] args) {
MainLoop loop = new MainLoop ();

// Create a session:
Soup.Session session = new Soup.Session ();

// Send a request:
Soup.Message msg = new Soup.Message ("GET", "http://gnome.org/");
session.queue_message (msg, (sess, mess) => {
// Process the result:
print ("Status Code: %u\n", mess.status_code);
print ("Message length: %lld\n", mess.response_body.length);
print ("Data: \n%s\n", (string) mess.response_body.data);
loop.quit ();
});

loop.run ();
return 0;
}

valac --pkg libsoup-2.4 basic-soup-request-get-async.vala

Parameters:

this

a Session

msg

the message to queue

callback

a SessionCallback which will be called after the message completes or when an unrecoverable error occurs.

user_data

a pointer passed to callback.