Re: SoupServer - understanding multiple request at once handling



Just implemented it as g_timeout_add, always forget about the g_idle_add function.

Thanks a lot!

Best

Bernhard


2013/8/19 Emmanuel Rodriguez <emmanuel rodriguez gmail com>
On 19 August 2013 00:30, Bernhard Schuster <schuster bernhard googlemail com> wrote:
A callback will not help at all, if there exists a mixture of short and long operations. Long operations would still prevent handling secondary (short) requests, which could be served (almost) instantly.

So
soup_message_unpause (...)
soup_message_set_status (...)
soup_message_set_response (...)
are required to be the only ones modifing the session/message (which seems to work).

How is the below supposed to be implemented? According to the API doc (stable) everything is being processed in one and the same GMainContext, correct me if I am wrong.

Below the conceptual implementation with threads, which does contain potential races.  

void
server_callback(...)
{
    //do some basic checks
    soup_server_pause_message (...);
    user_data... = ... //copy and ref all data which is required
    g_signal_conncet (msg, "finished", finished_callback_does_cleanup, user_data)
    g_thread_try_new("worker", threaded_worker, user_data, &error)
    g_assert (!error);
}

gpointer
threaded_worker (..., user_data)
{
    if (is_long_op(user_data))
        super_long_op(...);
    else
        short_op(...);
    soup_server_unpause_message (...);
    soup_message_set_status (...);
    soup_message_set_response (...);
    return NULL;
}


gboolean
worker_done (gpointer user_data)
{
    soup_server_unpause_message (...);
    soup_message_set_status (...);
    soup_message_set_response (...);

    // free(user_data);
    return FALSE;
}

void
server_callback(...)
{
    //do some basic checks
    soup_server_pause_message (...);
    user_data... = ... //copy and ref all data which is required
    g_thread_try_new("worker", threaded_worker, user_data, &error)
    g_assert (!error);
}

gpointer
threaded_worker (..., user_data)
{
    if (is_long_op(user_data))
        super_long_op(...);
    else
        short_op(...);
    // Go back to the main loop to finish the request
    g_idle_add(worker_done, user_data);
    return NULL;
}


--
Emmanuel Rodriguez



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