Run EventManager whenever writing to a file descriptor would block

This approach is not very elegant as it hooks into the event manager
deep inside the call graph, but solves the exiting issue and is an
okay stop gap solution until a better design comes up.

Fixes #4605
This commit is contained in:
Maxime Coste 2022-05-10 22:33:52 +10:00
parent 3882b0e21b
commit ae001a1f91
3 changed files with 19 additions and 5 deletions

View File

@ -5,6 +5,7 @@
#include "exception.hh" #include "exception.hh"
#include "flags.hh" #include "flags.hh"
#include "option_types.hh" #include "option_types.hh"
#include "event_manager.hh"
#include "ranked_match.hh" #include "ranked_match.hh"
#include "regex.hh" #include "regex.hh"
#include "string.hh" #include "string.hh"
@ -256,13 +257,20 @@ void write(int fd, StringView data)
const char* ptr = data.data(); const char* ptr = data.data();
ssize_t count = (int)data.length(); ssize_t count = (int)data.length();
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
auto restore_flags = on_scope_end([&] { fcntl(fd, F_SETFL, flags); });
while (count) while (count)
{ {
ssize_t written = ::write(fd, ptr, count); if (ssize_t written = ::write(fd, ptr, count); written != -1)
{
ptr += written; ptr += written;
count -= written; count -= written;
}
if (written == -1) else if (errno == EAGAIN and EventManager::has_instance())
EventManager::instance().handle_next_events(EventMode::Urgent, nullptr, false);
else
throw file_access_error(format("fd: {}", fd), strerror(errno)); throw file_access_error(format("fd: {}", fd), strerror(errno));
} }
} }

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,5 @@
exec 5000oabcdefghi<esc>%yppppp
nop %sh{
echo "write $kak_response_fifo" > "$kak_command_fifo"
strace -o /tmp/strace.log cat "$kak_response_fifo"
}