Sreekanth wrote:
No…I did set the timer.Now i am seeing that the message_connect is failing
with errno of ESRCH (May be i over looked it earlier).But message_connect
is not supposed to return this error.Here is my entire code
Yikes ! There is a lot of code missing from your test program.
What follows is a working example.
Remember, if you are inside io-net most of this work is already done for
you, and Xiaodans’ paraphrased code is close to what you need.
#include <signal.h>
#include <time.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int timer_func(message_context_t *ctp,int code,unsigned flags,void *hdl)
{
printf(“Timer Hit\n”);
return 0;
}
static resmgr_connect_funcs_t connect_funcs;
static resmgr_io_funcs_t io_funcs;
static iofunc_attr_t attr;
main(int argc, char **argv)
{
dispatch_t *dpp;
int coid;
struct sigevent ev;
timer_t timer_callb;
struct itimerspec itime;
resmgr_attr_t resmgr_attr;
dispatch_context_t *ctp;
int id;
/* initialize dispatch interface */
if ( (dpp = dispatch_create()) == NULL ) {
fprintf( stderr, “%s: Unable to allocate
dispatch handle.\n”, argv[0] );
return EXIT_FAILURE;
}
/* initialize resource manager attributes */
memset( &resmgr_attr, 0, sizeof resmgr_attr );
resmgr_attr.nparts_max = 1;
resmgr_attr.msg_max_size = 2048;
/* initialize functions for handling messages */
iofunc_func_init( _RESMGR_CONNECT_NFUNCS, &connect_funcs,
_RESMGR_IO_NFUNCS, &io_funcs );
/* initialize attribute structure */
iofunc_attr_init( &attr, S_IFNAM | 0666, 0, 0 );
if((id=resmgr_attach(dpp, &resmgr_attr, “/testpulse”,
_FTYPE_ANY, 0, &connect_funcs,
&io_funcs, &attr)) == -1 ) {
fprintf( stderr, “%s: Unable to attach name.\n”,
argv[0] );
return EXIT_FAILURE;
}
ev.sigev_coid=message_connect(dpp, 0);
if(ev.sigev_coid == -1)
printf(“Message Connect failed %d\n”,errno);
ev.sigev_code=pulse_attach(dpp,MSG_FLAG_ALLOC_PULSE,0,timer_func,0);
if(ev.sigev_code == -1)
perror(“Pulse attach failed”);
ev.sigev_notify=SIGEV_PULSE;
ev.sigev_priority=32;
if(timer_create(CLOCK_REALTIME, &ev, &timer_callb) == -1)
perror(“Timer Create failed.”);
itime.it_value.tv_sec=2;
itime.it_value.tv_nsec=0;
itime.it_interval.tv_sec=2;
itime.it_interval.tv_nsec=0;
if(timer_settime(timer_callb,0, &itime, NULL) == -1) {
perror(“timer settime failed”);
return -1;
}
ctp=dispatch_context_alloc(dpp);
while(1) {
if((ctp = dispatch_block(ctp)) == NULL) {
fprintf(stderr, “block error\n”);
return EXIT_FAILURE;
}
dispatch_handler(ctp);
}
}