Skip to content

Commit 4c9cd9e

Browse files
Rollup merge of rust-lang#110173 - solid-rs:patch/kmc-solid/socket-read-buf, r=cuviper
kmc-solid: Implement `Socket::read_buf` Follow-up to rust-lang#108326. Implements `Socket::read_buf` for the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.
2 parents d22b019 + 72bfd55 commit 4c9cd9e

File tree

1 file changed

+17
-6
lines changed
  • library/std/src/sys/solid

1 file changed

+17
-6
lines changed

library/std/src/sys/solid/net.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::abi;
22
use crate::{
33
cmp,
44
ffi::CStr,
5-
io::{self, ErrorKind, IoSlice, IoSliceMut},
5+
io::{self, BorrowedBuf, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut},
66
mem,
77
net::{Shutdown, SocketAddr},
88
ptr, str,
@@ -294,19 +294,30 @@ impl Socket {
294294
self.0.duplicate().map(Socket)
295295
}
296296

297-
fn recv_with_flags(&self, buf: &mut [u8], flags: c_int) -> io::Result<usize> {
297+
fn recv_with_flags(&self, mut buf: BorrowedCursor<'_>, flags: c_int) -> io::Result<()> {
298298
let ret = cvt(unsafe {
299-
netc::recv(self.0.raw(), buf.as_mut_ptr() as *mut c_void, buf.len(), flags)
299+
netc::recv(self.0.raw(), buf.as_mut().as_mut_ptr().cast(), buf.capacity(), flags)
300300
})?;
301-
Ok(ret as usize)
301+
unsafe {
302+
buf.advance(ret as usize);
303+
}
304+
Ok(())
302305
}
303306

304307
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
305-
self.recv_with_flags(buf, 0)
308+
let mut buf = BorrowedBuf::from(buf);
309+
self.recv_with_flags(buf.unfilled(), 0)?;
310+
Ok(buf.len())
306311
}
307312

308313
pub fn peek(&self, buf: &mut [u8]) -> io::Result<usize> {
309-
self.recv_with_flags(buf, MSG_PEEK)
314+
let mut buf = BorrowedBuf::from(buf);
315+
self.recv_with_flags(buf.unfilled(), MSG_PEEK)?;
316+
Ok(buf.len())
317+
}
318+
319+
pub fn read_buf(&self, buf: BorrowedCursor<'_>) -> io::Result<()> {
320+
self.recv_with_flags(buf, 0)
310321
}
311322

312323
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {

0 commit comments

Comments
 (0)