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

Add support for sendmmsg/recvmmsg #494

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Tuetuopay
Copy link

This PR aims to add support for the sendmmsg/recvmmsg syscalls.

The API exposed here is a bit simplified, where the "user friendly" functions don't expose the scatter/gather stuff (the _vectored variants found for recvmsg/sendmsg). This was not exposed to not blow up the API surface, while keeping the functionality using MmsgHdr(Mut) for advanced usages.

Thanks!

FreeBSD use a `size_t` for the `len` argument, while other UNIX-likes
use an `unigned int`.
From a quick glance, Windows does not have the equivalent syscall in the
WinSock API.
This one is great. The whole unix world uses an int for the flags, and
documents it as such. But musl uses an unsigned int there [1], while
still documenting a signed int.

This API is cursed.

[1]: https://git.musl-libc.org/cgit/musl/tree/include/sys/socket.h?id=39838619bb8b65a8897abcfda8c17ad6de0115d8#n70
For some braindead reason, old versions of android on 32 bit  defined
socklen_t to be an int, instead of the unsigned int it was everywhere
else.
Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw left a comment

Choose a reason for hiding this comment

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

Have you tried using &[MsgHdr] and &mut [MshHdrMut] instead of new types (MmsgHdr and MmsgHdrMut)?

src/sys/unix.rs Outdated Show resolved Hide resolved
@Tuetuopay
Copy link
Author

Have you tried using &[MsgHdr] and &mut [MshHdrMut] instead of new types (MmsgHdr and MmsgHdrMut)?

Sadly yes, but this is not possible because mmsghdr interleaves the buffer size inbetween msghdrs. So it's basically a &[(MsgHdr, usize)] that's required, hence the newtype. And the kernel has no struct-of-array constructs so there's no escape hatch there neither.

target_vendor = "apple"
))
))]
pub struct MmsgHdr<'addr, 'bufs, 'control> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about matching mmsghdr here? For example

pub struct MmsgHdr<'addr, 'bufs, 'control> {
    msg: MsgHdr,
    len: libc::c_uint,
}

This way the caller can decide if they want to use a Vec, a slice an array or something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants