Pipes and gtk_main() under Win32



Hello there.

I'm hacking on LogJam, a GTK+ project, to make it work equally well
(okay, almost equally well) on Win32, beside its natural habitat of
Unix.  Some existing code relied on a pipe file handle being closed to
regain control after calling gtk_main(), and implementing that code in
Win32, I do not receive the control back, for some reason.

Here is my code, simplified and with irrelevant parts cut out.  I'd
appreciate any insight into making this work.  Thanks in advance.

unsigned long __stdcall thread_func(void* params)
{
        thread_params* p = params;
        if (do_stuff() < 0) {
                pipe_write(p->nr->pipefds[1], SP__ERROR, ERROR_SIZE, p->nr->errorbuf);
        } else {
                pipe_write(p->nr->pipefds[1], SP__SUCCESS, p->response->len, p->response->str);
        }
        g_string_free(p->response, TRUE);
        close(p->nr->pipefds[1]);
        return 0;
}

static NetResult*
run_request_fork(net_request *nr, NetRequest *request) {
        NetResult *result;
        GString *response;
        DWORD thread_id;
        thread_params params;
        response = g_string_sized_new(RESPONSE_SIZE);

        /* prepare pipe and params */
        if (pipe(nr->pipefds) < 0) {
                /*...*/
                return NULL;
        }
        params.nr = nr;
        params.request = request;
        params.response = response;

        /* launch a thread */
        if(CreateThread(NULL, THREAD_STACK_SIZE, &thread_func, &params, 0, &thread_id) == NULL) {
                /*...*/
                return NULL;
        }

        /* wait for response */
        nr->pipe_tag = gtk_input_add_full(nr->pipefds[0], GDK_INPUT_READ,
                (GdkInputFunction)pipe_cb, NULL, nr, NULL);
        gtk_main();

        /* clean up */
        gtk_input_remove(nr->pipe_tag);
        nr->pipe_tag = 0;
        nr->pid = 0;

        close(nr->pipefds[0]);
        /* etc...*/

Tracing through the code, I see execution reach thread_func, as well
as pipe_cb, and all pipe writes and the close() calls succeed.  Why
then does it never return from gtk_main()?

Any help appreciated.

   Ijon
-- 
http://ijon.livejournal.com
 Ijon                          mailto:ijon forum2 org




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