TimerTimout() doesn't work on MsgReceivev

Hallo all,

i am trying to implement a small example application for timeout on MsgReceivev() function with TimerTimeout(), but it doesn’t work.

Basically i want to test whether the TimerTimeout can unblock the MsgReceivev() function after a given time. The application itself has no client side, so i expect the timeout shall elapse. But unfortunatelly the MsgReceivev() function is never unblocked.

Here is my code:

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/neutrino.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>

#define TIMEOUT_1      1000         /* 1000 ns = 1 us */
#define TIMEOUT_2      1000000      /* 1000000 ns = 1 ms */
#define TIMEOUT_3      1000000000   /* 1000000000 ns = 1 s */

int main(int argc, char *argv[]) 
{
  int chid;
  struct sigevent s_event; 
  uint64_t  ll_timeout, ll_time;
  struct timespec tp;
  uint8_t ab_buf[64];
  iov_t iov;
  struct _msg_info msg_info;
  int ret;

  /* init IOV */
  SETIOV(&iov, ab_buf, sizeof(ab_buf));

  /* creating channel for message passing */
  printf("\nCreating channel for message passing...");
  chid = ChannelCreate(_NTO_CHF_UNBLOCK);
  if(chid == -1)
  {
    printf("FAILED, errno:%i", errno);
  }
  else
  {
    printf("OK, chid=%i", chid);
  }

  /* setting timeout */
  SIGEV_UNBLOCK_INIT(&s_event);
  ll_timeout = TIMEOUT_3;
  printf("\nSetting timeout...");
  if(TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_RECEIVE, 
                  &s_event, &ll_timeout, &ll_time ) == -1)
  {
    printf("FAILED, errno:%i", errno);
  }
  else
  {
    printf("OK");
  }

  if(clock_gettime(CLOCK_REALTIME, &tp) == -1)
  {
    printf("\nError getting start time, errno:%i", errno);
  }
  else
  {
    printf("\nStart time: %i.%09li", tp.tv_sec, tp.tv_nsec);
  }
  
  /* try to receive a message/pulse */
  ret = MsgReceivev(chid, &iov, 1, &msg_info);
  if(clock_gettime(CLOCK_REALTIME, &tp) == -1)
  {
    printf("\nError getting stop time, errno:%i", errno);
  }
  else
  {
    printf("\nStop  time: %i.%09li", tp.tv_sec, tp.tv_nsec);
  }
  printf("\nMsgReceivePulse returns=%i, errno=%i", ret, errno);

  return EXIT_SUCCESS;
}

Thanks in advance for any hint!

Always call time_timeout() just before the function that you wish to timeout.

In this case time_timeout works on printf(“OK”);

thanks! it works as you said

Hi all,

i have another short questions regarding QNX, while i am still beginner in the topic:

What is the common difference between the functions in capital letters and small letters, e.g.:

TimerTimeout() - timer_timeout()
SignalAction - sigaction

etc.

They seems to have same functions.

Thanks for any hint.

I think the difference that you are observing is between Posix routines and QNX native routines. In some cases they will be identical in function.

The ones in capital letters are direct kernel calls and aren’t POSIX functions. You should consider call the other the ones in small letter.