Update to latest line_discipline to handle EOF correctly

This commit is contained in:
pjht 2024-11-20 13:59:04 -06:00
parent 2fad35bcd7
commit fabf69b353
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A

View File

@ -42,17 +42,22 @@ impl Pty {
}
fn read_slave(&self, len: usize) -> Vec<u8> {
while !self.input_buffer.lock().contains(&b'\n') {
while self.input_buffer.lock().is_empty() {
ipc::process_messages();
let mut input_buffer = self.input_buffer.lock();
input_buffer.extend_from_slice(&self.line_discipline.lock().get_program_input());
let input = self.line_discipline.lock().get_program_input();
let Some(input) = input else {
continue;
};
if input.is_empty() {
return Vec::new();
}
input_buffer.extend_from_slice(&input);
}
let mut input_buffer = self.input_buffer.lock();
input_buffer.extend_from_slice(&self.line_discipline.lock().get_program_input());
let Some(line_end) = input_buffer.iter().position(|&x| x == b'\n') else {
return Vec::new();
};
let rem_buf = input_buffer.split_off(usize::min(len, line_end + 1));
input_buffer.extend_from_slice(&self.line_discipline.lock().get_program_input().unwrap_or_default());
let buf_len = input_buffer.len();
let rem_buf = input_buffer.split_off(usize::min(len, buf_len));
std::mem::replace(&mut *input_buffer, rem_buf)
}
@ -63,7 +68,7 @@ impl Pty {
fn curr_slave_poll(&self) -> PollEvents {
self.input_buffer
.lock()
.extend_from_slice(&self.line_discipline.lock().get_program_input());
.extend_from_slice(&self.line_discipline.lock().get_program_input().unwrap_or_default());
let mut events = PollEvents::POLLOUT;
if self.input_buffer.lock().contains(&b'\n') {
events |= PollEvents::POLLIN;