Skip to content

Commit de54253

Browse files
MaxVerevkinbeeender
authored andcommitted
Wayland: use std::io::copy
1 parent dea81e0 commit de54253

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/clipboard/wayland.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ use super::PasteConfig;
44
use super::mime_type::decide_mime_type;
55
use crate::protocol::SourceData;
66
use anyhow::{Context, Error, Result};
7-
use nix::unistd::{pipe, read};
7+
use nix::unistd::pipe;
88
use std::collections::HashMap;
99
use std::ffi::CString;
1010
use std::fs::File;
1111
use std::io::Write;
12-
use std::os::fd::AsRawFd;
1312
use wayrs_client::core::ObjectId;
1413
use wayrs_client::protocol::wl_seat::WlSeat;
1514
use wayrs_client::{Connection, EventCtx, IoMode};
@@ -119,21 +118,12 @@ fn paste_wayland(cfg: PasteConfig) -> Result<()> {
119118

120119
// offer.receive needs a fd to write, we cannot use the stdin since the read side of the
121120
// pipe may close earlier before all data written.
122-
let fds = pipe()?;
123-
offer.receive(&mut client.conn, mime_type, fds.1);
121+
let (pipe_read, pipe_write) = pipe()?;
122+
offer.receive(&mut client.conn, mime_type, pipe_write);
124123
client.conn.flush(IoMode::Blocking)?;
125124

126-
let mut buffer = vec![0; 1024 * 4];
127-
loop {
128-
// Read from the pipe until EOF
129-
let n = read(fds.0.as_raw_fd(), &mut buffer)?;
130-
if n > 0 {
131-
// Write the content to the destination
132-
state.config.writter.write(&buffer[0..n])?;
133-
} else {
134-
break;
135-
}
136-
}
125+
let mut pipe_read = File::from(pipe_read);
126+
std::io::copy(&mut pipe_read, &mut state.config.writter)?;
137127

138128
Ok(())
139129
}

0 commit comments

Comments
 (0)