Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to the default implementation of write_vectored #125333

Merged
merged 2 commits into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions library/std/src/sys/pal/hermit/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,12 @@ impl Socket {
}

pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
let mut size: isize = 0;

for i in bufs.iter_mut() {
let ret: isize =
cvt(unsafe { netc::read(self.0.as_raw_fd(), i.as_mut_ptr(), i.len()) })?;

if ret != 0 {
size += ret;
}
}

Ok(size.try_into().unwrap())
crate::io::default_read_vectored(|b| self.read(b), bufs)
}

#[inline]
pub fn is_read_vectored(&self) -> bool {
true
false
}

fn recv_from_with_flags(&self, buf: &mut [u8], flags: i32) -> io::Result<(usize, SocketAddr)> {
Expand Down Expand Up @@ -225,17 +214,11 @@ impl Socket {
}

pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let mut size: isize = 0;

for i in bufs.iter() {
size += cvt(unsafe { netc::write(self.0.as_raw_fd(), i.as_ptr(), i.len()) })?;
}

Ok(size.try_into().unwrap())
crate::io::default_write_vectored(|b| self.write(b), bufs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, this appears to be the exact same implementation as what's on the left. weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but is_write_vectored was wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably just delete the implementation altogether, it'll fall back to the default automatically.

Copy link
Member

@workingjubilee workingjubilee May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the impl of Socket, tho, innit?

Or do you mean that the write_vectored calls will resolve to the trait and then dispatch to that one's default impl?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the impl of Socket, tho, innit?

Oh yeah. Nevermind my comment then, didn't notice.

}

pub fn is_write_vectored(&self) -> bool {
true
false
}

pub fn set_timeout(&self, dur: Option<Duration>, kind: i32) -> io::Result<()> {
Expand Down
Loading