Skip to content

Commit

Permalink
Support pasting to non-pipe FDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Saveau committed Dec 17, 2024
1 parent 13178c5 commit 4361c8d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion wayland/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
use std::{
collections::HashMap,
fmt::{Debug, Formatter},
fs::File,
hash::BuildHasherDefault,
io,
io::ErrorKind::WouldBlock,
mem,
mem::ManuallyDrop,
ops::Deref,
os::fd::{AsFd, OwnedFd},
os::fd::{AsFd, AsRawFd, FromRawFd, OwnedFd},
ptr,
rc::Rc,
};
Expand Down Expand Up @@ -929,6 +931,19 @@ impl OutgoingTransfers {
Err(Errno::AGAIN) => {
return Ok(false);
}
Err(Errno::INVAL) => {
let bytes = io::copy(
&mut *ManuallyDrop::new(unsafe {
File::from_raw_fd(data.as_fd().as_raw_fd())
}),
&mut *ManuallyDrop::new(unsafe {
File::from_raw_fd(write.as_fd().as_raw_fd())
}),
)
.map_io_err(|| "Fallback paste into peer failed.")?;
debug!("Fallback finished sending {bytes} bytes.");
return Ok(true);
}
r => {
let count =
r.map_io_err(|| "Failed to splice data from data file into peer.")?;
Expand Down

0 comments on commit 4361c8d

Please sign in to comment.