On page 34 of the book "Linux System Programming" the following example of correctly handling partial reads with a while loop for blocking reads is given
ssize_t ret;
while (len != 0 && (ret = read(fd, buf, len)) != 0) {
if (ret == -1) {
if (errno == EINTR)
continue;
perror("read");
break;
}
len -= ret;
buf += ret;
}
On the next page it gives the following example for nonblocking reads. Does this example need to be wrapped in a while loop to handle the possibility of partial reads?
char buf[BUFSIZ];
ssize_t nr;
start:
nr = read(fd, buf, BUFSIZ);
if (nr == -1) {
if (errno == EINTR)
goto start; /* oh shush */
if (erron == EAGAIN)
/* resubmit later */
else
/* error */
}