Page 1 of 1
select() with timeout on stdin not working
Posted: Wed Jul 08, 2015 1:06 pm
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:
Am I missing something?
Re: select() with timeout on stdin not working
Posted: Wed Jul 08, 2015 4:11 pm
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.
Re: select() with timeout on stdin not working
Posted: Thu Jul 09, 2015 3:08 pm
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