select woes

I am trying to select on a number of devices for reading. Most are
serial ports but I also want to include keyboard so I add zero to both
the read and error sets. I am getting an immediate return from select
with the error “No error” on fd zero.

Is select not supported for stdin from keyboard? Or is there something
else I should be doing?

Dean Douthat <ddouthat@faac.com> wrote:

I am trying to select on a number of devices for reading. Most are
serial ports but I also want to include keyboard so I add zero to both
the read and error sets. I am getting an immediate return from select
with the error “No error” on fd zero.

And is fd zero set for read in the bit field?

Is select not supported for stdin from keyboard? Or is there something
else I should be doing?

I think that you generally need a device to be in raw mode to be able
to select() on it. Terminal devices (like the console) don’t usually
default to this, so you may have to play with the tcsetattr() function
to change the mode of the terminal. If doing this, and your program
may exit, you will probably want to get the current state, save it
away, set you new state, then restore the original state on exit.

-David

QNX Training Services
dagibbs@qnx.com

Hi David:

David Gibbs wrote:

Dean Douthat <> ddouthat@faac.com> > wrote:
I am trying to select on a number of devices for reading. Most are
serial ports but I also want to include keyboard so I add zero to both
the read and error sets. I am getting an immediate return from select
with the error “No error” on fd zero.

And is fd zero set for read in the bit field?

Yes, I had fd zero set for both read bit field and error bit field. I used
dev_mode to set fd 0 to raw. I have concluded that stdin being from a
pseudo-tty doesn’t handle the error bit field in select. My understanding of
the error bit field is somewhat vague but I’m beginning to think it’s for
“extra” errors such as parity or framing on a serial port, not for “ordinary”
read errors. Anyway, I just dropped fd 0 out of the error bit field and it
seems to work. I think I want to keep any fd associated with a serial port
in the error bit field. Does this sound right?

Is select not supported for stdin from keyboard? Or is there something
else I should be doing?

I think that you generally need a device to be in raw mode to be able
to select() on it. Terminal devices (like the console) don’t usually
default to this, so you may have to play with the tcsetattr() function
to change the mode of the terminal. If doing this, and your program
may exit, you will probably want to get the current state, save it
away, set you new state, then restore the original state on exit.

-David

QNX Training Services
dagibbs@qnx.com

Dean Douthat <ddouthat@faac.com> wrote:

Hi David:

David Gibbs wrote:

Dean Douthat <> ddouthat@faac.com> > wrote:
I am trying to select on a number of devices for reading. Most are
serial ports but I also want to include keyboard so I add zero to both
the read and error sets. I am getting an immediate return from select
with the error “No error” on fd zero.

And is fd zero set for read in the bit field?

Yes, I had fd zero set for both read bit field and error bit field. I used
dev_mode to set fd 0 to raw. I have concluded that stdin being from a
pseudo-tty doesn’t handle the error bit field in select. My understanding of
the error bit field is somewhat vague but I’m beginning to think it’s for
“extra” errors such as parity or framing on a serial port, not for “ordinary”
read errors. Anyway, I just dropped fd 0 out of the error bit field and it
seems to work. I think I want to keep any fd associated with a serial port
in the error bit field. Does this sound right?

The only place I think I’ve actually seen something that signal an
exception condition for a file descriptor documented is for TCP/IP
sockets. Serial ports might as well, but I don’t know for sure.

-David

QNX Training Services
dagibbs@qnx.com