GIOChannel



Hello all,

I encounter a lot of segfaults in my program - randomly from pango,
malloc_consolidate and maybe some more functions in libraries.
Everything started when I wanted to shutdown GIOChannel.

Only a very little is written about using channels, however doc says
gdk_input_* functions are deprecated so I decided to use them in network
communication.

DESCRIPTION:

Created:
        -server channel -> socket(STREAM);
                           bind();
                           listen();
                           srv_chan = g_io_channel_unix_new(server_sock);
                           /* will do accept on condition */
                           srv_source =g_io_add_watch(G_IO_IN);

        -client channels -> socket(UDP);
                            connect();
                            cli_chan = g_io_channel_unix_new(client_sock);
                            cli_source = g_io_add_watch(G_IO_IN);


Destroyed:
        -server channel -> right after client is accepted
                           ( it is created again later)

                          g_source_remove(srv_source);
                          g_io_channel_shutdown(srv_chan);
                          
                          /* HORRIBLE!!! any other way ? */
                          while (srv_chan->ref_count>1)
                                g_io_channel_unref(srv_chan);
                                
                          /* last reference causes channel to be
                             destroyed and ref_count is set to random
                             value, often higher than 1, which caused
                             'infinite' looping */
                           g_io_channel_unref(srv_chan);

                           /* ok, now ref_count is 0, channel should
                              be destroyed */
                           srv_chan = NULL;
                             
        
        -client channels -> randomly by user or some events
                            - code is very similar to server's 




QUESTIONS:
        i)      Is this 'modus operandi' OK?
        
        ii)     Should I explicitly unregister triggering functions? How?
        
        iii)    Is there any CLEAN way how to find out ref_count of channel?
        
        iv)     Anybody willing to share running example code?
        
        v)      Is there any way how to unregister triggering function (I don't
                really need to destroy the server channel, just prevent it from 
                accepting messages for a period of time)

REMARKS:

        Everytime I destroy a channel, it is set to NULL. Every
        channel-destroying function checks it before doing anything.


        I used only g_io_channel_shutdown(), calling ONCE g_io_channel_unref() 
        immidiately afterwards  - sometimes the channel lowers its
        ref_count in shutdown() call, so the result were *FAULTs when I
        tried to re-createe server channel on the same port (new channel,
        new socket, the same parameters) 

        Removing source advice comes from this list - it worked for
        someone.



I'm a little bit desperate (all these segfaults comming from depths of
libraries :((( ), so I'd really appreciate any help.

Thank you people.
Michal



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