[gnet-dev] GIOChannel encoding in glib-2.0



In glib-2.0, GIOChannels support character encoding, and by default are
created with an encoding of UTF-8.  This is inappropriate for sending
binary data (it may cause g_io_channel_read_chars to block, for
example).  Reference:

http://developer.gnome.org/doc/API/2.0/glib/glib-io-channels.html#g-io-channel-set-encoding

The following patch immediately sets the encoding to NULL (in
src/inetaddr.c).  It does no error checking because immediately after
creating is one of the times setting the encoding is guaranteed to work.

Ian
--- inetaddr.c.old	Fri Sep 13 15:27:30 2002
+++ inetaddr.c	Fri Sep 13 15:23:23 2002
@@ -593,6 +593,7 @@
 	state->pid = pid;
 	state->fd = pipes[0];
 	state->iochannel = g_io_channel_unix_new(pipes[0]);
+	g_io_channel_set_encoding (state->iochannel, NULL, NULL);
 	state->watch = g_io_add_watch(state->iochannel,
 				      (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL),
 				      gnet_inetaddr_new_async_cb, 
@@ -1323,6 +1324,7 @@
 	state->pid = pid;
 	state->fd = pipes[0];
 	state->iochannel = g_io_channel_unix_new(pipes[0]);
+	g_io_channel_set_encoding (state->iochannel, NULL, NULL);
 	state->watch = g_io_add_watch(state->iochannel,
 				      (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL),
 				      gnet_inetaddr_get_name_async_cb, 


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