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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

Jump to solution
891 Views
Novalis
Contributor III

Hello,

is it possible to use something like this:

  int count;

  char buffptr[100];

  FILE  *ser;

  ser = fopen("ttye","a+");

  while(1)

     {

        fd_set rfds;

        FD_ZERO(&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; }     

         count=read(ser->_FD,buffptr,99);

         USB_PRINTF("%d bytes\n",count);

        //DO_SOMETHING_WITH_DATA

        /* Let the other task run */

        _time_delay(1);

     }

(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 Smiley Happy

Thanks,

Martin

0 Kudos
Reply
1 Solution
670 Views
Martin_
NXP Employee
NXP Employee

select() in Freescale MQX can work only with RTCS sockets.

View solution in original post

0 Kudos
Reply
1 Reply
671 Views
Martin_
NXP Employee
NXP Employee

select() in Freescale MQX can work only with RTCS sockets.

0 Kudos
Reply