read_all: return 0 when EOF occurs after 0 bytes
Originally it would return -1 (without setting errno) if the fd was already at EOF when you called read_all. This is already fixed in sendfile_all. Reviewed-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
This commit is contained in:
parent
7951164c1f
commit
418eb09482
|
@ -67,13 +67,15 @@ static inline ssize_t read_all(int fd, char *buf, size_t count)
|
||||||
memset(buf, 0, count);
|
memset(buf, 0, count);
|
||||||
while (count > 0) {
|
while (count > 0) {
|
||||||
ret = read(fd, buf, count);
|
ret = read(fd, buf, count);
|
||||||
if (ret <= 0) {
|
if (ret < 0) {
|
||||||
if (ret < 0 && (errno == EAGAIN || errno == EINTR) && (tries++ < 5)) {
|
if ((errno == EAGAIN || errno == EINTR) && (tries++ < 5)) {
|
||||||
xusleep(250000);
|
xusleep(250000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return c ? c : -1;
|
return c ? c : -1;
|
||||||
}
|
}
|
||||||
|
if (ret == 0)
|
||||||
|
return c;
|
||||||
tries = 0;
|
tries = 0;
|
||||||
count -= ret;
|
count -= ret;
|
||||||
buf += ret;
|
buf += ret;
|
||||||
|
|
Loading…
Reference in New Issue