Re: How to use GIOChannel to read an Unix socket



Hi silverburgh,

On Tue, 26 Jan 2010 23:59:11 -0800 you wrote:
> 
> I have updated my gio_read_socket per your advice.

No you haven't.


Chris explicitly said you need to "free the GIOChannel object"and that using g_io_channel_shutdown "of itself is not sufficient". I quote:

> Actually, you have attempted to fix your problem in a different way,
> by closing the socket when the read data length is 0, assuming that you
> are doing blocking reads.  However, you need to free the GIOChannel
> object. The easiest way to do that is to call g_io_channel_unref() on
> the GIOChannel object immediately after you have called
> g_io_add_watch() on it. g_io_channel_*_new() returns a GIOChannel
> object with a reference count of one.  g_io_add_watch() adds a further
> reference count - if you decrement it by 1, the callback will be
> disconnected and the relevant GSource object removed when the callback
> returns FALSE, which it should do when it detects end-of-file, or if
> you call g_source_remove() on the return value of g_io_add_watch().
> (Incidentally, you are also supposed to use g_io_channel_shutdown()
> rather than g_io_channel_close(), but that of itself is not sufficient
> to free the GIOCondition object and it is not necessary anyway in this
> usage.)  I agree that the documentation on this isn't very good.

So you need to change how you create the channel object (which you haven't posted so I have to assume you didn't change it) _AND_ you need to ensure that the callback returns FALSE when it detects end of file. Try doing what Chris said and see if that helps.

Rob


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