Rollup merge of #110173 - solid-rs:patch/kmc-solid/socket-read-buf, r=cuviper
kmc-solid: Implement `Socket::read_buf` Follow-up to #108326. Implements `Socket::read_buf` for the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.
This commit is contained in:
commit
4c9cd9e739
@ -2,7 +2,7 @@
|
||||
use crate::{
|
||||
cmp,
|
||||
ffi::CStr,
|
||||
io::{self, ErrorKind, IoSlice, IoSliceMut},
|
||||
io::{self, BorrowedBuf, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut},
|
||||
mem,
|
||||
net::{Shutdown, SocketAddr},
|
||||
ptr, str,
|
||||
@ -294,19 +294,30 @@ pub fn duplicate(&self) -> io::Result<Socket> {
|
||||
self.0.duplicate().map(Socket)
|
||||
}
|
||||
|
||||
fn recv_with_flags(&self, buf: &mut [u8], flags: c_int) -> io::Result<usize> {
|
||||
fn recv_with_flags(&self, mut buf: BorrowedCursor<'_>, flags: c_int) -> io::Result<()> {
|
||||
let ret = cvt(unsafe {
|
||||
netc::recv(self.0.raw(), buf.as_mut_ptr() as *mut c_void, buf.len(), flags)
|
||||
netc::recv(self.0.raw(), buf.as_mut().as_mut_ptr().cast(), buf.capacity(), flags)
|
||||
})?;
|
||||
Ok(ret as usize)
|
||||
unsafe {
|
||||
buf.advance(ret as usize);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
self.recv_with_flags(buf, 0)
|
||||
let mut buf = BorrowedBuf::from(buf);
|
||||
self.recv_with_flags(buf.unfilled(), 0)?;
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
pub fn peek(&self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
self.recv_with_flags(buf, MSG_PEEK)
|
||||
let mut buf = BorrowedBuf::from(buf);
|
||||
self.recv_with_flags(buf.unfilled(), MSG_PEEK)?;
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
pub fn read_buf(&self, buf: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
self.recv_with_flags(buf, 0)
|
||||
}
|
||||
|
||||
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
|
||||
|
Loading…
Reference in New Issue
Block a user