summaryrefslogtreecommitdiff
path: root/src/shell_manager.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2016-12-03 12:41:36 +0000
committerMaxime Coste <mawww@kakoune.org>2016-12-03 12:41:36 +0000
commit8a74ef980492f4d85d96215f05dffe608d0815c0 (patch)
tree728309e1da0957d85cee52c470008997897fdb68 /src/shell_manager.cc
parent75986911f88b78b54811db6a19f8009c6f9c41a3 (diff)
Read as much as possible data from shell processes on each read event
We were reading at most 1024 bytes every time, going back to the event loop.
Diffstat (limited to 'src/shell_manager.cc')
-rw-r--r--src/shell_manager.cc17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 25cc2be6..2428709a 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -161,14 +161,17 @@ std::pair<String, int> ShellManager::eval(
: FDWatcher(pipe.read_fd(), FdEvents::Read,
[&contents, &pipe](FDWatcher& watcher, FdEvents, EventMode) {
char buffer[1024];
- size_t size = ::read(pipe.read_fd(), buffer, 1024);
- if (size <= 0)
+ while (fd_readable(pipe.read_fd()))
{
- pipe.close_read_fd();
- watcher.disable();
- return;
+ size_t size = ::read(pipe.read_fd(), buffer, 1024);
+ if (size <= 0)
+ {
+ pipe.close_read_fd();
+ watcher.disable();
+ return;
+ }
+ contents += StringView{buffer, buffer+size};
}
- contents += StringView{buffer, buffer+size};
})
{}
};
@@ -227,7 +230,7 @@ std::pair<String, int> ShellManager::eval(
if (wait_notified) // clear the status line
context.print_status({ "", get_face("Information") }, true);
- return { stdout_contents, WIFEXITED(status) ? WEXITSTATUS(status) : -1 };
+ return { std::move(stdout_contents), WIFEXITED(status) ? WEXITSTATUS(status) : -1 };
}
void ShellManager::register_env_var(StringView str, bool prefix,