Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Getting info about remote process death with a channel/connection: (4 Items)
   
Getting info about remote process death with a channel/connection  
Hi,

I'd like to know how I can get info whether the remote end of a connection is still alive...

Our Setting:
in the client i do a ChannelCreate() and ConnectAttach(). This channel ID is advertised to the server so it can notify 
the client asynchronously when necessary by sending a pulse. I do MsgReceive() in the client to receive the pulses.

This works so far.

Now I'd like to have the client notice when the server process dies. It has opened the client's channel, so this should 
be possible.

I've taken a look at the various ways to do this, but none seems to suit the problem:
http://www.qnx.com/developers/docs/6.4.0/neutrino/lib_ref/c/channelcreate.html

_NTO_CHF_DISCONNECT / _PULSE_CODE_DISCONNECT won't work because it is triggered when "all connections from a process are
 detached". This is not what I want... I want it to be called for any connection that is detached. Or did i 
misunderstand the manual here? The manual text is very confusing and seems to contradict itself at times. (On one hand, 
it says "Deliver a pulse when all connections from a process are detached", on the other hand it indicates that after 
receiving this pulse one should do a ConnectDetach() _in order to close_ the dropped connection...?)

_NTO_CHF_COID_DISCONNECT / _PULSE_CODE_COIDDEATH won't work because it seems this pulse occurs in the process who opened
 the channel (our example: the server), not the one who created it (our example: the client).

_NTO_CHF_THREAD_DEATH / _PULSE_CODE_THREADDEATH won't work because it only signals death of threads in the local process
, not the remotely connected process.

Am I mistaken? Or isn't there really any way to find out whether the server has died in our example? (Besides trying a 
periodic MsgSend() to it... yuck..)

Greetings,
 Marc
Re: Getting info about remote process death with a channel/connection  
> 
> _NTO_CHF_COID_DISCONNECT / _PULSE_CODE_COIDDEATH won't work because it seems 
> this pulse occurs in the process who opened the channel (our example: the 
> server), not the one who created it (our example: the client).
> 
yes.
_NTO_CHF_COID_DISCONNECT works for me in the networkcase.
Of courcse my client has a own channel with that flag to get the pulse that the server died.

my client:
[snip]
   /* look for server */
    server_coid = name_open( RECV_NAME, NAME_FLAG_ATTACH_GLOBAL );
    while( server_coid == -1 )
    {  
      sleep(1);
      server_coid = name_open( RECV_NAME, NAME_FLAG_ATTACH_GLOBAL );
    }

    /* We want to be notified when the server goes away.*/
    chid = ChannelCreate(_NTO_CHF_COID_DISCONNECT );
    if( -1 == chid)
    {
        perror( PROGNAME "ChannelCreate");
        exit( EXIT_FAILURE );
    }
    self_coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0 );
    if( -1 == self_coid )
    {
        perror( PROGNAME "ConnectAttach");
        exit( EXIT_FAILURE );
    }
    
    msg.type = REG_MSG;
    
    /* Initialize the sigevent structure (msg.ev) in the message 
     * to be sent to the server.
     */
    SIGEV_PULSE_INIT( &msg.ev, self_coid, getprio(0), MY_PULSE_CODE, 0 );

//send something to the server
    if (MsgSend( server_coid, &msg, sizeof( msg ), NULL, 0 ))
    {
        perror(PROGNAME "MsgSend");
        exit( EXIT_FAILURE );
    }
    
    while( 1 )
    {
        rcvid = MsgReceive( chid, &recv_buf, sizeof(recv_buf), NULL );
        if( -1 == rcvid )
        {
            perror(PROGNAME "MsgReceive");
            continue;
        }
        
        
        if ( 0 == rcvid )
        {
            /* we received a pulse, often a side-effect of using name_attach()
             * we need to deal with the system pulses appropriately 
             */
            switch( recv_buf.pulse.code ) 
            {
                /* system disconnect pulse */
                /* our pulse */    
                case MY_PULSE_CODE:
                	printf(PROGNAME "got my pulse, value is %d\n", recv_buf.pulse.value.sival_int);
                	break;
                
                case _PULSE_CODE_COIDDEATH:
                	printf(PROGNAME "COIDDEATH, value is %d\n", recv_buf.pulse.value.sival_int);
                	printf(PROGNAME "Exiting ...Bye\n");
                	exit(0);
                	break;	 
[snap]

attached a picture.
Jeevan

Attachment: Image ServDeathDetection.JPG 116.18 KB
Re: Getting info about remote process death with a channel/connection  
Jeevan, thanks it seems to work.
But I'm wondering a bit because it essentially contradicts the manual...
Re: Getting info about remote process death with a channel/connection  
> Jeevan, thanks it seems to work.
> But I'm wondering a bit because it essentially contradicts the manual...


Marc,

can you please elaborate where exactly you feel the contradiction is taking action ? That will hopefully help to get the
 docs more clear.

Thank You.
Jeevan