Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
BroadcastCommunity.qnx.com will be offline from May 31 6:00pm until June 2 12:00AM for upcoming system upgrades. For more information please go to https://community.qnx.com/sf/discussion/do/listPosts/projects.bazaar/discussion.bazaar.topc28418
Forum Topic - select() vs ionotify(): Page 1 of 8 (8 Items)
   
select() vs ionotify()  
I've got one resource manager that gathers data and supports ionotify so clients can wait on data to arrive and then 
grab it.  I'd like to have another resource manager consume these data and process them further.  For this it seems that
 I should use ionotify() over select(), as ionotify can deliver pulses to my second resource manager.  This all makes 
sense, but while the following example using select() works, the ionotify() version doesn't receive messages.  I'm sure 
I'm doing something silly, but if someone could point me in the right direction for using ionotify(), I'd greatly 
appreciate it!

/////// select version: works
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/select.h>

int main( void )
{
  int fd;
  char buf[128];
  fd_set rfd;
  
  fd = open("/dev/pioint", O_RDONLY);
  if (fd < 0) {
    perror("open");
    return 1;
  }

  /*
   * Clear the set of read file descriptors, and * add the two we just got from the open calls. 
   */
  FD_ZERO( &rfd );
  FD_SET( fd, &rfd );

  for (;;) {
    select( 1+fd, &rfd, 0, 0, NULL);
    if( FD_ISSET( fd, &rfd ) ) {
      read(fd, buf, sizeof(buf));
      printf(buf);
    }
  }
  return 0;
}

/////// ionotify version: doesn't receive any even message

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/iomsg.h>
#include <sys/neutrino.h>

int main()
{
  int chid, coid;
  struct sigevent event;
  char buf[128];
  char msg[32];
  int r, rcvid;

  int fd = open("/dev/pioint", O_RDONLY);
  if (fd < 0) {
    perror("open");
    return 1;
  }
  chid = ChannelCreate(0);
  coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0);
  SIGEV_PULSE_INIT(&event, coid, 0,  SI_NOTIFY, 0);

  for (;;) {
    r = ionotify(fd, _NOTIFY_ACTION_POLLARM, _NOTIFY_COND_INPUT, &event);
    rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);
    if (!rcvid) {
      read(r, &buf, 128);
      printf(buf);
    }
  }
  
  return 0;
}