mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 03:54:04 +08:00
Bravely have read_blocked return after first read
In commitfd6d814ea4
, 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 tofd6d814ea4
. 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:
parent
81d5a3ea64
commit
68092c5d21
|
@ -474,23 +474,11 @@ void fish_setlocale() {
|
|||
}
|
||||
|
||||
long read_blocked(int fd, void *buf, size_t count) {
|
||||
long bytes_read = 0;
|
||||
|
||||
while (count) {
|
||||
ssize_t res = read(fd, static_cast<char *>(buf) + bytes_read, count);
|
||||
if (res == 0) {
|
||||
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;
|
||||
ssize_t res;
|
||||
do {
|
||||
res = read(fd, buf, count);
|
||||
} while (res < 0 && errno == EINTR);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Loop a write request while failure is non-critical. Return -1 and set errno in case of critical
|
||||
|
|
Loading…
Reference in New Issue
Block a user