Jeevan Mathew(deleted)
|
Re: Getting info about remote process death with a channel/connection
|
Jeevan Mathew(deleted)
06/03/2009 7:07 AM
post30659
|
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
|
|
|