How to set a specific channel that has higher priority?
Also I notice from the QNX library example of using “MsgDeliverEvent()”, the server first create a channel (#1) to receive a “cookie” from the client, the client then create another channel (#2) to receive pulse sigevent from the server. When the server has the need of notifying the client, it calls “MsgDeliverEvent(channel(#1), sigevent)” to deliver a pulse through channel #1 to the client that’s waiting for pulse on channel #2. My question is why is necessary to create two channel to do this? Is one channel enough for receiving message and pulse event? The example code is as follows:
#########client.c############
/* we need a channel to receive the pulse notification on */
chid = ChannelCreate( 0 );
/* and we need a connection to that channel for the pulse to be
delivered on */
coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0 );
/* fill in the event structure for a pulse */
SIGEV_PULSE_INIT( &msg.event, coid, SIGEV_PULSE_PRIO_INHERIT,
MY_PULSE_CODE, 0 );
msg.type = MSG_GIVE_PULSE;
/* find the server */
if ( (srv_coid = name_open( MY_SERV, 0 )) == -1)
{
printf(“failed to find server, errno %d\n”, errno );
exit(1);
}
/* give the pulse event we initialized above to the server for
later delivery */
MsgSend( srv_coid, &msg, sizeof(msg), NULL, 0 );
/* wait for the pulse from the server */
rcvid = MsgReceivePulse( chid, &pulse, sizeof( pulse ), NULL );
printf(“got pulse with code %d, waiting for %d\n”, pulse.code,
MY_PULSE_CODE );
###########server.c#########
/* attach the name the client will use to find us /
/ our channel will be in the attach structure */
if ( (attach = name_attach( NULL, MY_SERV, 0 )) == NULL)
{
printf(“server:failed to attach name, errno %d\n”, errno );
exit(1);
}
/* wait for the message from the client /
rcvid = MsgReceive( attach->chid, &msg, sizeof( msg ), NULL );
MsgReply(rcvid, 0, NULL, 0);
if ( msg.type == MSG_GIVE_PULSE )
{
/ wait until it is time to notify the client */
sleep(2);
/* deliver notification to client that client requested */
MsgDeliverEvent( rcvid, &msg.event );
printf("server:delivered event\n");
} else
{
printf(“server: unexpected message \n”);
}