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

Method write

api/src/file/pipe.rs:143–179  ·  view source on GitHub ↗
(&self, src: &mut IoSrc)

Source from the content-addressed store, hash-verified

141 }
142
143 fn write(&self, src: &mut IoSrc) -> AxResult<usize> {
144 if !self.is_write() {
145 return Err(AxError::BadFileDescriptor);
146 }
147 let size = src.remaining();
148 if size == 0 {
149 return Ok(0);
150 }
151
152 let mut total_written = 0;
153
154 block_on(poll_io(self, IoEvents::OUT, self.nonblocking(), || {
155 if self.closed() {
156 raise_pipe();
157 return Err(AxError::BrokenPipe);
158 }
159
160 let written = {
161 let mut prod = self.shared.buffer.lock();
162 let (left, right) = prod.vacant_slices_mut();
163 let mut count = src.read(unsafe { left.assume_init_mut() })?;
164 if count >= left.len() {
165 count += src.read(unsafe { right.assume_init_mut() })?;
166 }
167 unsafe { prod.advance_write_index(count) };
168 count
169 };
170 if written > 0 {
171 self.shared.poll_rx.wake();
172 total_written += written;
173 if total_written == size || self.nonblocking() {
174 return Ok(total_written);
175 }
176 }
177 Err(AxError::WouldBlock)
178 }))
179 }
180
181 fn stat(&self) -> AxResult<Kstat> {
182 Ok(Kstat {

Callers 1

readMethod · 0.45

Calls 8

raise_pipeFunction · 0.85
is_writeMethod · 0.80
closedMethod · 0.80
remainingMethod · 0.45
nonblockingMethod · 0.45
readMethod · 0.45
lenMethod · 0.45
wakeMethod · 0.45

Tested by

no test coverage detected