Re: Handling read() errors



Krivenok Dmitry <krivenok.dmitry@xxxxxxxxx> wrote:
Suppose read() system call returns -1.
There are many causes of the error.

I exactly know that if errno = EINTR, then I can safety restart
system call as follows:
while( (rc = read(sock, buf, count)) == -1 and errno == EINTR)
{
// Do nothing.
}

Are there another cases when I can safety restart read()?
If so, what errno values correspond to these cases?

If you have opened the file in non-blocking mode you may
get EAGAIN or EWOULDBLOCK if there were no data to be read.
This is probably the second "normal" case where calling
read() again makes sense. If there are others depends on
the what kind of object you're reading from - if you're
reading from a socket and you get ETIMEDOUT because the
transmission timed out there might be some reasons to call
read() again. And if your system is struggling because it
doesn't have enough memory you may get ENOBUFS or ENOMEM.
In that case you also might decide to try your luck again,
perhaps after a short pause to give the system time re-
claim enough memory.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.



Relevant Pages

  • Re: How hard is socket programming?
    ... I believe the first one is very good "easy reading" ... Non-Uniform Memory Access (NUMA) ... New NUMA Support with Windows Server 2008 R2 and Windows 7 ... 100% CPU usage. ...
    (microsoft.public.vc.mfc)
  • Re: Programming in standard c
    ... I consider having the text file size used for reading the file into ... memory to be used insufficiently often to make it worth caching it. ... size may suck significantly more than getting the binary-mode size ... NOT precalculate the size) and reallocing when needed ...
    (comp.lang.c)
  • Re: Large text file - in memory ( > 60mb)
    ... The file is over 64mb in size, reading it line by line to do a search ... while running the app, it would mean reading/searching the>64mb file many ... Then I have to show this record found (wich ... maybe creating a datatable to ease the search but I'm pretty sure memory ...
    (microsoft.public.dotnet.framework)
  • Re: Off Topic: Memory
    ... Given that my memory is something of a concern to me, ... I've only just started reading it but it addresses the causes ... - the rather haphazard way our brains are built, sort of like kludged ... P.S. haven't tried the test yet - keep forgetting ...
    (rec.music.makers.guitar.acoustic)
  • Re: Noise Level of the PowerMac G5
    ... Or is it just a little bit more memory slots, ... If you are spending most of your time reading, thinking and editing ... I may have 10 to 15 apps open at once and switching between them a lot, ...
    (comp.sys.mac.misc)