select() with timeout on stdin not working

Discussion to talk about software related topics only.
Post Reply
dnishimura
Posts: 19
Joined: Fri Dec 19, 2014 3:07 pm

select() with timeout on stdin not working

Post by dnishimura »

Code: Select all

int readfds;
fd_set fds;
int stdin_fileno = fileno(stdin);
FD_ZERO(&fds);
FD_SET(stdin_fileno, &fds);
iprintf("Press any key to enter configuration.\r\n");
readfds = select(stdin_fileno + 1, &fds, NULL, NULL, TICKS_PER_SECOND * 5);
iprintf("STDIN: %d, READ_FDS: %d, FD_ISSET: %d\r\n", stdin_fileno, readfds, FD_ISSET(stdin_fileno, &fds));
Above prints out "STDIN: 0, READ_FDS: 0, FD_ISSET: 0", so it appears select() doesn't work on stdin. However, fgets works fine on stdin:

Code: Select all

fgets(buf, sizeof(buf), stdin);
Am I missing something?
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: select() with timeout on stdin not working

Post by rnixon »

As a test I would try closing stdin, then re-opening with OpenSerial() (going from memory on the function name), getting the returned file descriptor, and then using that fd in your select function.
User avatar
pbreed
Posts: 1088
Joined: Thu Apr 24, 2008 3:58 pm

Re: select() with timeout on stdin not working

Post by pbreed »

Unless you change it stdio opens in polled mode.
(This is a very old choice I wish I could undo)

To fix this and have it work the way you want ...

#include <iosys.h>
then
void IrqStdio();

Paul
Post Reply