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

Method read

api/src/file/pipe.rs:113–141  ·  view source on GitHub ↗
(&self, dst: &mut IoDst)

Source from the content-addressed store, hash-verified

111
112impl FileLike for Pipe {
113 fn read(&self, dst: &mut IoDst) -> AxResult<usize> {
114 if !self.is_read() {
115 return Err(AxError::BadFileDescriptor);
116 }
117 if dst.is_full() {
118 return Ok(0);
119 }
120
121 block_on(poll_io(self, IoEvents::IN, self.nonblocking(), || {
122 let read = {
123 let cons = self.shared.buffer.lock();
124 let (left, right) = cons.as_slices();
125 let mut count = dst.write(left)?;
126 if count >= left.len() {
127 count += dst.write(right)?;
128 }
129 unsafe { cons.advance_read_index(count) };
130 count
131 };
132 if read > 0 {
133 self.shared.poll_tx.wake();
134 Ok(read)
135 } else if self.closed() {
136 Ok(0)
137 } else {
138 Err(AxError::WouldBlock)
139 }
140 }))
141 }
142
143 fn write(&self, src: &mut IoSrc) -> AxResult<usize> {
144 if !self.is_write() {

Callers 1

writeMethod · 0.45

Calls 6

is_readMethod · 0.80
closedMethod · 0.80
nonblockingMethod · 0.45
writeMethod · 0.45
lenMethod · 0.45
wakeMethod · 0.45

Tested by

no test coverage detected