+2007-03-29 Dan Winship <danw@novell.com>
+
+ * libsoup/soup-session-sync.c (queue_message): Implement this by
+ sending the message (synchronously) in another thread and then
+ queueing the callback back in the main thread.
+
+ * libsoup/soup-session.c (soup_session_queue_message): update docs
+ to be more explicit about what thread the callback occurs in
+
2007-03-17 Dan Winship <danw@novell.com>
* libsoup/soup-message.c (soup_message_set_auth)
#include "soup-session-sync.h"
#include "soup-connection.h"
+#include "soup-misc.h"
typedef struct {
GMutex *lock;
return session;
}
+typedef struct {
+ SoupSession *session;
+ SoupMessage *msg;
+ SoupMessageCallbackFn callback;
+ gpointer user_data;
+} SoupSessionSyncAsyncData;
+
+static void
+async_data_free (SoupSessionSyncAsyncData *sad)
+{
+ g_object_unref (sad->session);
+ g_object_unref (sad->msg);
+ g_free (sad);
+}
+
+static gboolean
+queue_message_callback (gpointer data)
+{
+ SoupSessionSyncAsyncData *sad = data;
+
+ sad->callback (sad->msg, sad->user_data);
+ async_data_free (sad);
+ return FALSE;
+}
+
+static gpointer
+queue_message_thread (gpointer data)
+{
+ SoupSessionSyncAsyncData *sad = data;
+
+ soup_session_send_message (sad->session, sad->msg);
+ if (sad->callback) {
+ GMainContext *async_context;
+
+ g_object_get (sad->session,
+ SOUP_SESSION_ASYNC_CONTEXT, &async_context,
+ NULL);
+ soup_add_idle (async_context, queue_message_callback, sad);
+ } else
+ async_data_free (sad);
+
+ return NULL;
+}
static void
queue_message (SoupSession *session, SoupMessage *msg,
SoupMessageCallbackFn callback, gpointer user_data)
{
- /* FIXME */
- g_warning ("soup_session_queue_message called on synchronous session");
+ SoupSessionSyncAsyncData *sad;
+
+ sad = g_new (SoupSessionSyncAsyncData, 1);
+ sad->session = g_object_ref (session);
+ sad->msg = g_object_ref (msg);
+ sad->callback = callback;
+ sad->user_data = user_data;
+
+ g_thread_create (queue_message_thread, sad, FALSE, NULL);
}
static SoupConnection *
* 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.
+ * be invoked (in the thread associated with @session's async
+ * context). If after returning from this callback the message has not
+ * been requeued, @msg will be unreffed.
*/
void
soup_session_queue_message (SoupSession *session, SoupMessage *msg,