Re: Using GIOChannel synchronously and asynchronously
- From: silverburgh <silverburgh meryl gmail com>
- To: gtk-list gnome org
- Subject: Re: Using GIOChannel synchronously and asynchronously
- Date: Mon, 8 Feb 2010 22:41:05 -0800
Hi,
I have a gtk program which uses GIOChannel to process data from a
socket asynchronously. Like this:
int
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?
int
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
gio_read_socket(channel...)
}
// 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(;;)
loop?
// Never get here now?
//gtk_main()
}
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]