select() or IRQ?

Hi I have this question:

I have to read from serial port one byte at time, but I can’t spend CPU time in waiting . What is the difference about using the function select() instead of InterruptWait()?

I first decided to use interrupts, but I have some doubts about portability of code because I don’t think that serial ports always have the same IRQs.
Thanks

Don’t use interrupts. Use either select() or readcond() - both will give you a blocking method with timeouts. readcond() is slightly more efficient, but less portable.

Thanks,

I have tried select() because readcond() seems to be the same as using read() with tcsetattr() to set the timeout.

I have found that select() only works if you set a timeout greater than 1 second, otherwise it always return that a timeout occurred (but I am sure that with my application that is wrong).

Moreover I found that the computation time of other application is more or less the same if I use select() or simply read(), so I am not sure that select() is useful for saving CPU time, at least with the serial port.

Have you some other hint?
Thanks, Enrico

The difference between select() and handling the interrupt yourself it very negligeble. If you are looking at that choice because you suspect your program is using too much CPU and isn’t leaving enough for other processes, I suggess you look somewhere else. Handling serial data via select usually result in insignificant usage of CPU.

I think you are looking at the problem from the wrong end.

Do you want your program “blocked” and “wait” ? I thought you wanted select() timeout.

Any way, if you want select() block until there is data, you should pass NULL as the timeout pointer.

As for select() and read(), they are (in your case) the same except select() can do multiple fds at a time, where read() can only block on one fd.