g_io_add_watch_full : Bad Condition passed to the callback function



Hi,
I'm working on Gaim and got the following problem/(bug?) : the function
used as callback is given the right condition (the one originally given
to g_io_add_watch_full) but suddenly that condition seems to be modified
by one of the internal GLib functions maybe so another condition is
passed to it. Here's the code :

from eventloop.h : 
----------------

typedef enum
{
        GAIM_INPUT_READ  = 1 << 0,  /**< A read condition.  */
        GAIM_INPUT_WRITE = 1 << 1   /**< A write condition. */
                                                                                
} GaimInputCondition;

from gtkeventloop.c :
-------------------

static guint gaim_gtk_input_add(gint fd, GaimInputCondition condition,
GaimInputFunction function,
                                                           gpointer
data)
{
        GaimGtkIOClosure *closure = g_new0(GaimGtkIOClosure, 1);
        GIOChannel *channel;
        GIOCondition cond = 0;
                                                                                                                             
        closure->function = function;
        closure->data = data;
                                                                                                                             
        if (condition & GAIM_INPUT_READ)
                cond |= GAIM_GTK_READ_COND;
        if (condition & GAIM_INPUT_WRITE)
                cond |= GAIM_GTK_WRITE_COND;
                                                                                                                             
        channel = g_io_channel_unix_new(fd);
        closure->result = g_io_add_watch_full(channel,
G_PRIORITY_DEFAULT, cond,
                                              gaim_gtk_io_invoke,
closure, gaim_gtk_io_destroy);
                                                                                                                             
#if 0
        gaim_debug(GAIM_DEBUG_MISC, "gtk_eventloop",
                           "CLOSURE: adding input watcher %d for fd
%d\n",
                           closure->result, fd);
#endif
                                                                                                                             
        g_io_channel_unref(channel);
        return closure->result;
}


static gboolean gaim_gtk_io_invoke(GIOChannel *source, GIOCondition
condition, gpointer data)
{
        GaimGtkIOClosure *closure = data;
        GaimInputCondition gaim_cond = 0;
                                                                                                                             
        if (condition & GAIM_GTK_READ_COND)
                gaim_cond |= GAIM_INPUT_READ;
        if (condition & GAIM_GTK_WRITE_COND)
                gaim_cond |= GAIM_INPUT_WRITE;
        gaim_debug_info(NULL, "INVOKED WITH CONDITION %d gaim_cond : %d
source[%d] !!\n", condition, gaim_cond, source);
#if 0
        gaim_debug(GAIM_DEBUG_MISC, "gtk_eventloop",
                           "CLOSURE: callback for %d, fd is %d\n",
                           closure->result,
g_io_channel_unix_get_fd(source));
#endif
                                                                                                                             
        closure->function(closure->data,
g_io_channel_unix_get_fd(source), gaim_cond);
                                                                                                                             
        return TRUE;
}


Here's the output I get :

(...)
INVOKED WITH CONDITION 4 gaim_cond  : 2 source[137976744] !!
INVOKED WITH CONDITION 4 gaim_cond  : 2 source[137976744] !!
INVOKED WITH CONDITION 4 gaim_cond  : 2 source[137976744] !!
INVOKED WITH CONDITION 4 gaim_cond  : 2 source[137976744] !!
INVOKED WITH CONDITION 24 gaim_cond  : 3 source[137976744] !!
COND = 3
BAD CONDITION !!
INVOKED WITH CONDITION 24 gaim_cond  : 3 source[137976744] !!
(...)

I use all this to watch a socket for datas for File Transfer, and the
bug only seems to happen at speeds between 20 and 50 KB/s (it's maybe
just a coincidence, can't be sure about that), so maybe it's linked with
the frenquency at which the callback function is invoked.

Anything stupid thing in this piece of code :P ?
Is it possible for an external element to modify that condition ?
Or can it be a bug in the GLib ?

System infos :  rpm -q glib2 => glib2-2.2.3-1.1
------------	ldd /usr/local/bin/gaim |grep glib => libglib-2.0.so.0 =>
/usr/lib/libglib-2.0.so.0 (0x4f33c000)
		uname -a => Linux Spooky 2.4.25 #4 Tue Mar 30 12:45:55 CEST 2004 i686
athlon i386 GNU/Linux (running Fedora Core 1)

Thanks a lot.


Christian VINCENOT

"Portability is for people who cannot write new programs
                -me [Linus Torvalds], right now (with tongue in cheek)




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