From 2aa605a5276f5aa365cae5e08aa6ce76951e9a1d Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 7 Mar 2024 13:33:57 +0400 Subject: [PATCH] Clear O_NONBLOCK Fixes 7e4f56d11, apparently io::copy() can't deal with nonblocking fds. --- src/copy.rs | 6 ++++++ src/tests/copy.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/copy.rs b/src/copy.rs index 72a543d6a9..1fd6f9c68d 100644 --- a/src/copy.rs +++ b/src/copy.rs @@ -10,6 +10,7 @@ use std::sync::mpsc::sync_channel; use std::{iter, thread}; use log::trace; +use rustix::fs::{fcntl_setfl, OFlags}; use wayland_client::globals::GlobalListContents; use wayland_client::protocol::wl_registry::WlRegistry; use wayland_client::protocol::wl_seat::WlSeat; @@ -350,6 +351,11 @@ impl Dispatch for State { let file = File::open(data_path).map_err(DataSourceError::FileOpen); let result = file.and_then(|mut data_file| { + // Clear O_NONBLOCK, otherwise io::copy() will stop halfway. + fcntl_setfl(&fd, OFlags::empty()) + .map_err(io::Error::from) + .map_err(DataSourceError::Copy)?; + let mut target_file = File::from(fd); io::copy(&mut data_file, &mut target_file).map_err(DataSourceError::Copy) }); diff --git a/src/tests/copy.rs b/src/tests/copy.rs index 3678fd5fc8..c801e79fae 100644 --- a/src/tests/copy.rs +++ b/src/tests/copy.rs @@ -278,7 +278,7 @@ fn copy_multi_no_additional_text_mime_types_test() { fn copy_large() { // Assuming the default pipe capacity is 65536. let mut bytes_to_copy = vec![]; - for i in 0..70000 { + for i in 0..65536 * 10 { bytes_to_copy.push((i % 256) as u8); }