MCPcopy Create free account
hub / github.com/Starry-OS/StarryOS / read

Method read

api/src/terminal/ldisc.rs:328–370  ·  view source on GitHub ↗
(&mut self, buf: &mut [u8])

Source from the content-addressed store, hash-verified

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}

Callers 1

pollMethod · 0.45

Calls 6

WaitPollableClass · 0.85
is_emptyMethod · 0.80
canonicalMethod · 0.80
special_charMethod · 0.80
lenMethod · 0.45
wakeMethod · 0.45

Tested by

no test coverage detected