Main Page | Report this Page
Linux Forum Index  »  Linux Development - Applications  »  EIO on read after select returns data is available...
Page 1 of 1    

EIO on read after select returns data is available...

Author Message
Sven Boden...
Posted: Thu Oct 22, 2009 11:19 am
Guest
Anyone has any ideas on the following:

My application reads from a tty using a combination of select() and
read() in a loop. I reset the file read mask before the select call.
The first time an echo "test" is executed on the tty everything runs
as I expect: the select nicely waits until timeout or until data is
available.
However with a second echo the select() returns immediately indicating
data is available, and a read() returns an EIO error (so no data is
really available although select() indicates there was).

Anyone has experience with this kind of behaviour on Linux? The same
application runs perfectly on other Unix systems.

Regards,
Sven
 
David Schwartz...
Posted: Thu Oct 22, 2009 12:34 pm
Guest
On Oct 22, 2:19 pm, Sven Boden <boden.s... at (no spam) gmail.com> wrote:

Quote:
However with a second echo the select() returns immediately indicating
data is available, and a read() returns an EIO error (so no data is
really available although select() indicates there was).

You are misunderstanding what 'select' is telling you. A select hit
for read doesn't mean that data is available, it simply means that it
is no longer possible to wait for data to be available.

Quote:
Anyone has experience with this kind of behaviour on Linux? The same
application runs perfectly on other Unix systems.

Handle the error.

DS
 
Joe Pfeiffer...
Posted: Thu Oct 22, 2009 5:12 pm
Guest
Sven Boden <boden.sven at (no spam) gmail.com> writes:

Quote:
Anyone has any ideas on the following:

My application reads from a tty using a combination of select() and
read() in a loop. I reset the file read mask before the select call.
The first time an echo "test" is executed on the tty everything runs
as I expect: the select nicely waits until timeout or until data is
available.
However with a second echo the select() returns immediately indicating
data is available, and a read() returns an EIO error (so no data is
really available although select() indicates there was).

One subtle point is that select() doesn't actually tell you data is
available, it tells you a read() won't block -- and notice that calling
read() when at EOF will return 0 bytes, and of course it also won't
block if it would return an error.

The way you phrase your question brings up a question in my mind: when
you say it returns EIO, do you mean it returns -1 and errno is set to
EIO? If it isn't returning -1 then errno is meaningless.

Quote:
Anyone has experience with this kind of behaviour on Linux? The same
application runs perfectly on other Unix systems.

Take a look at the termios man page, and especially noncanonical mode
input.
--
As we enjoy great advantages from the inventions of others, we should
be glad of an opportunity to serve others by any invention of ours;
and this we should do freely and generously. (Benjamin Franklin)
 
Sven Boden...
Posted: Thu Oct 22, 2009 8:51 pm
Guest
On Oct 23, 1:12 am, Joe Pfeiffer <pfeif... at (no spam) cs.nmsu.edu> wrote:
Quote:
Sven Boden <boden.s... at (no spam) gmail.com> writes:
Anyone has any ideas on the following:

My application reads from attyusing a combination of select() and
read() in a loop. Iresetthe filereadmask before the select call.
The first time an echo "test" is executed on thettyeverything runs
as I expect: the select nicely waits until timeout or until data is
available.
However with a second echo the select() returns immediately indicating
data is available, and aread() returns anEIOerror (so no data is
really available although select() indicates there was).

One subtle point is that select() doesn't actually tell you data is
available, it tells you aread() won't block -- and notice that callingread() when at EOF will return 0 bytes, and of course it also won't
block if it would return an error.

The way you phrase your question brings up a question in my mind:  when
you say it returnsEIO, do you mean it returns -1 and errno is set toEIO?  If it isn't returning -1 then errno is meaningless.

read returns -1 and sets errno to EIO (5). Strange thing is that the
select() after the second time never sleeps anymore... when no data is
available the read will return -1/set errno... however if later on new
data is available on the tty it will be read properly (for those reads
you get the actual data) after which read will return to -1.

My own hunch is that the EIO is an EOF, and that you have to reset the
tty somehow on linux to get back to a proper state.
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Mon Nov 30, 2009 1:01 am