RE: problems with GIOChannel



I want to ask two questions about GIOChannel:

1) when I add the channel to event loop by g_io_channel_add_watch(),
channel's reference number becomes 2. It's ok, but when I close the
socket: g_io_channel_shutdown() and g_io_unref() the 
reference number is
1. How can I remove this GIOChannel from the main event loop (is there
anything like g_io_channel_remove_watch() ?) ?

No, to remove the watch, you return FALSE in the callback function, as
explained here:
http://developer.gnome.org/doc/API/2.0/glib/glib-IO-Channels.html#GIOFunc


2) when data is ready to be received (in a socket) my application
freezes. I debugged it and found out that it freezes in
g_io_channel_read_chars(). I pass an allocated buffer and 

I did have a similar problem, I found that I was being notified that there
was input ready to read (via the g_io_channel_add_watch() callback) and was
reading the input, and that was fine.  In some instances (during early the
stages of development) I was trying to read MORE than was waiting for me on
the socket.  This mean't that the read function was waiting for more input
and the rest of the application stopped dealing with events until such time.

If you want me to send you the TCP module I wrote (under Linux), let me
know.

Also, just out of interest, have you thought about using gnet instead?? - I
moved over to it for cross-platform compatibility, it makes light work of
sockets and is fairly straight forward to use:
http://www.gnetlibrary.org/


Regards,
Martyn




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