I am working on serial port application on Linux , when select () api is checked for data on waiting handles it returns positive value once data arrives on port but read() api call returns -1 , how can this possible?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is what man pages say about
select:If there is an error condition on a file descriptor (RST segment received for a network sockets, for example), the only way to notify the process that is currently blocked in
selectis to make this descriptor ready for IO. The subsequent read/write function will return an error so that the application can handle it.This behavior looks compliant with what
selectpromises – flag a descriptor as ready if you can perform a non-blocking IO on it (however, there are some cases with network sockets, when a descriptor is flagged as ready for read, but the subsequent read operation blocks). You don’t block on read – an error is returned immediately.As for the return status of
select, it should only return the number of “ready events” for the file descriptors in all sets. It can be negative if select itself fails (interrupted by a system call, for example –errno == EINTR), but not when some errors on the descriptors being watched occur.