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

Allow sendmsg to accept a preallocated Vec #2457

Open
vkrasnov opened this issue Jun 27, 2024 · 2 comments · May be fixed by #2498
Open

Allow sendmsg to accept a preallocated Vec #2457

vkrasnov opened this issue Jun 27, 2024 · 2 comments · May be fixed by #2498

Comments

@vkrasnov
Copy link

Currently sendmsg allocates a new vector for cmsg_buffer every time it is called. It would be nice if it could accept a mutable reference to Vec instead so it can reuse existing storage instead or &mut [u8], perhaps as an option?

@SteveLauC
Copy link
Member

SteveLauC commented Jul 10, 2024

Hi, it would be nice to avoid heap allocations here, but if we allow users to pass a pre-allocated cmsg buffer, then users have to ensure that:

  1. The buffer is zero-initialized
  2. The buffer is sufficient in size

For 1, Nix can guarantee this by (possibly) re-initializing it. For 2, if we use a vector and it is insufficient, we can re-allocate to extend the capacity.

Perhaps we should provide an alternative interface? Something like sendmsg_pre_alloc()?

@howjmay howjmay linked a pull request Sep 12, 2024 that will close this issue
@SteveLauC
Copy link
Member

The buffer is zero-initialized

Cannot remember why I said this is needed, I think we do not need to satisfy this condition.

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

Successfully merging a pull request may close this issue.

2 participants