AnsweredAssumed Answered

select() on *FILE->_FD    + nonblocking read

Question asked by Martin Kozusky on Nov 20, 2015
Latest reply on Nov 20, 2015 by Martin Latal


is it possible to use something like this:


  int count;
  char buffptr[100];
  FILE  *ser;
  ser = fopen("ttye","a+");
        fd_set rfds;
        FD_SET(ser->_FD, &rfds);

         int res = select(ser->_FD+1, &rfds, NULL, NULL, 500);
         if (res == -1) { USB_PRINTF("SELECT ERROR\n "); continue; }
         if (res == 0) { USB_PRINTF("SELECT TIMEOUT"); continue; }
         if (!FD_ISSET(ser->_FD, &rfds)) { USB_PRINTF("no FD_ISSET"); continue; }      
         USB_PRINTF("%d bytes\n",count);

        /* Let the other task run */


(that I normaly use in linux) also in KSDK MQX , or is select()  intended only for RTCS sockets?


select()  in this example alway returns -1 to me, I also tried  RTCS_  versions and it didn't help.


I know I can use blocking read() with 1 byte that would block me, but this way I could also find out that there nothing coming using select timeout.


For this example I would also need nonblocking read - opening  file not using fopen(), but open() with O_NONBLOCK doesn't help here.


If it's too much trouble, I will stay with 1 byte blocking read