Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement safe sendmsg/recvmsg abstractions #16
Conversation
teisenbe
added some commits
Sep 7, 2015
This comment has been minimized.
This comment has been minimized.
elmarco
commented
Sep 16, 2015
|
thank you! |
sfackler
reviewed
Sep 17, 2015
| @@ -8,11 +8,16 @@ repository = "https://github.com/sfackler/rust-unix-socket" | |||
| documentation = "https://sfackler.github.io/rust-unix-socket/doc/v0.4.5/unix_socket" | |||
| readme = "README.md" | |||
| keywords = ["posix", "unix", "socket", "domain"] | |||
| links = "cmsg_manip" | |||
This comment has been minimized.
This comment has been minimized.
sfackler
Sep 17, 2015
Member
This isn't necessary - it's only needed when linking to third party stuff.
sfackler
reviewed
Sep 17, 2015
| @@ -0,0 +1,41 @@ | |||
| #define _GNU_SOURCE | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
sfackler
reviewed
Sep 17, 2015
|
|
||
| fn set_passcred(&self, receive_creds: bool) -> io::Result<()> { | ||
| unsafe { | ||
| let v: libc::c_int = if receive_creds { 1 } else { 0 }; |
This comment has been minimized.
This comment has been minimized.
sfackler
reviewed
Sep 17, 2015
| } | ||
|
|
||
| #[allow(dead_code)] | ||
| #[link(name = "cmsg_manip")] |
This comment has been minimized.
This comment has been minimized.
sfackler
reviewed
Sep 17, 2015
| /// flags is a pass-through of the flags specified in the sendmsg(2) man page | ||
| /// | ||
| /// On success, returns the number of bytes written. | ||
| pub fn recvmsg(&self, buffers: &[&mut[u8]], cmsg_buffer: &mut [u8], flags: libc::c_int) -> io::Result<RecvMsgResult> { |
This comment has been minimized.
This comment has been minimized.
sfackler
Sep 17, 2015
Member
The APIs here seem slightly too low-level, IMO, specifically the flags field here.
This comment has been minimized.
This comment has been minimized.
teisenbe
Sep 21, 2015
Author
Yeah. I'm a little up in the air about the cmsg_buffer option, too. I'll probably replace it with a stack allocated array inside of the function
sfackler
reviewed
Sep 17, 2015
| /// flags is a pass-through of the flags specified in the sendmsg(2) man page | ||
| /// | ||
| /// On success, returns the number of bytes written. | ||
| pub fn sendmsg<P: AsRef<Path>>(&self, path: Option<P>, buffers: &[&[u8]], ctrl_msgs: &[ControlMsg], flags: libc::c_int) -> io::Result<usize> { |
This comment has been minimized.
This comment has been minimized.
sfackler
reviewed
Sep 17, 2015
| /// List of all control messages received during this call | ||
| pub control_msgs: Vec<ControlMsg>, | ||
| /// Flags returned by recvmsg, see the recv(2) man page for a list | ||
| pub flags: libc::c_int, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Thanks for doing this! I left some comments here and there. Also, this'll need to be put behind a feature since these are Linux-only APIs I believe. I'm not totally sure what the API for |
This comment has been minimized.
This comment has been minimized.
|
I think all of the flags are potentially applicable and usable with this API. If you want, I can replace the c_int with a struct of bools to make it a bit more friendly? Can also take it out completely, but I think the options flags provides and the data it returns are genuinely useful. Will probably work to address comments today |
This comment has been minimized.
This comment has been minimized.
|
Oh yeah, the options flags are definitely useful, I'd just prefer something more structured than a raw c_int. A struct with bool setters/getters seems reasonable to me. |
This comment has been minimized.
This comment has been minimized.
|
Take a look at the latest version of the pull request. Replaced it with the struct as requested |
This comment has been minimized.
This comment has been minimized.
geofft
commented
Oct 8, 2015
|
I just saw this -- I have a PR for a pure-Rust implementation of this (just |
sfackler
reviewed
Oct 11, 2015
| @@ -771,6 +802,46 @@ impl UnixDatagram { | |||
| } | |||
| } | |||
|
|
|||
| /// Receives data on the socket. | |||
| /// | |||
| /// If path is None, the peer address set by the `connect` method will be used. If it has not | |||
This comment has been minimized.
This comment has been minimized.
sfackler
reviewed
Oct 11, 2015
| /// This interface allows receiving data into multiple buffers. This acts as if the buffers had been | ||
| /// concatenated in the order they were given. | ||
| /// | ||
| /// cmsg_buffer is space to use for storing control messages. |
This comment has been minimized.
This comment has been minimized.
sfackler
Oct 11, 2015
Member
This field seems a bit weird - it's basically scratch space for the internal logic, right?
This comment has been minimized.
This comment has been minimized.
teisenbe
Oct 11, 2015
Author
Yeah, just to prevent having to do an allocation on every sendmsg call even if cmsgs aren't being used. Though I guess a stack allocation is basically free so could kill it
sfackler
reviewed
Oct 11, 2015
| [dev-dependencies] | ||
| tempdir = "0.3" | ||
|
|
||
| [features] | ||
| default = ["from_raw_fd"] | ||
| default = ["from_raw_fd", "sendmsg"] |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
teisenbe
Oct 11, 2015
Author
Well, the SCM_RIGHTS stuff isn't portable past Linux (POSIX doesn't define what gets passed in the message, I believe)
This comment has been minimized.
This comment has been minimized.
|
Finally got around to addressing the comments |
maghoff
reviewed
Dec 17, 2015
| /// | ||
| /// This is a Rust version of `struct ucred` from sys/socket.h | ||
| #[derive(Clone, Debug)] | ||
| pub struct UCred{ |
teisenbe commentedSep 8, 2015
Supports SCM_CREDENTIALS and SCM_RIGHTS control messages
Resolves #4 and resolves #5