I’m trying to configure a timer with the timer_create() function to send a
pulse when it expires. I had read that the value returned from name_open is
equivalent to the coid returned by ConnectAttach. When I use the file
descriptor from name_open to initialize the signal sigevent structure, then
try to run the timer, I don’t receive any of the pulse messages. If I use
the ConnectAttach to init the sigevent, everything works as expected. Is the
help file on name_attach wrong, or am I trying to do something incorrect.
Following is a short test that demonstrates my problem. when _USE_CCT_ATT is
defined, everything works well. When it isn’t, the pulses aren’t received.
Thanks for your help,
David Kuechenmeister
#include <stdio.h>
#include <syslog.h>
#include <sys/neutrino.h>
#include <sys/dispatch.h>
#define _USE_CCT_ATT
#undef _USE_CCT_ATT
#define _PULSE_CODE_STOW_FAIL 10
int main(void)
{
struct _pulse msg;
name_attach_t *attach;
struct itimerspec timerVal;
int coid;
struct sigevent sigEventT1;
timer_t timerT1ID;
int axis = 0;
timerVal.it_value.tv_sec = (long int)10;
timerVal.it_value.tv_nsec = 0;
timerVal.it_interval.tv_sec = (long int)1;
timerVal.it_interval.tv_nsec = 0;
#ifdef _USE_CCT_ATT
int chid = ChannelCreate(0);
coid = ConnectAttach(0,0,chid,_NTO_SIDE_CHANNEL,0);
#else
// create the channel
if ((attach = name_attach(NULL, “testTimer”, 0)) == NULL) {
syslog(LOG_ERR,“name_attach failed…%m”);
}
// get coid for timer
if((coid = name_open(“testTimer”,0) < 0))
{
syslog(LOG_ERR,“name_open failed…%m”);
}
#endif
// Set up the timer
sigEventT1.sigev_notify = SIGEV_PULSE;
sigEventT1.sigev_coid = coid;
sigEventT1.sigev_priority = getprio(0);
sigEventT1.sigev_code = _PULSE_CODE_STOW_FAIL;
sigEventT1.sigev_value.sival_int = axis;
if(timer_create(CLOCK_REALTIME, &sigEventT1, &timerT1ID) < 0)
{
syslog(LOG_ERR,“CStowPed:timer_create failed for T1…%m”);
}
if(timer_settime(timerT1ID, 0, &timerVal, NULL) < 0)
{
syslog(LOG_ERR,“CStowPed::timer_settime failed for T1…%m”);
}
int rcvid;
for(int i=0;i<10;i++)
{
#ifdef _USE_CCT_ATT
rcvid = MsgReceive(chid,&msg,sizeof(msg),NULL);
#else
rcvid = MsgReceive(attach->chid,&msg,sizeof(msg),NULL);
#endif
if(rcvid == 0)
{
if(msg.code == _PULSE_CODE_STOW_FAIL)
{
printf(“Received timer pulse\n”);
}
else
{
printf(“Received some other pulse %d\n”,msg.code);
}
}
else
{
printf(“Received some other message, rcvid = %d\n”,rcvid);
}
}
}