nix-rust / nix

Rust friendly bindings to *nix APIs
MIT License
2.67k stars 667 forks source link

recvmsg: take slice for cmsg_buffer #2524

Closed erenon closed 1 month ago

erenon commented 1 month ago

Instead of a Vec, to avoid forcing an allocation.

cmsg_space! now creates a zero initialized vec (instead of a zero-len vec with capacity): this way callsites do not need to be changed.

I tried to change cmsg_space! to create a fixed sized array (instead of a Vec) but run into:

error: constant expression depends on a generic parameter
    --> test/sys/test_socket.rs:2907:26
     |
2907 |         let mut cspace = cmsg_space!(libc::sock_extended_err, SA);
     |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Fixes #2523