Skip to content

Commit

Permalink
Rollup merge of rust-lang#110173 - solid-rs:patch/kmc-solid/socket-re…
Browse files Browse the repository at this point in the history
…ad-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.
  • Loading branch information
compiler-errors committed Apr 12, 2023
2 parents d22b019 + 72bfd55 commit 4c9cd9e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions library/std/src/sys/solid/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::abi;
use crate::{
cmp,
ffi::CStr,
io::{self, ErrorKind, IoSlice, IoSliceMut},
io::{self, BorrowedBuf, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut},
mem,
net::{Shutdown, SocketAddr},
ptr, str,
Expand Down Expand Up @@ -294,19 +294,30 @@ impl 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> {
Expand Down

0 comments on commit 4c9cd9e

Please sign in to comment.