dnd.c: use non-blocking I/O in drop_send_file_chunks()

Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/472b29a5-22c7-4f25-9541-9c9fafa78518

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-02 06:13:23 +00:00
committed by GitHub
parent 5cb0df0305
commit e948f64dbf
2 changed files with 8 additions and 1 deletions

View File

@@ -217,6 +217,8 @@ Detailed list of changes
- Password input in kittens: hide the cursor and display 🔒 (U+1F512) at the end of typed characters to make it visually clear the user is entering a password
- DnD: Use non-blocking I/O when reading file chunks in ``drop_send_file_chunks()`` to avoid blocking the main event loop
0.46.2 [2026-03-21]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -552,6 +552,11 @@ drop_send_file_chunks(Window *w) {
ssize_t n;
do { n = read(w->drop.file_fd_plus_one - 1, buf, sizeof(buf)); } while (n < 0 && errno == EINTR);
if (n < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
/* No data available right now; retry via timer */
w->drop.file_send_timer = add_main_loop_timer(ms_to_monotonic_t(20), false, file_send_timer_callback, (void*)(uintptr_t)w->id, NULL);
return;
}
drop_close_file_fd(w);
drop_send_error(w, EIO);
return;
@@ -583,7 +588,7 @@ drop_send_file_chunks(Window *w) {
static void
drop_send_file_data(Window *w, const char *path) {
drop_close_file_fd(w);
int fd = safe_open(path, O_RDONLY | O_CLOEXEC, 0);
int fd = safe_open(path, O_RDONLY | O_CLOEXEC | O_NONBLOCK, 0);
if (fd < 0) {
switch (errno) {
case ENOENT: case ENOTDIR: drop_send_error(w, ENOENT); break;