summaryrefslogtreecommitdiff
path: root/src/file.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-11-22 13:47:08 +1100
committerMaxime Coste <mawww@kakoune.org>2024-11-22 13:51:09 +1100
commit9358c62bf2c26f5604ddffb7b41d55ff89a9e51f (patch)
tree5dc1ecf8e149749f3cac71dc8c599cb155795b14 /src/file.cc
parente74a3ac6a3bad1b74af71aa0bfdacb41ffcb7355 (diff)
Take a timeout argument in EventManager::handle_next_events
When provided, this gives the maximal time to wait before exiting handle_next_events. If not given handle_next_events will block, this provides a more flexible approach than the previous "block" boolean. Use this to wait for a millisecond between each try to open a fifo for writing. Fixes the 100% cpu usage discussed in github on commit e74a3ac6a3bad1b74af71aa0bfdacb41ffcb7355
Diffstat (limited to 'src/file.cc')
-rw-r--r--src/file.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/file.cc b/src/file.cc
index f75b0685..262caa09 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -269,7 +269,7 @@ void write(int fd, StringView data)
count -= written;
}
else if (errno == EAGAIN and not atomic and EventManager::has_instance())
- EventManager::instance().handle_next_events(EventMode::Urgent, nullptr, false);
+ EventManager::instance().handle_next_events(EventMode::Urgent, nullptr, std::chrono::nanoseconds{});
else
throw file_access_error(format("fd: {}", fd), strerror(errno));
}
@@ -285,7 +285,7 @@ void write_to_file(StringView filename, StringView data)
while ((fd = open(filename.zstr(), flags, 0644)) == -1)
{
if (errno == ENXIO and EventManager::has_instance()) // trying to open a FIFO with no readers yet
- EventManager::instance().handle_next_events(EventMode::Urgent, nullptr, false);
+ EventManager::instance().handle_next_events(EventMode::Urgent, nullptr, std::chrono::nanoseconds{1'000'000});
else
throw file_access_error(filename, strerror(errno));
}