Problems with GIOChannels and sockets
- From: Arne Skjaerholt <arnsholt online no>
- To: <gtk-app-devel-list gnome org>
- Subject: Problems with GIOChannels and sockets
- Date: Fri, 17 Dec 2004 01:53:54 +0100 (CET)
Hello all,
I am starting to do some gtk application development, and I've started on a network server application.
Obviously I'm using the BSD socket interface to the network, and after a bit of digging I found the
GIOChannel interface for doing IO with gtk.
Now my problem is that my GIOChannel never seems to go be in any other state than G_IO_IN, which susequently
makes it a bit tricky to know when the remote host closes the connection. I've noticed that reading from the
closed socket always returns an empty string, so I guess that might be a workaround to the problem, but it
really seems to me that there is should be a better way to do this.
The bits of code pertaining to seting up the g_io_watch and so on:
=== BEGIN CODE ===
condition = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_PRI | G_IO_NVAL; /* When should the callback be called? */
new.watch_tag = g_io_add_watch ( new.io_channel, condition, socket_handler, (gpointer) pnew );
gboolean socket_handler ( GIOChannel *channel, GIOCondition condition, gpointer data )
{
switch ( condition )
{
case G_IO_IN:
/* Some variable decls. */
g_io_channel_read ( channel, &data_read, &data_len, &error );
/* Some debug print statements */
break;
default:
/* Close the socket/GIOChannel and some other cleanup needed. */
return TRUE;
}
=== END CODE ===
TIA,
Arne
:wq
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]