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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

ソリューションへジャンプ
793件の閲覧回数
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 解決策
572件の閲覧回数
Martin_
NXP Employee
NXP Employee

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

元の投稿で解決策を見る

0 件の賞賛
返信
1 返信
573件の閲覧回数
Martin_
NXP Employee
NXP Employee

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

0 件の賞賛
返信