Skip to content

Commit 05ef39e

Browse files
committed
read Pty to completion
1 parent c4a8a81 commit 05ef39e

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/exec/event.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ impl EventHandle {
9191
}
9292
}
9393
}
94+
95+
/// Is this event handle ready to be processed?
96+
pub(super) fn is_active(&self) -> bool {
97+
self.should_poll
98+
}
9499
}
95100

96101
/// The kind of event that will be monitored for a file descriptor.

src/exec/use_pty/pipe/mod.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)