Unix Programming - Re: A question about read() from "Unix Network Programming", Vol

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2008 > Re: A question about read() from "Unix Network Programming", Vol





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: A question about read() from "Unix Network Programming", Vol
Syren Baran

2008-01-04, 7:38 am

William Pursell schrieb:
> If the function is intended to always "return the number of
> bytes read", then it should return 0 if an error
> occurs on the first read. However, that is not the
> intended behavior, nor is it the behavior of the read(2)
> system call. From the read man page:
>
> On success, the number of bytes read is returned (zero indicates end
> of file)...
> On error, -1 is returned
>
> Steven's function returns the number of bytes read if there
> is no error. It returns -1 if there is an error, regardless
> of the number of bytes that were read. That is correct
> behavior.


Unluckily only partially true. The return values may be the same for
both functions, yet there is a subtle difference. If bytes were read and
a further call to read returns an error you would have to insert a
statement such as "fseek(fd,nleft-n,SEEK_CUR);" in line 15.
Provoking such an error should be easy, by setting fd into nonblocking
mode checking what happens when EAGAIN arrives.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com