In read_all()/write_all(), continue upon EINTR.

This commit is contained in:
Rafal Wojtczuk 2011-03-16 12:58:40 +01:00
parent a195f436b7
commit 777eaa2168

View File

@ -31,6 +31,8 @@ int write_all(int fd, void *buf, int size)
int ret; int ret;
while (written < size) { while (written < size) {
ret = write(fd, (char *) buf + written, size - written); ret = write(fd, (char *) buf + written, size - written);
if (ret == -1 && errno == EINTR)
continue;
if (ret <= 0) { if (ret <= 0) {
perror("write"); perror("write");
return 0; return 0;
@ -47,6 +49,8 @@ int read_all(int fd, void *buf, int size)
int ret; int ret;
while (got_read < size) { while (got_read < size) {
ret = read(fd, (char *) buf + got_read, size - got_read); ret = read(fd, (char *) buf + got_read, size - got_read);
if (ret == -1 && errno == EINTR)
continue;
if (ret == 0) { if (ret == 0) {
errno = 0; errno = 0;
fprintf(stderr, "EOF\n"); fprintf(stderr, "EOF\n");
@ -68,6 +72,8 @@ int copy_fd_all(int fdout, int fdin)
char buf[4096]; char buf[4096];
for (;;) { for (;;) {
ret = read(fdin, buf, sizeof(buf)); ret = read(fdin, buf, sizeof(buf));
if (ret == -1 && errno == EINTR)
continue;
if (!ret) if (!ret)
break; break;
if (ret < 0) { if (ret < 0) {
@ -81,4 +87,3 @@ int copy_fd_all(int fdout, int fdin)
} }
return 1; return 1;
} }