@@ -4,12 +4,11 @@ use super::PasteConfig;
44use super :: mime_type:: decide_mime_type;
55use crate :: protocol:: SourceData ;
66use anyhow:: { Context , Error , Result } ;
7- use nix:: unistd:: { pipe, read } ;
7+ use nix:: unistd:: pipe;
88use std:: collections:: HashMap ;
99use std:: ffi:: CString ;
1010use std:: fs:: File ;
1111use std:: io:: Write ;
12- use std:: os:: fd:: AsRawFd ;
1312use wayrs_client:: core:: ObjectId ;
1413use wayrs_client:: protocol:: wl_seat:: WlSeat ;
1514use 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