Regarding EAGAIN error in read()

M

Madhu

Hi,

I need to trap EAGAIN error while using read().

I read in some website that read() has to wait till write() is
completed for EAGAIN to occur. But read() doesnt seem to wait, it reads
whatever it can and stores it in the buffer and sets the rest of the
buffer to NULL.

Thanks,
Madhukar
 
W

Walter Roberson

Madhu said:
I need to trap EAGAIN error while using read().

Try asking in comp.unix.programmer . The C language itself does not
have read() or EAGAIN: they are extensions beyond the standard.

I read in some website that read() has to wait till write() is
completed for EAGAIN to occur.

Don't trust that website.
But read() doesnt seem to wait, it reads
whatever it can and stores it in the buffer and sets the rest of the
buffer to NULL.

Don't trust that test.
 
P

Papastefanos Serafeim

I've never heard of the behaviour you mention.
The standard behavior for read is to read anything
available in the stream and return.

If there is no data available, then if read is reading
from a blocking descriptor it will block. If read is
reading from a non blocking descriptor then it will
return with an EAGAIN or EWOULDBLOCK
error.

Also, read and write are not in standard C, so
maybe in another newsgroup you'll get a better
answer than mine.

Papastefanos Serafeim
 
K

Keith Thompson

Papastefanos Serafeim said:
I've never heard of the behaviour you mention.
The standard behavior for read is to read anything
available in the stream and return.

If there is no data available, then if read is reading
from a blocking descriptor it will block. If read is
reading from a non blocking descriptor then it will
return with an EAGAIN or EWOULDBLOCK
error.

Also, read and write are not in standard C, so
maybe in another newsgroup you'll get a better
answer than mine.

Please don't top-post. See <http://www.caliburn.nl/topposting.html>.

Please don't offer detailed answers to off-topic questions. The
experts on this stuff hang out in comp.unix.programmer. If you make a
mistake in your answer here (we all make mistakes), we're not going to
be able to correct it If we do, it will likely lead to a lengthy
off-topic discussion that should have been in comp.unix.programmer in
the first place.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top