Skip to content

Commit

Permalink
Clear O_NONBLOCK
Browse files Browse the repository at this point in the history
Fixes 7e4f56d, apparently io::copy() can't deal with nonblocking fds.
  • Loading branch information
YaLTeR committed Mar 7, 2024
1 parent e81562a commit 2aa605a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -350,6 +351,11 @@ impl Dispatch<ZwlrDataControlSourceV1, ()> 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)
});
Expand Down
2 changes: 1 addition & 1 deletion src/tests/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 2aa605a

Please sign in to comment.