callbacks: doing i/o bound stuff in them



Ok, I've got this problem. I want to write an application which at some point has some networking
to do. The user configures the networking settings in a druid, and when the druid finishes I want
a progress window to pop up and show the status (the networking thing is basically listening at a
port and waiting for 3 clients to connect, so it might take a while).

So, I did the druid, figured out how to make it non-linear and added a callback to the finish
signal. Problem is that things I do IN the callback function do not get "done" until the function
has returned. Look at the following code:


/* inteface.c (yes I'm using glade :-) */
 g_signal_connect ((gpointer) druid_pf, "finish",
                    G_CALLBACK (on_druid_pf_finish),
                    NULL);

/* callbacks.c */
void on_druid_pf_finish                     (GnomeDruidPage  *gnomedruidpage,
                                        GtkWidget       *widget,
                                        gpointer         user_data)
{
        GtkWidget *win;

        win=create_progress_win();
        gtk_widget_show(win);
        gtk_widget_destroy(lookup_widget(GTK_WIDGET(widget),"newgame_win"));
        sleep(10);
}


What happens is that I click "Finish" on the druid the "finish" button remains clicked and it
sleeps for 10 seconds. AFTER that, the druid window closes and the progress window shows up
("newgame_win" is the window containing the druid)! What am I doing wrong? It happens with -O0
optimization.

How should I handle this? Do I need threads to do the socket listening so as not to lag the UI?

Sorry if this is a trivial question, but this is my first gtk+ program.

Thanks in advance,
Vassilis Pandis


        
        
                
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com



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