Merge remote-tracking branch 'krobelus/fix-crash-connecting-monitor'

This commit is contained in:
Maxime Coste 2023-05-10 20:03:22 +10:00
commit 3d989af2de
5 changed files with 16 additions and 6 deletions

2
.gitignore vendored
View File

@ -5,7 +5,9 @@
.*.kak.* .*.kak.*
src/kak src/kak
src/kak.debug src/kak.debug
src/kak.debug.san_*
src/kak.opt src/kak.opt
src/kak.opt.san_*
src/.version* src/.version*
src/.*.json src/.*.json
doc/kak.1.gz doc/kak.1.gz

View File

@ -252,13 +252,14 @@ bool regular_file_exists(StringView filename)
(st.st_mode & S_IFMT) == S_IFREG; (st.st_mode & S_IFMT) == S_IFREG;
} }
template<bool atomic>
void write(int fd, StringView data) 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); int flags = fcntl(fd, F_GETFL, 0);
if (EventManager::has_instance()) if (not atomic and EventManager::has_instance())
fcntl(fd, F_SETFL, flags | O_NONBLOCK); fcntl(fd, F_SETFL, flags | O_NONBLOCK);
auto restore_flags = on_scope_end([&] { fcntl(fd, F_SETFL, flags); }); auto restore_flags = on_scope_end([&] { fcntl(fd, F_SETFL, flags); });
@ -269,12 +270,15 @@ void write(int fd, StringView data)
ptr += written; ptr += written;
count -= written; count -= written;
} }
else if (errno == EAGAIN and EventManager::has_instance()) 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, false);
else else
throw file_access_error(format("fd: {}", fd), strerror(errno)); throw file_access_error(format("fd: {}", fd), strerror(errno));
} }
} }
template void write<true>(int fd, StringView data);
template void write<false>(int fd, StringView data);
void write_to_file(StringView filename, StringView data) void write_to_file(StringView filename, StringView data)
{ {
@ -295,7 +299,7 @@ void write_buffer_to_fd(Buffer& buffer, int fd)
eoldata = "\n"; eoldata = "\n";
BufferedWriter writer{fd}; BufferedWriter<false> writer{fd};
if (buffer.options()["BOM"].get<ByteOrderMark>() == ByteOrderMark::Utf8) if (buffer.options()["BOM"].get<ByteOrderMark>() == ByteOrderMark::Utf8)
writer.write("\xEF\xBB\xBF"); writer.write("\xEF\xBB\xBF");

View File

@ -39,6 +39,7 @@ bool fd_readable(int fd);
bool fd_writable(int fd); bool fd_writable(int fd);
String read_fd(int fd, bool text = false); String read_fd(int fd, bool text = false);
String read_file(StringView filename, bool text = false); String read_file(StringView filename, bool text = false);
template<bool force_blocking = false>
void write(int fd, StringView data); void write(int fd, StringView data);
void write_to_file(StringView filename, StringView data); void write_to_file(StringView filename, StringView data);
@ -121,7 +122,7 @@ CandidateList complete_filename(StringView prefix, const Regex& ignore_regex,
CandidateList complete_command(StringView prefix, ByteCount cursor_pos = -1); CandidateList complete_command(StringView prefix, ByteCount cursor_pos = -1);
template<int buffer_size = 4096> template<bool atomic, int buffer_size = 4096>
struct BufferedWriter struct BufferedWriter
{ {
BufferedWriter(int fd) BufferedWriter(int fd)
@ -149,7 +150,7 @@ struct BufferedWriter
void flush() void flush()
{ {
Kakoune::write(m_fd, {m_buffer, m_pos}); Kakoune::write<atomic>(m_fd, {m_buffer, m_pos});
m_pos = 0; m_pos = 0;
} }

View File

@ -208,7 +208,7 @@ void TerminalUI::Window::draw(DisplayCoord pos,
lines[(int)pos.line].append({}, size.column - pos.column, default_face); lines[(int)pos.line].append({}, size.column - pos.column, default_face);
} }
struct Writer : BufferedWriter<> struct Writer : BufferedWriter<true>
{ {
using Writer::BufferedWriter::BufferedWriter; using Writer::BufferedWriter::BufferedWriter;
~Writer() noexcept(false) = default; ~Writer() noexcept(false) = default;

View File

@ -10,3 +10,6 @@ ui_in '{ "jsonrpc": "2.0", "method": "mouse_release", "params": [ "left", 0, 4 ]
sleep .1 sleep .1
ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "c<esc>" ] }' ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "c<esc>" ] }'
sleep .1 sleep .1
if [ -n "$CI" ]; then
sleep 1
fi