@@ -98,9 +98,28 @@ impl<L: Read + Write + AsFd, R: Read + Write + AsFd> Pipe<L, R> {
9898 }
9999 }
100100
101- /// Ensure that all the contents of the pipe's internal buffer are written to the left side.
101+ /// Flush the pipe, ensuring that all the contents are written to the left side.
102102 pub ( super ) fn flush_left ( & mut self ) -> io:: Result < ( ) > {
103- self . buffer_rl . flush ( & mut self . left )
103+ let buffer = & mut self . buffer_rl ;
104+ let source = & mut self . right ;
105+ let sink = & mut self . left ;
106+
107+ // Remove bytes from the right buffer and write them to the left buffer;
108+ // then flush the left buffer.
109+
110+ if buffer. write_handle . is_active ( ) {
111+ // There may still be data in flight, read until EOF
112+ loop {
113+ buffer. internal . remove ( sink) ?;
114+ buffer. internal . insert ( source) ?;
115+ if !buffer. internal . is_full ( ) {
116+ break ;
117+ }
118+ }
119+ }
120+ buffer. internal . remove ( sink) ?;
121+
122+ sink. flush ( )
104123 }
105124}
106125
@@ -181,12 +200,4 @@ impl<R: Read, W: Write> Buffer<R, W> {
181200
182201 Ok ( ( ) )
183202 }
184-
185- /// Flush this buffer, ensuring that all the contents of its internal buffer are written.
186- fn flush ( & mut self , write : & mut W ) -> io:: Result < ( ) > {
187- // Remove bytes from the buffer and write them.
188- self . internal . remove ( write) ?;
189-
190- write. flush ( )
191- }
192203}
0 commit comments