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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
732 次查看
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 项奖励
回复
1 解答
511 次查看
Martin_
NXP Employee
NXP Employee

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

在原帖中查看解决方案

0 项奖励
回复
1 回复
512 次查看
Martin_
NXP Employee
NXP Employee

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

0 项奖励
回复