From 4361c8dbf0bc98b5085713a45bb87cbcedf82fc2 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Tue, 17 Dec 2024 13:32:01 -0500 Subject: [PATCH] Support pasting to non-pipe FDs --- wayland/src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/wayland/src/main.rs b/wayland/src/main.rs index 9d9ebe4..cc089d7 100644 --- a/wayland/src/main.rs +++ b/wayland/src/main.rs @@ -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, }; @@ -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.")?;