Re: Using GIOChannel synchronously and asynchronously


I have a gtk program which uses GIOChannel to process data from a
socket asynchronously. Like this:

main (int argc, char* argv[])
 // int socket is a socket which is set to non-blocking mode

GIOChannel* channel = g_io_channel_unix_new(socket);

// gio_read_socket() is called when there is somet data in the socket
g_io_add_watch(channel, G_IO_IN | G_IO_HUP,
			gio_read_socket, NULL)

 gtk_main ();
  // never gets here

I would like to know if it is possible to change my program to process
data form a socket synchronously?

main (int argc, char* argv[])
 // int socket is a socket

GIOChannel* channel = g_io_channel_unix_new(socket);

for(;;) {
//block until there is data from channel....
  if  (g_io_channel_read_line(channel...) != G_IO_STATUS_ERROR) {
     // call my gio_read_socket() function to process data from channell


// My question is if i do the above, how can I call gtk_main()? Isn't
gtk_main() supposed to create its own message loop for input events,
UI events, how can I process those events if i have my own for(;;)
// Never get here now?

Thank you for any suggestion.

On Sun, Feb 7, 2010 at 4:56 PM, silverburgh <silverburgh meryl gmail com> wrote:
> Hi,
> I am trying to use GIOChannel with a socket on Linux.
> I would like to know if I need to set the socket to 'non blocking'
> mode before I setup the GIOChannel?
> And If I can mix my GIOChannel read/write operation synchronously and
> asynchronously? If yes, how can I do that?
> Thank you.

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