(&mut self, buf: &mut [u8])
| 326 | } |
| 327 | |
| 328 | pub fn read(&mut self, buf: &mut [u8]) -> AxResult<usize> { |
| 329 | if buf.is_empty() { |
| 330 | return Ok(0); |
| 331 | } |
| 332 | if matches!(self.processor, Processor::None(_, _)) { |
| 333 | let read = self.buf_rx.pop_slice(buf); |
| 334 | return if read == 0 { |
| 335 | Err(AxError::WouldBlock) |
| 336 | } else { |
| 337 | Ok(read) |
| 338 | }; |
| 339 | } |
| 340 | |
| 341 | let term = self.terminal.termios.lock().clone(); |
| 342 | let vmin = if term.canonical() { |
| 343 | 1 |
| 344 | } else { |
| 345 | let vtime = term.special_char(VTIME); |
| 346 | if vtime > 0 { |
| 347 | todo!(); |
| 348 | } |
| 349 | term.special_char(VMIN) as usize |
| 350 | }; |
| 351 | |
| 352 | if buf.len() < vmin as usize { |
| 353 | return Err(AxError::WouldBlock); |
| 354 | } |
| 355 | |
| 356 | let mut total_read = 0; |
| 357 | let set = match &self.processor { |
| 358 | Processor::Manual(_) => None, |
| 359 | Processor::External(set) => Some(set), |
| 360 | _ => unreachable!(), |
| 361 | }; |
| 362 | let pollable = WaitPollable(set); |
| 363 | block_on(poll_io(&pollable, IoEvents::IN, false, || { |
| 364 | total_read += self.buf_rx.pop_slice(&mut buf[total_read..]); |
| 365 | self.poll_tx.wake(); |
| 366 | (total_read >= vmin) |
| 367 | .then_some(total_read) |
| 368 | .ok_or(AxError::WouldBlock) |
| 369 | })) |
| 370 | } |
| 371 | } |
no test coverage detected