Bravely have read_blocked return after first read

In commit fd6d814ea4, read_blocked was changed to read until EOF
or the full amount requested is returned. Switch this to returning
as soon as any data is available, which was the behavior prior to
fd6d814ea4.

This will allow builtin_string to output data in a "streaming"
fashion instead of needing to read a large block up-front.
This commit is contained in:
ridiculousfish 2020-07-30 20:58:19 -07:00
parent 81d5a3ea64
commit 68092c5d21

View File

@ -474,23 +474,11 @@ void fish_setlocale() {
} }
long read_blocked(int fd, void *buf, size_t count) { long read_blocked(int fd, void *buf, size_t count) {
long bytes_read = 0; ssize_t res;
do {
while (count) { res = read(fd, buf, count);
ssize_t res = read(fd, static_cast<char *>(buf) + bytes_read, count); } while (res < 0 && errno == EINTR);
if (res == 0) { return res;
break;
} else if (res == -1) {
if (errno == EINTR) continue;
if (errno == EAGAIN) return bytes_read ? bytes_read : -1;
return -1;
} else {
bytes_read += res;
count -= res;
}
}
return bytes_read;
} }
/// Loop a write request while failure is non-critical. Return -1 and set errno in case of critical /// Loop a write request while failure is non-critical. Return -1 and set errno in case of critical