Re: how to generate glib events



My approach to this is to spawn another thread to handle the events
- Create a GAsyncQueue
	g_async_queue_new(void);
- Create the worker thread
- in your watch callback, pack the data you've received into a structure, and push it onto the GAsyncQueue
	g_async_queue_push(GAsyncQueue *queue, gpointer data);

- in your worker thread, wait on the queue and process messages, as they are received, in order
	while (message = g_async_queue_pop(GAsyncQueue *queue))
	{
		/* do stuff */
	}

Mauro Condarelli wrote:
Hi All,
sorry to disturb, but I seem unable to fully grasp this.

I am using glib (not full GTK+) for a server application that needs to listen to multiple sockets/pipes.
I managed to have the GIOChannels working the way I need them.
Now I have (in some of the GIOChannel watches) a complete message to be processed. In order to serialize processing I would like to avoid processing directly in the watch callback, I would like to "queue" somehow the message and have another "watch" in the main loop to wait on this queue. I can do this easily using polling and timeouts, but this would introduce unacceptable delays. I'm currently trying to implement this using a pipe and another GIOChannel watching on it.
Is this the right way to do such a thing?
Is there another (better) way to do this.
Can someone point me to the right documentation (possibly some tutorial)?
Should I implement a new Source (g_source_new() and all associated paraphernalia)?
If so: where can I get some example?

Thanks in Advance
Mauro
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





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