[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gtk-devel
Subject:    Re: Is this a bug in the GIOChannel g_io_channel_write_chars() function?
From:       Jan Kratochvil <rcpt-gtk-devel-list.AT.gnome.org () jankratochvil ! net>
Date:       2003-11-12 15:09:47
[Download RAW message or body]

Hi,

On Wed, 12 Nov 2003 15:57:32 +0100, Jeff Franks wrote:
...
> In mainloop-test.c in the GLIb tests directory the following function works:
...
> err = g_io_channel_write (channel, buf + bytes_written, len - 
> bytes_written, &count);
...
> However g_io_channel_write() is deprecated. When I repalce it with 
> g_io_channel_write_chars() and update the code appropriately, to this:
...
> status = g_io_channel_write_chars (channel, buf + bytes_written, 
> len - bytes_written, &count, NULL);
...
> It does not work. instead you get this compiler error:
> 
> GLib-ERROR **: file giochannel.c: line 2113 (g_io_channel_write_chars): 
> should not be reached
> aborting...
> Trace/breakpoint trap

GIOChannel is expecting UTF8 text encoding for its data by default. If you want
to use it for raw binary data you need to use:

		g_io_channel_set_encoding (giochannel,
				NULL,	/* encoding; force binary data */
				NULL);	/* error */


Here is also a function to setup binary non-buffered GIOChannel from its any
previous state. GLib produces some warnings if used in straightforward way:

void captive_giochannel_setup (GIOChannel *giochannel)
{
	GIOStatus erriostatus;

	g_return_if_fail (giochannel != NULL);

	if (g_io_channel_get_encoding (giochannel)) {
		if (! g_io_channel_get_buffered (giochannel))	/* Prevent: Need to have NULL \
encoding to set the buffering state ... */  g_io_channel_set_buffered (giochannel, \
TRUE);	/* Prevent: Need to set the channel buffered before setting the encoding. */  \
erriostatus = g_io_channel_set_encoding (giochannel,  NULL,	/* encoding; force binary \
data */  NULL);	/* error */
		g_assert (erriostatus == G_IO_STATUS_NORMAL);
		}
	erriostatus = g_io_channel_flush (giochannel,
			NULL);	/* error */
	g_assert (erriostatus == G_IO_STATUS_NORMAL);
	g_io_channel_set_buffered (giochannel, FALSE);
}


Regards,
Lace

-- 
Jan Kratochvil; Captive: free r/w NTFS Filesystem; http://www.jankratochvil.net/
_______________________________________________
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic